250 lines
9.5 KiB
C#
250 lines
9.5 KiB
C#
using AccountingWarehouseProductsContracts.BindingModels;
|
||
using AccountingWarehouseProductsContracts.BusinessLogicsContracts;
|
||
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 AccountingWarehouseProductsView
|
||
{
|
||
public partial class FormMain : Form
|
||
{
|
||
private readonly IOrderLogic _logic;
|
||
private readonly IProductLogic _productLogic;
|
||
public FormMain(IOrderLogic logic, IProductLogic productLogic)
|
||
{
|
||
InitializeComponent();
|
||
_logic = logic;
|
||
_productLogic = productLogic;
|
||
}
|
||
|
||
private void продуктToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormProducts));
|
||
if (service is FormProducts form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void складскоеПомещениеToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormWarehouses));
|
||
if (service is FormWarehouses form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void поставщикToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormSuppliers));
|
||
if (service is FormSuppliers form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void поставкаToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormStands));
|
||
if (service is FormStands form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void отгрузкаToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormShipments));
|
||
if (service is FormShipments form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void FormMain_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
|
||
private void LoadData()
|
||
{
|
||
var _list = _logic.ReadList(null);
|
||
if (_list != null)
|
||
{
|
||
dataGridView.DataSource = _list;
|
||
dataGridView.Columns["ProductId"].Visible = false;
|
||
dataGridView.Columns["SupplierId"].Visible = false;
|
||
//dataGridView.Columns["WarehouseId"].Visible = false;
|
||
//dataGridView.Columns["SupplierId"].Visible = false;
|
||
//dataGridView.Columns["StandId"].Visible = false;
|
||
//dataGridView.Columns["ShipmentId"].Visible = false;
|
||
dataGridView.Columns["OrderProduct"].Visible = false;
|
||
//dataGridView.Columns["WarehouseProducts"].Visible = false;
|
||
}
|
||
}
|
||
|
||
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 buttonComeOrder_Click(Object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _logic.ComeOrder(new OrderBindingModel
|
||
{
|
||
Id = id,
|
||
Status = Enum.Parse<AccountingWarehouseProductsDataModels.Enums.OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||
});
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonTakeOrder_Click(Object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _logic.TakeOrder(new OrderBindingModel
|
||
{
|
||
Id = id,
|
||
Status = Enum.Parse<AccountingWarehouseProductsDataModels.Enums.OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||
DateofOrder = DateTime.Now,
|
||
});
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonArrangeOrder_Click(Object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _logic.ArrangeOrder(new OrderBindingModel
|
||
{
|
||
Id = id,
|
||
Status = Enum.Parse<AccountingWarehouseProductsDataModels.Enums.OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||
});
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonChekOrder_Click(Object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _logic.ChekOrder(new OrderBindingModel
|
||
{
|
||
Id = id,
|
||
Status = Enum.Parse<AccountingWarehouseProductsDataModels.Enums.OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||
});
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonDeliverOrder_Click(Object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count == 1)
|
||
{
|
||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||
try
|
||
{
|
||
var operationResult = _logic.DeliverOrder(new OrderBindingModel
|
||
{
|
||
Id = id,
|
||
Status = Enum.Parse<AccountingWarehouseProductsDataModels.Enums.OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||
DateImplement = DateTime.Now,
|
||
});
|
||
if (!operationResult)
|
||
{
|
||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||
}
|
||
LoadData();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonTest_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
ProductBindingModel model = new ProductBindingModel()
|
||
{
|
||
ProductName = "Вкуснятина",
|
||
Cost = 1000000,
|
||
DateofFabrication = DateTime.Now,
|
||
ValidUntil = null,
|
||
Category = "Вкусное"
|
||
};
|
||
|
||
DateTime start = DateTime.Now;
|
||
_productLogic.Create(model);
|
||
DateTime stop = DateTime.Now;
|
||
MessageBox.Show((stop - start).ToString(), "Test", MessageBoxButtons.OK);
|
||
}
|
||
}
|
||
}
|