using Microsoft.Extensions.Logging; using SushiBarContracts.BusinessLogicsContracts; using SushiBarDataModels.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 SushiBarView.Shops { public partial class FormSell : Form { private readonly ISushiLogic _sushiLogic; private readonly IShopLogic _shopLogic; private readonly ILogger _logger; public FormSell(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) { _logger = logger; _shopLogic = shopLogic; _sushiLogic = sushiLogic; InitializeComponent(); } private void buttonSell_Click(object sender, EventArgs e) { if (numericUpDownCountForSelling.Value == 0) { MessageBox.Show("Мы не можем продать ноль изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxSushis.SelectedValue == null) { MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Продажа изделий"); try { var operationResult = _shopLogic.SellSushis(_sushiLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxSushis.SelectedValue) }), Convert.ToInt32(numericUpDownCountForSelling.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 FormSell_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для продажи"); try { var list = _sushiLogic.ReadList(null); if (list != null) { comboBoxSushis.DisplayMember = "SushiName"; comboBoxSushis.ValueMember = "Id"; comboBoxSushis.DataSource = list; comboBoxSushis.SelectedItem = null; } } 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(); } } }