181 lines
6.7 KiB
C#
181 lines
6.7 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using MotorPlantContracts.BindingModels;
|
|
using MotorPlantContracts.BusinessLogicsContracts;
|
|
using MotorPlantBusinessLogic;
|
|
|
|
namespace MotorPlantView.Forms
|
|
{
|
|
public partial class FormMain : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IOrderLogic _orderLogic;
|
|
private readonly IReportLogic _reportLogic;
|
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_orderLogic = orderLogic;
|
|
_reportLogic = reportLogic;
|
|
}
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
private void LoadData()
|
|
{
|
|
_logger.LogInformation("Çàãðóçêà çàêàçîâ");
|
|
try
|
|
{
|
|
var list = _orderLogic.ReadList(null);
|
|
|
|
if (list != null)
|
|
{
|
|
dataGridView.DataSource = list;
|
|
dataGridView.Columns["EngineId"].Visible = false;
|
|
dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
}
|
|
|
|
_logger.LogInformation("Çàãðóçêà çàêàçîâ");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Îøèáêà çàãðóçêè çàêàçîâ");
|
|
}
|
|
}
|
|
private void ÊîìïîíåíòûToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
|
if (service is FormComponents form)
|
|
{
|
|
form.ShowDialog();
|
|
}
|
|
}
|
|
private void ÈçäåëèÿToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormEngines));
|
|
|
|
if (service is FormEngines form)
|
|
{
|
|
form.ShowDialog();
|
|
}
|
|
}
|
|
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
|
if (service is FormCreateOrder form)
|
|
{
|
|
form.ShowDialog();
|
|
LoadData();
|
|
}
|
|
}
|
|
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
_logger.LogInformation("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Â ðàáîòå'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
|
{
|
|
Id = id,
|
|
});
|
|
if (!operationResult)
|
|
{
|
|
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
|
|
}
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Îøèáêà ïåðåäà÷è çàêàçà â ðàáîòó");
|
|
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("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Ãîòîâ'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
|
if (!operationResult)
|
|
{
|
|
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
|
|
}
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Îøèáêà îòìåòêè î ãîòîâíîñòè çàêàçà");
|
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
private void buttonIssuedOrder_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
_logger.LogInformation("Çàêàç ¹{id}. Ìåíÿåòñÿ ñòàòóñ íà 'Âûäàí'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
|
{
|
|
Id = id
|
|
});
|
|
if (!operationResult)
|
|
{
|
|
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
|
|
}
|
|
_logger.LogInformation("Çàêàç ¹{id} âûäàí", id);
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Îøèáêà îòìåòêè î âûäà÷è çàêàçà"); MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
private void buttonRef_Click(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
private void ñïèñîêÊîìïîíåíòîâToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
_reportLogic.SaveEnginesToWordFile(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(FormReportEngineComponents));
|
|
if (service is FormReportEngineComponents 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();
|
|
}
|
|
}
|
|
}
|
|
}
|