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

156 lines
6.0 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;
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;
2024-04-07 16:54:02 +04:00
2024-04-07 17:05:30 +04:00
namespace SoftwareInstallation.Forms
2024-04-07 16:54:02 +04:00
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
2024-04-07 17:05:30 +04:00
_logger.LogInformation("Загрузка заказов");
2024-04-07 16:54:02 +04:00
try
{
var list = _orderLogic.ReadList(null);
2024-04-07 17:05:30 +04:00
2024-04-07 16:54:02 +04:00
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-04-07 17:05:30 +04:00
2024-04-07 16:54:02 +04:00
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
}
}
2024-04-07 17:05:30 +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-04-07 17:05:30 +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));
2024-04-07 17:05:30 +04:00
2024-04-07 16:54:02 +04:00
if (service is FormPackages form)
{
form.ShowDialog();
}
}
2024-04-07 17:05:30 +04:00
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-04-07 17:05:30 +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-04-07 17:05:30 +04:00
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
2024-04-07 16:54:02 +04:00
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
2024-04-07 17:05:30 +04:00
Id = id,
2024-04-07 16:54:02 +04:00
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-04-07 17:05:30 +04:00
private void buttonOrderReady_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-04-07 17:05:30 +04:00
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", 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)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
2024-04-07 17:05:30 +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-04-07 17:05:30 +04:00
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
2024-04-07 16:54:02 +04:00
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = id
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
2024-04-07 17:05:30 +04:00
_logger.LogInformation("Заказ №{id} выдан", id);
2024-04-07 16:54:02 +04:00
LoadData();
}
catch (Exception ex)
{
2024-04-07 17:05:30 +04:00
_logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
}
2024-04-07 17:05:30 +04:00
private void buttonRef_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
LoadData();
}
}
}