using SewingDressesContracts.BindingModels; using SewingDressesContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using System.Windows.Forms; namespace SewingDressesView { public partial class MainForm : Form { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; public MainForm(ILogger logger, IOrderLogic orderLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; } private void LoadData() { try { var list = _orderLogic.ReadList(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns["DressId"].Visible = false; dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Load orders"); } catch (Exception ex) { _logger.LogError(ex, "Load orders error"); } } private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(ComponentsForm)); if (service is ComponentsForm form) { form.ShowDialog(); } } private void DressesToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(DressForm)); if (service is DressForm form) { form.ShowDialog(); } } private void buttonCreate_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(OrderForm)); if (service is OrderForm form) { form.ShowDialog(); LoadData(); } } private void buttonDoOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Order №{id}. Change Status on 'In work'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } LoadData(); } catch (Exception ex) { _logger.LogError(ex, "Change Status on 'In work' error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void buttonOrderReady_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Order №{id}. Change status on 'Ready'", id); try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } LoadData(); } catch (Exception ex) { _logger.LogError(ex, "Change status on 'Ready' error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void buttonOrderGive_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Order №{id}. Status change on 'Given'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } _logger.LogInformation("Order №{id} given", id); LoadData(); } catch (Exception ex) { _logger.LogError(ex, "Change status on 'Give' error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void buttonOrderUpdate_Click(object sender, EventArgs e) { LoadData(); } } }