2024-06-23 22:18:51 +04:00
|
|
|
|
using Contracts.BindingModels;
|
|
|
|
|
using Contracts.BusinessLogicContracts;
|
|
|
|
|
using DataModels.Enums;
|
|
|
|
|
using DataModels.Models;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
2024-06-24 22:04:04 +04:00
|
|
|
|
using System.Diagnostics;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
using System.Drawing;
|
2024-06-24 22:04:04 +04:00
|
|
|
|
using System.Drawing.Printing;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
using System.Linq;
|
2024-06-24 22:04:04 +04:00
|
|
|
|
using System.Reflection.Metadata;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsApp
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ISupplyLogic _supplyLogic;
|
|
|
|
|
private readonly IProductLogic _productLogic;
|
|
|
|
|
private readonly ISupplierLogic _supplierLogic;
|
2024-06-24 19:26:39 +04:00
|
|
|
|
private readonly IReportLogic _reportLogic;
|
|
|
|
|
public FormMain(ILogger<FormMain> logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic, IReportLogic reportLogic)
|
2024-06-23 12:07:01 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_supplierLogic = supplierLogic;
|
|
|
|
|
_supplyLogic = supplyLogic;
|
|
|
|
|
_productLogic = productLogic;
|
|
|
|
|
_logger = logger;
|
2024-06-24 19:26:39 +04:00
|
|
|
|
_reportLogic = reportLogic;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка поставок");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _supplyLogic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
2024-06-25 13:14:23 +04:00
|
|
|
|
dataGridView.Columns["SupplierId"].Visible = false;
|
|
|
|
|
dataGridView.Columns["Products"].Visible = false;
|
2024-06-23 12:07:01 +04:00
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Загрузка поставок");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки поставок");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-23 17:04:26 +04:00
|
|
|
|
private void товарыToolStripMenuItem_Click_1(object sender, EventArgs e)
|
2024-06-23 14:01:09 +04:00
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormProducts));
|
|
|
|
|
if (service is FormProducts form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-23 17:04:26 +04:00
|
|
|
|
|
|
|
|
|
private void поставщикиToolStripMenuItem_Click_1(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormSuppliers));
|
|
|
|
|
if (service is FormSuppliers form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-23 21:35:37 +04:00
|
|
|
|
|
|
|
|
|
private void buttonCreateSupply_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormSupply));
|
|
|
|
|
if (service is FormSupply form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-23 22:18:51 +04:00
|
|
|
|
|
|
|
|
|
private void buttonSupplyStatusArriving_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
Guid id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
|
|
|
|
_logger.LogInformation("Поставка No{id}. Меняется статус", id);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _supplyLogic.StatusUpdate(new SupplyBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Status = (SupplyStatus)dataGridView.SelectedRows[0].Cells["Status"].Value
|
|
|
|
|
}, SupplyStatus.Arriving);
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
2024-06-23 22:32:43 +04:00
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonSupplyStatusCompleted_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
Guid id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
|
|
|
|
_logger.LogInformation("Поставка No{id}. Меняется статус", id);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _supplyLogic.StatusUpdate(new SupplyBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
2024-06-25 13:14:23 +04:00
|
|
|
|
Status = (SupplyStatus)dataGridView.SelectedRows[0].Cells["Status"].Value,
|
|
|
|
|
DateArriving = (DateTime?)dataGridView.SelectedRows[0].Cells["DateArriving"].Value,
|
|
|
|
|
DateComplete = (DateTime?)dataGridView.SelectedRows[0].Cells["DateComplete"].Value,
|
2024-06-23 22:32:43 +04:00
|
|
|
|
}, SupplyStatus.Completed);
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
2024-06-23 22:18:51 +04:00
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-24 19:26:39 +04:00
|
|
|
|
|
|
|
|
|
private void buttonCreateReport_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите одну поставку для формирования отчета", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-25 18:32:16 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
|
2024-06-24 19:26:39 +04:00
|
|
|
|
{
|
2024-06-25 18:32:16 +04:00
|
|
|
|
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
|
|
|
|
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
|
|
|
|
|
SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value
|
|
|
|
|
});
|
|
|
|
|
_logger.LogInformation("Сохранение отчета о поставке");
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сохранения отчета о поставке");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
2024-06-24 19:26:39 +04:00
|
|
|
|
}
|
2024-06-24 22:04:04 +04:00
|
|
|
|
|
|
|
|
|
private void buttonPrintReport_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-06-25 14:27:20 +04:00
|
|
|
|
if (dataGridView.SelectedRows.Count != 1) return;
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormPreviewPDF));
|
|
|
|
|
if (service is FormPreviewPDF form)
|
2024-06-24 22:04:04 +04:00
|
|
|
|
{
|
2024-06-25 14:27:20 +04:00
|
|
|
|
var src = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf";
|
2024-06-25 18:32:16 +04:00
|
|
|
|
if (!File.Exists(src))
|
2024-06-25 13:37:33 +04:00
|
|
|
|
{
|
2024-06-25 15:47:50 +04:00
|
|
|
|
var result = MessageBox.Show("Отчёт о поставке не был найден. Сформировать?", "", MessageBoxButtons.YesNo);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_reportLogic.SaveSuppliesToPdfFile(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
FileName = $"supplyreport{dataGridView.SelectedRows[0].Cells["Id"].Value}.pdf",
|
|
|
|
|
Date = (DateTime)dataGridView.SelectedRows[0].Cells["Date"].Value,
|
|
|
|
|
SupplyId = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value
|
|
|
|
|
});
|
|
|
|
|
_logger.LogInformation("Сохранение отчета о поставке");
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сохранения отчета о поставке");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else return;
|
2024-06-25 14:27:20 +04:00
|
|
|
|
}
|
|
|
|
|
form.src = System.IO.Path.GetFullPath(src);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
IronPrint.Printer.PrintAsync(src);
|
2024-06-25 13:37:33 +04:00
|
|
|
|
}
|
2024-06-24 22:04:04 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-25 13:14:23 +04:00
|
|
|
|
|
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
2024-06-25 18:32:16 +04:00
|
|
|
|
|
|
|
|
|
private void статистикаToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormStatistics));
|
|
|
|
|
if (service is FormStatistics form)
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-23 12:07:01 +04:00
|
|
|
|
}
|
|
|
|
|
}
|