using Microsoft.Extensions.Logging; using FishFactoryContracts.BusinessLogicsContracts; using FishFactoryContracts.SearchModels; using FishFactoryContracts.StoragesContracts; using FishFactoryContracts.ViewModels; 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 FishFactoryView { public partial class FormSellCanned : Form { private readonly ILogger _logger; private readonly ICannedLogic _logicP; private readonly IShopLogic _logicS; private List _cannedList = new List(); public FormSellCanned(ILogger logger, ICannedLogic logicP, IShopLogic logicS) { InitializeComponent(); _logger = logger; _logicP = logicP; _logicS = logicS; } private void FormSellingCanned_Load(object sender, EventArgs e) { _cannedList = _logicP.ReadList(null); if (_cannedList != null) { comboBoxCanned.DisplayMember = "CannedName"; comboBoxCanned.ValueMember = "Id"; comboBoxCanned.DataSource = _cannedList; comboBoxCanned.SelectedItem = null; _logger.LogInformation("Загрузка консерв для продажи"); } } private void ButtonSell_Click(object sender, EventArgs e) { if (comboBoxCanned.SelectedValue == null) { MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание покупки"); try { bool resout = _logicS.Sale(new SupplySearchModel { CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text) }); if (resout) { _logger.LogInformation("Проверка пройдена, продажа проведена"); MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } else { _logger.LogInformation("Проверка не пройдена"); MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } 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(); } } }