PIbd-22_Kozlova_A.A_Precast.../PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs

245 lines
9.3 KiB
C#
Raw Normal View History

2024-03-05 22:19:49 +04:00
using Microsoft.Extensions.Logging;
2024-04-03 00:11:17 +04:00
using PrecastConcretePlantBusinessLogic.BusinessLogics;
2024-03-05 22:19:49 +04:00
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
2024-06-15 20:22:17 +04:00
using PrecastConcretePlantView;
2024-03-05 22:19:49 +04:00
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 PrecastConcretePlantView
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private readonly IOrderLogic _orderLogic;
2024-06-15 20:22:17 +04:00
2024-04-03 00:11:17 +04:00
private readonly IReportLogic _reportLogic;
2024-06-15 20:22:17 +04:00
2024-04-03 00:11:17 +04:00
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
2024-03-05 22:19:49 +04:00
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
2024-04-03 00:11:17 +04:00
_reportLogic = reportLogic;
2024-03-05 22:19:49 +04:00
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ReinforcedId"].Visible = false;
dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
2024-06-15 20:22:17 +04:00
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
2024-03-05 22:19:49 +04:00
if (service is FormComponents form)
{
form.ShowDialog();
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReinforceds));
if (service is FormReinforceds form)
{
form.ShowDialog();
}
}
2024-06-15 20:22:17 +04:00
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
if (service is FormShopReplenishment form)
{
form.ShowDialog();
}
}
private void ПродажаИзделийToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale));
if (service is FormReinforcedSale form)
{
form.ShowDialog();
}
}
private void СписокИзделийToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveReinforcedsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void КомпонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportReinforcedComponents));
if (service is FormReportReinforcedComponents form)
{
form.ShowDialog();
}
}
private void СписокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}
private void СписокМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
{
/*using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}*/
}
private void ЗагруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e)
{
/* var service = Program.ServiceProvider?.GetService(typeof(FormReportShopIceCreams));
if (service is FormReportShopIceCreams form)
{
form.ShowDialog();
}*/
}
private void ЗаказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e)
{
/*var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders));
if (service is FormReportGroupedOrders form)
{
form.ShowDialog();
}*/
}
2024-03-05 22:19:49 +04:00
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
2024-06-15 20:22:17 +04:00
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
2024-03-05 22:19:49 +04:00
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-06-15 20:22:17 +04:00
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'В работе'", id);
2024-03-05 22:19:49 +04:00
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
2024-06-15 20:22:17 +04:00
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
2024-03-05 22:19:49 +04:00
}
LoadData();
}
catch (Exception ex)
{
2024-06-15 20:22:17 +04:00
_logger.LogError(ex, "Error taking an order to work");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-03-05 22:19:49 +04:00
}
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-06-15 20:22:17 +04:00
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'Готов'", id);
2024-03-05 22:19:49 +04:00
try
{
2024-06-15 20:22:17 +04:00
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
2024-03-05 22:19:49 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
2024-06-15 20:22:17 +04:00
_logger.LogError(ex, "Order readiness marking error");
2024-03-05 22:19:49 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-06-15 20:22:17 +04:00
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'Выдан'", id);
2024-03-05 22:19:49 +04:00
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
2024-06-15 20:22:17 +04:00
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
2024-03-05 22:19:49 +04:00
}
2024-06-15 20:22:17 +04:00
_logger.LogInformation("Order №{id} issued", id);
2024-03-05 22:19:49 +04:00
LoadData();
}
catch (Exception ex)
{
2024-06-15 20:22:17 +04:00
_logger.LogError(ex, "Order issue marking error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-03-05 22:19:49 +04:00
}
}
}
2024-06-15 20:22:17 +04:00
2024-03-05 22:19:49 +04:00
private void ButtonUpd_Click(object sender, EventArgs e)
{
LoadData();
}
}
2024-06-15 20:22:17 +04:00
}