2024-05-16 21:48:52 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-04-05 17:36:10 +04:00
|
|
|
|
using PrecastConcretePlantBusinessLogic.BusinessLogics;
|
2024-03-22 20:10:17 +04:00
|
|
|
|
using PrecastConcretePlantContracts.BindingModels;
|
|
|
|
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IOrderLogic _orderLogic;
|
2024-04-05 17:36:10 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
2024-03-22 20:10:17 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_orderLogic = orderLogic;
|
2024-04-05 17:36:10 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _orderLogic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
|
|
|
|
dataGridView.Columns["ReinforcedId"].Visible = false;
|
|
|
|
|
dataGridView.Columns["ReinforcedName"].AutoSizeMode =
|
|
|
|
|
DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogInformation("Загрузка заказов");
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки заказов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-03-22 20:10:17 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponentS));
|
|
|
|
|
if (service is FormComponentS form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-03-22 20:10:17 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedS));
|
|
|
|
|
if (service is FormReinforcedS form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-04-18 23:41:30 +04:00
|
|
|
|
{
|
2024-05-17 00:59:46 +04:00
|
|
|
|
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
2024-04-18 23:41:30 +04:00
|
|
|
|
{
|
2024-05-17 00:59:46 +04:00
|
|
|
|
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2024-04-18 23:41:30 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-04-18 23:41:30 +04:00
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
|
|
|
|
|
if (service is FormShopReplenishment form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
private void ПродажаИзделийToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-05-16 21:48:52 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale));
|
|
|
|
|
if (service is FormReinforcedSale form)
|
2024-04-18 23:41:30 +04:00
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-22 20:10:17 +04:00
|
|
|
|
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);
|
2024-05-17 00:19:57 +04:00
|
|
|
|
_logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
2024-05-17 00:19:57 +04:00
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
2024-05-17 00:19:57 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-17 00:19:57 +04:00
|
|
|
|
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-17 00:19:57 +04:00
|
|
|
|
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
2024-05-17 00:19:57 +04:00
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
2024-05-17 00:19:57 +04:00
|
|
|
|
_logger.LogInformation("Заказ No{id} выдан", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
2024-05-17 00:19:57 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRef_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
2024-05-17 00:19:57 +04:00
|
|
|
|
private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-04-05 17:36:10 +04:00
|
|
|
|
{
|
|
|
|
|
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveReinforcedsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
|
2024-05-17 00:19:57 +04:00
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2024-04-05 17:36:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 00:19:57 +04:00
|
|
|
|
private void изделияПоКомпонентамToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-04-05 17:36:10 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormReportReinforcedComponents));
|
|
|
|
|
if (service is FormReportReinforcedComponents form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 00:19:57 +04:00
|
|
|
|
private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e)
|
2024-04-05 17:36:10 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
|
|
|
|
if (service is FormReportOrders form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|