159 lines
5.7 KiB
C#
159 lines
5.7 KiB
C#
using FlowerShopContracts.BindingModels;
|
|
using FlowerShopContracts.BusinessLogicsContracts;
|
|
using FlowerShopDataModels.Enums;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace FlowerShop
|
|
{
|
|
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 MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
_logger.LogInformation("Загрузка заказов");
|
|
try
|
|
{
|
|
var list = _orderLogic.ReadList(null);
|
|
|
|
if (list != null)
|
|
{
|
|
dataGridView.DataSource = list;
|
|
dataGridView.Columns["BouquetId"].Visible = false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during receiving orders");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
|
if (service is FormComponents form)
|
|
{
|
|
form.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void bouquetsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormBouquets));
|
|
|
|
if (service is FormBouquets form)
|
|
{
|
|
form.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
|
if (service is FormCreateOrder form)
|
|
{
|
|
form.ShowDialog();
|
|
LoadData();
|
|
}
|
|
}
|
|
|
|
private void buttonToWork_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
_logger.LogInformation("Order №{id}. Changing status to 'Processing'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
|
|
|
if (!operationResult)
|
|
{
|
|
_logger.LogError("Error during changing order's status to 'Processing'");
|
|
MessageBox.Show("Заказ должен быть в состоянии 'Принят'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during changing order's status to 'Processing'");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonReady_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
_logger.LogInformation("Order №{id}. Changing status to 'Ready'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
|
if (!operationResult)
|
|
{
|
|
_logger.LogError("Error during changing order's status to 'Ready'");
|
|
MessageBox.Show("Заказ должен быть в состоянии 'Выполняется'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during changing order's status to 'Ready'");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonPut_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
_logger.LogInformation("Order №{id}. Changing status to 'Delivered'", id);
|
|
try
|
|
{
|
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
|
|
|
if (!operationResult)
|
|
{
|
|
_logger.LogError("Error during changing order's status to 'Delivered'");
|
|
MessageBox.Show("Заказ должен быть в состоянии 'Готов'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error during changing order's status to 'Delivered'");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|