141 lines
5.2 KiB
C#
141 lines
5.2 KiB
C#
using Contracts.BindingModels;
|
||
using Contracts.BusinessLogicContracts;
|
||
using DataModels.Enums;
|
||
using DataModels.Models;
|
||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||
using Microsoft.Extensions.Logging;
|
||
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 WinFormsApp
|
||
{
|
||
public partial class FormMain : Form
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly ISupplyLogic _supplyLogic;
|
||
private readonly IProductLogic _productLogic;
|
||
private readonly ISupplierLogic _supplierLogic;
|
||
public FormMain(ILogger<FormMain> logger, ISupplierLogic supplierLogic, ISupplyLogic supplyLogic, IProductLogic productLogic)
|
||
{
|
||
InitializeComponent();
|
||
_supplierLogic = supplierLogic;
|
||
_supplyLogic = supplyLogic;
|
||
_productLogic = productLogic;
|
||
_logger = logger;
|
||
}
|
||
|
||
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;
|
||
}
|
||
_logger.LogInformation("Загрузка поставок");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка загрузки поставок");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
private void товарыToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormProducts));
|
||
if (service is FormProducts form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void поставщикиToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormSuppliers));
|
||
if (service is FormSuppliers form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void buttonCreateSupply_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormSupply));
|
||
if (service is FormSupply form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
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)
|
||
{
|
||
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,
|
||
Status = (SupplyStatus)dataGridView.SelectedRows[0].Cells["Status"].Value
|
||
}, SupplyStatus.Completed);
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||
MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|