2023-02-19 11:27:59 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using PrecastConcretePlant;
|
2023-04-19 22:48:32 +03:00
|
|
|
|
using PrecastConcretePlantBusinessLogic.BusinessLogic;
|
2023-02-19 11:27:59 +04:00
|
|
|
|
using PrecastConcretePlantContracts.BindingModels;
|
|
|
|
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
2023-05-21 13:53:18 +03:00
|
|
|
|
using PrecastConcretePlantContracts.DI;
|
2023-02-19 11:27:59 +04:00
|
|
|
|
using PrecastConcretePlantDataModels.Enums;
|
2023-05-20 22:04:30 +03:00
|
|
|
|
using PrecastConcretePlantView;
|
2023-02-19 11:27:59 +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
|
|
|
|
|
{
|
2023-05-20 22:04:30 +03:00
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IOrderLogic _orderLogic;
|
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
private readonly IWorkProcess _workProcess;
|
2023-05-21 13:53:18 +03:00
|
|
|
|
private readonly IBackUpLogic _backUpLogic;
|
2023-05-20 22:04:30 +03:00
|
|
|
|
|
2023-05-21 13:53:18 +03:00
|
|
|
|
public FormMain(ILogger<FormMain> logger, IBackUpLogic backUpLogic, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic)
|
2023-05-20 22:04:30 +03:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_orderLogic = orderLogic;
|
|
|
|
|
_reportLogic = reportLogic;
|
|
|
|
|
_workProcess = workProcess;
|
2023-05-21 13:53:18 +03:00
|
|
|
|
_backUpLogic = backUpLogic;
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка заказов");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
DataGridView.FillandConfigGrid(_orderLogic.ReadList(null));
|
2023-05-20 22:04:30 +03:00
|
|
|
|
_logger.LogInformation("Загрузка заказов");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormComponents>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormReinforceds>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateOrderButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadData();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TakeOrderInWorkButton_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 IssuedOrderButton_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("Ошибка при сохранении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OrderReadyButton_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 UpdateListButton_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.SaveReinforcedsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormReportReinforcedComponents>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormClients>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
|
2023-05-20 22:04:30 +03:00
|
|
|
|
MessageBox.Show("Процесс обработки запущен", "Сообщение",
|
2023-05-21 13:53:18 +03:00
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormImplementers>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-21 13:53:18 +03:00
|
|
|
|
private void элписьмаToolStripMenuItem_Click_1(object sender, EventArgs e)
|
2023-05-20 22:04:30 +03:00
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
var form = DependencyManager.Instance.Resolve<FormMails>();
|
|
|
|
|
form.ShowDialog();
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-21 13:53:18 +03:00
|
|
|
|
private void бекапToolStripMenuItem_Click(object sender, EventArgs e)
|
2023-05-20 22:04:30 +03:00
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_backUpLogic != null)
|
|
|
|
|
{
|
|
|
|
|
var fbd = new FolderBrowserDialog();
|
|
|
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel
|
|
|
|
|
{
|
|
|
|
|
FolderName = fbd.SelectedPath
|
|
|
|
|
});
|
|
|
|
|
MessageBox.Show("Бекап создан", "Сообщение",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2023-05-20 22:04:30 +03:00
|
|
|
|
{
|
2023-05-21 13:53:18 +03:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error);
|
2023-05-20 22:04:30 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-19 11:27:59 +04:00
|
|
|
|
}
|