using FlowerShopContracts.BusinessLogicsContracts; using FlowerShopContracts.SearchModels; using FlowerShopContracts.ViewModels; using FlowerShopDataModels.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 ProjectFlowerShop { public partial class SellForm : Form { private readonly List? _flowerList; IShopLogic _shopLogic; IFlowerLogic _flowerLogic; public SellForm(IFlowerLogic flowerLogic, IShopLogic shopLogic) { InitializeComponent(); _shopLogic = shopLogic; _flowerLogic = flowerLogic; _flowerList = flowerLogic.ReadList(null); if (_flowerList != null) { comboBoxFlower.DisplayMember = "FlowerName"; comboBoxFlower.ValueMember = "Id"; comboBoxFlower.DataSource = _flowerList; comboBoxFlower.SelectedItem = null; } } public int FlowerId { get { return Convert.ToInt32(comboBoxFlower.SelectedValue); } set { comboBoxFlower.SelectedValue = value; } } public IFlowerModel? FlowerModel { get { if (_flowerList == null) { return null; } foreach (var elem in _flowerList) { if (elem.Id == FlowerId) { return elem; } } return null; } } public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxFlower.SelectedValue == null) { MessageBox.Show("Выберите цветы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { int count = Convert.ToInt32(textBoxCount.Text); bool res = _shopLogic.MakeSell( _flowerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxFlower.SelectedValue) }), count ); if (!res) { throw new Exception("Ошибка при продаже."); } MessageBox.Show("Продажа прошла успешно"); DialogResult = DialogResult.OK; Close(); } catch (Exception err) { MessageBox.Show("Ошибка продажи"); return; } } private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }