ISEbd_21_Kuklew_M.I._Softwa.../SoftwareInstallation/FormMain.cs

175 lines
6.5 KiB
C#
Raw Normal View History

2024-04-07 17:05:30 +04:00
using SoftwareInstallationContracts.BindingModels;
2024-04-07 16:54:02 +04:00
using SoftwareInstallationContracts.BusinessLogicsContracts;
2024-04-07 17:05:30 +04:00
using Microsoft.Extensions.Logging;
2024-04-07 16:54:02 +04:00
2024-05-12 14:38:32 +04:00
namespace SoftwareInstallationView
2024-04-07 16:54:02 +04:00
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
2024-05-12 14:38:32 +04:00
2024-04-07 16:54:02 +04:00
private readonly IOrderLogic _orderLogic;
2024-05-12 14:38:32 +04:00
2024-04-07 16:54:02 +04:00
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
2024-05-12 14:38:32 +04:00
2024-04-07 16:54:02 +04:00
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
2024-05-12 14:38:32 +04:00
2024-04-07 16:54:02 +04:00
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["PackageId"].Visible = false;
2024-04-07 17:05:30 +04:00
dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
2024-04-07 16:54:02 +04:00
}
2024-05-12 14:38:32 +04:00
_logger.LogInformation("Orders loading");
2024-04-07 16:54:02 +04:00
}
catch (Exception ex)
{
2024-05-12 14:38:32 +04:00
_logger.LogError(ex, "Orders loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
2024-05-12 14:38:32 +04:00
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
2024-05-12 14:38:32 +04:00
private void МороженоеToolStripMenuItem_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormPackages));
if (service is FormPackages form)
{
form.ShowDialog();
}
}
2024-05-12 14:38:32 +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(FormMakeShipment));
if (service is FormMakeShipment form)
{
form.ShowDialog();
}
}
private void продажаМороженогоToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPackageSale));
if (service is FormPackageSale form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
2024-05-12 14:38:32 +04:00
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
2024-05-12 14:38:32 +04:00
_logger.LogInformation("Order №{id}. Status changes to 'В работе'", id);
2024-04-07 16:54:02 +04:00
try
{
2024-05-12 14:38:32 +04:00
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
2024-05-12 14:38:32 +04:00
_logger.LogError(ex, "Error taking an order to work");
2024-04-07 16:54:02 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-05-12 14:38:32 +04:00
private void ButtonOrderReady_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-05-12 14:38:32 +04:00
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status changes to 'Готов'", id);
2024-04-07 16:54:02 +04:00
try
{
2024-04-07 17:05:30 +04:00
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
2024-05-12 14:38:32 +04:00
_logger.LogError(ex, "Order readiness marking error");
2024-04-07 16:54:02 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-05-12 14:38:32 +04:00
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
2024-05-12 14:38:32 +04:00
_logger.LogInformation("Order №{id}. Status changes to 'Выдан'", id);
2024-04-07 16:54:02 +04:00
try
{
2024-05-12 14:38:32 +04:00
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
2024-05-12 14:38:32 +04:00
_logger.LogInformation("Order №{id} issued", id);
2024-04-07 16:54:02 +04:00
LoadData();
}
catch (Exception ex)
{
2024-05-12 14:38:32 +04:00
_logger.LogError(ex, "Order issue marking error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
}
2024-05-12 14:38:32 +04:00
private void ButtonUpd_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
LoadData();
}
}
2024-05-12 14:38:32 +04:00
}