using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.ViewModels; namespace PrecastConcretePlantView { public partial class FormSellReinforced : Form { private readonly ILogger _logger; private readonly IShopLogic _shopLogic; private readonly IReinforcedLogic _reinforcedLogic; private readonly List? _listReinforced; public FormSellReinforced(ILogger logger, IShopLogic shopLogic, IReinforcedLogic reinforcedLogic) { InitializeComponent(); _logger = logger; _shopLogic = shopLogic; _reinforcedLogic = reinforcedLogic; _listReinforced = reinforcedLogic.ReadList(null); if (_listReinforced != null) { comboBoxReinforced.DisplayMember = "ReinforcedName"; comboBoxReinforced.ValueMember = "Id"; comboBoxReinforced.DataSource = _listReinforced; comboBoxReinforced.SelectedItem = null; } } private void ButtonSave_Click(object sender, EventArgs e) { if (comboBoxReinforced.SelectedValue == null) { MessageBox.Show("Выберите ЖБИ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(numericUpDownCount.Text)) { MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Продажа ЖБИ"); try { var reinforced = _reinforcedLogic.ReadElement(new() { Id = (int)comboBoxReinforced.SelectedValue }); if (reinforced == null) { throw new Exception("ЖБИ не найдено. Дополнительная информация в логах."); } var operationResult = _shopLogic.SellReinforced( model: reinforced, count: (int)numericUpDownCount.Value ); if (!operationResult) { throw new Exception("Ошибка при продаже ЖБИ. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { _logger.LogError(ex, "Ошибка сохранения ЖБИ"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }