using SewingDressesContracts.BindingModels; using SewingDressesContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using System.Windows.Forms; using SewingDressesBusinessLogic.BusinessLogic; namespace SewingDressesView { public partial class MainForm : Form { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; } private void LoadData() { try { var list = _orderLogic.ReadList(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns["DressId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; } _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(DressesForm)); if (service is DressesForm 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(); } private void MainForm_Load(object sender, EventArgs e) { LoadData(); } private void ComponentProductsToolStripMenuItemReport_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(ReportDressComponentsForm)); if (service is ReportDressComponentsForm form) { form.ShowDialog(); } } private void OrdersToolStripMenuItemReport_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(ReportOrdersForm)); if (service is ReportOrdersForm form) { form.ShowDialog(); } } private void DressesToolStripMenuItemReport_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { _reportLogic.SaveComponentsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void clientsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(ClientsForm)); if (service is ClientsForm form) { form.ShowDialog(); } } } }