2024-05-16 21:48:52 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
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;
|
|
|
|
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_orderLogic = orderLogic;
|
|
|
|
|
}
|
|
|
|
|
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;
|
2024-05-16 21:48:52 +04:00
|
|
|
|
dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var service =
|
|
|
|
|
Program.ServiceProvider?.GetService(typeof(FormComponentS));
|
2024-03-22 20:10:17 +04:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
|
|
|
|
if (service is FormShops 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-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)
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var service =
|
|
|
|
|
Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
2024-03-22 20:10:17 +04:00
|
|
|
|
if (service is FormCreateOrder form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
int id =
|
|
|
|
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogInformation("Заказ {id}. Меняется статус на 'В работе'", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
2024-03-22 20:10:17 +04:00
|
|
|
|
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,
|
2024-05-16 21:48:52 +04:00
|
|
|
|
MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
int id =
|
|
|
|
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogInformation("Заказ {id}. Меняется статус на 'Готов'",
|
2024-05-16 21:48:52 +04:00
|
|
|
|
id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var operationResult = _orderLogic.FinishOrder(new
|
|
|
|
|
OrderBindingModel
|
|
|
|
|
{ Id = id });
|
2024-03-22 20:10:17 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
int id =
|
|
|
|
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogInformation("Заказ {id}. Меняется статус на 'Выдан'", id);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-16 21:48:52 +04:00
|
|
|
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
2024-03-22 20:10:17 +04:00
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
2024-05-16 21:59:54 +04:00
|
|
|
|
throw new Exception("Ошибка");
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
2024-05-16 21:59:54 +04:00
|
|
|
|
_logger.LogInformation("Заказ {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, "Ошибка отметки о выдачи заказа");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
2024-05-16 21:48:52 +04:00
|
|
|
|
MessageBoxIcon.Error);
|
2024-03-22 20:10:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 21:48:52 +04:00
|
|
|
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
2024-03-22 20:10:17 +04:00
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|