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

295 lines
11 KiB
C#
Raw Normal View History

2024-05-19 11:21:27 +04:00
using SoftwareInstallationBusinessLogic.BusinessLogic;
2024-05-12 14:45:39 +04:00
using SoftwareInstallationContracts.BindingModels;
2024-04-07 16:54:02 +04:00
using SoftwareInstallationContracts.BusinessLogicsContracts;
2024-05-19 11:21:27 +04:00
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Enums;
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-05-19 11:21:27 +04:00
namespace SoftwareInstallation
2024-04-07 16:54:02 +04:00
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
2024-05-19 11:21:27 +04:00
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
2024-04-07 16:54:02 +04:00
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
2024-05-19 11:21:27 +04:00
_reportLogic = reportLogic;
}
private void КомпонентыStripMenuItem_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(ComponentsForm));
if (service is ComponentsForm form)
{
form.ShowDialog();
}
2024-04-07 16:54:02 +04:00
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void MainForm_Load(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
LoadData();
}
2024-05-12 14:45:39 +04:00
2024-04-07 16:54:02 +04:00
private void LoadData()
{
2024-05-19 11:21:27 +04:00
_logger.LogInformation("Загрузка заказов");
2024-04-07 16:54:02 +04:00
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
2024-05-19 11:21:27 +04:00
DataGridView.DataSource = list;
DataGridView.Columns["PackageId"].Visible = false;
DataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
2024-04-07 16:54:02 +04:00
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
2024-05-12 14:45:39 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void ПутевкаStripMenuItem_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
var service = Program.ServiceProvider?.GetService(typeof(FormPackages));
if (service is FormPackages form)
2024-04-07 16:54:02 +04:00
{
form.ShowDialog();
}
}
2024-05-12 14:45:39 +04:00
2024-06-17 20:50:46 +04:00
private void ClientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
2024-05-19 11:21:27 +04:00
private void CreateOrderButton_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
var service =
Program.ServiceProvider?.GetService(typeof(OrderForm));
if (service is OrderForm form)
2024-04-07 16:54:02 +04:00
{
form.ShowDialog();
2024-05-19 11:21:27 +04:00
LoadData();
2024-04-07 16:54:02 +04:00
}
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private OrderBindingModel CreateBindingModel(int id, bool isDone = false)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
return new OrderBindingModel
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
Id = id,
PackageId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["PackageId"].Value),
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
};
2024-04-07 16:54:02 +04:00
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void TakeInWorkButton_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
if (DataGridView.SelectedRows.Count == 1)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +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-05-19 11:21:27 +04:00
var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id));
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
2024-05-19 11:21:27 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
2024-05-19 11:21:27 +04:00
2024-04-07 16:54:02 +04:00
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void ReadyButton_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
if (DataGridView.SelectedRows.Count == 1)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +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-05-19 11:21:27 +04:00
var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id));
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
2024-05-19 11:21:27 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void IssuedButton_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +04:00
if (DataGridView.SelectedRows.Count == 1)
2024-04-07 16:54:02 +04:00
{
2024-05-19 11:21:27 +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-05-19 11:21:27 +04:00
var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id));
2024-04-07 16:54:02 +04:00
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
2024-05-19 11:21:27 +04:00
_logger.LogInformation("Заказ №{id} выдан", id);
2024-04-07 16:54:02 +04:00
LoadData();
}
catch (Exception ex)
{
2024-05-12 14:45:39 +04:00
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
2024-05-19 11:21:27 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
2024-04-07 16:54:02 +04:00
}
}
2024-05-19 11:21:27 +04:00
2024-04-07 16:54:02 +04:00
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void RefreshButton_Click(object sender, EventArgs e)
2024-04-07 16:54:02 +04:00
{
LoadData();
}
2024-05-12 14:45:39 +04:00
2024-05-19 11:21:27 +04:00
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(ShopsForm));
if (service is ShopsForm form)
{
form.ShowDialog();
}
}
private void поставкиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(SupplyForm));
if (service is SupplyForm form)
{
form.ShowDialog();
}
}
private void продажиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(SellForm));
if (service is SellForm 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.SavePackageToWordFile(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(ReportPackageComponentForm));
if (service is ReportPackageComponentForm form)
{
form.ShowDialog();
}
}
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-12 14:45:39 +04:00
{
2024-05-19 11:21:27 +04:00
var service =
Program.ServiceProvider?.GetService(typeof(ReportOrdersForm));
if (service is ReportOrdersForm form)
2024-05-12 14:45:39 +04:00
{
form.ShowDialog();
}
2024-05-19 11:21:27 +04:00
}
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);
}
2024-05-12 14:45:39 +04:00
}
2024-05-19 11:21:27 +04:00
private void ПутевкаПоМагазинамToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-12 14:45:39 +04:00
{
2024-05-19 11:21:27 +04:00
var service =
Program.ServiceProvider?.GetService(typeof(ReportShopsSoftwareInstallationForm));
if (service is ReportShopsSoftwareInstallationForm form)
2024-05-12 14:45:39 +04:00
{
form.ShowDialog();
}
}
2024-05-19 11:21:27 +04:00
private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-12 14:45:39 +04:00
{
2024-05-19 11:21:27 +04:00
var service =
Program.ServiceProvider?.GetService(typeof(ReportDateOrdersForm));
if (service is ReportDateOrdersForm form)
2024-05-12 14:45:39 +04:00
{
form.ShowDialog();
}
}
2024-04-07 16:54:02 +04:00
}
}