using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantListImplement.Models; 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; namespace PrecastConcretePlantView { public partial class FormShopRefill : Form { private readonly ILogger _logger; private readonly IReinforcedLogic _logicReinforced; private readonly IShopLogic _logicShop; public FormShopRefill(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) { InitializeComponent(); _logger = logger; _logicReinforced = logicReinforced; _logicShop = logicShop; } private void FormShopRefill_Load(object sender, EventArgs e) { _logger.LogInformation("Reinforceds loading"); try { var list = _logicReinforced.ReadList(null); if (list != null) { comboBoxReinforced.DisplayMember = "ReinforcedName"; comboBoxReinforced.ValueMember = "Id"; comboBoxReinforced.DataSource = list; comboBoxReinforced.SelectedItem = null; } } catch (Exception ex) { _logger.LogError(ex, "Reinforceds loading error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } _logger.LogInformation("Shops loading"); try { var list = _logicShop.ReadList(null); if (list != null) { comboBoxShop.DisplayMember = "ShopName"; comboBoxShop.ValueMember = "Id"; comboBoxShop.DataSource = list; comboBoxShop.SelectedItem = null; } } catch (Exception ex) { _logger.LogError(ex, "Shops loading error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonSave_Click(object sender, EventArgs e) { if (comboBoxShop.SelectedValue == null) { MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxReinforced.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Shop Refill"); try { var reinforced = _logicReinforced.ReadElement(new ReinforcedSearchModel { Id = Convert.ToInt32(comboBoxReinforced.SelectedValue) }); if (reinforced == null) { throw new Exception("Изделие не найдено."); } var operationResult = _logicShop.RefillShop(new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, reinforced, Convert.ToInt32(textBoxCount.Text)); if (!operationResult) { throw new Exception("Ошибка при проведении поставки."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { _logger.LogError(ex, "Shop Refill error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult = DialogResult.OK; Close(); } private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }