visual studio momento

This commit is contained in:
DavidMakarov 2024-06-21 16:01:34 +04:00
parent 18a0b79d79
commit 6cf160b0b2
10 changed files with 240 additions and 522 deletions

View File

@ -22,178 +22,6 @@
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
menuStrip1 = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
ЦветыToolStripMenuItem = new ToolStripMenuItem();
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem();
исполнителиToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
списокЦветковToolStripMenuItem = new ToolStripMenuItem();
компонентыПоЦветамToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
запускToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
menuStrip1.Size = new Size(1102, 30);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
//
// ЦветыToolStripMenuItem
//
ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem";
ЦветыToolStripMenuItem.Size = new Size(185, 26);
ЦветыToolStripMenuItem.Text = "Цветы";
ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click;
//
// КомпонентыToolStripMenuItem
//
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
КомпонентыToolStripMenuItem.Size = new Size(185, 26);
КомпонентыToolStripMenuItem.Text = "Компоненты";
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(185, 26);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
//
// исполнителиToolStripMenuItem
//
исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
исполнителиToolStripMenuItem.Size = new Size(185, 26);
исполнителиToolStripMenuItem.Text = "Исполнители";
исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem
//
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЦветковToolStripMenuItem, компонентыПоЦветамToolStripMenuItem, списокЗаказовToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(73, 24);
отчётыToolStripMenuItem.Text = "Отчёты";
//
// списокЦветковToolStripMenuItem
//
списокЦветковToolStripMenuItem.Name = "списокЦветковToolStripMenuItem";
списокЦветковToolStripMenuItem.Size = new Size(258, 26);
списокЦветковToolStripMenuItem.Text = "Список цветков";
списокЦветковToolStripMenuItem.Click += списокЦветковToolStripMenuItem_Click;
//
// компонентыПоЦветамToolStripMenuItem
//
компонентыПоЦветамToolStripMenuItem.Name = омпонентыПоЦветамToolStripMenuItem";
компонентыПоЦветамToolStripMenuItem.Size = new Size(258, 26);
компонентыПоЦветамToolStripMenuItem.Text = "Компоненты по цветам";
компонентыПоЦветамToolStripMenuItem.Click += компонентыПоЦветамToolStripMenuItem_Click;
//
// списокЗаказовToolStripMenuItem
//
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
списокЗаказовToolStripMenuItem.Size = new Size(258, 26);
списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
//
// запускToolStripMenuItem
//
запускToolStripMenuItem.Name = апускToolStripMenuItem";
запускToolStripMenuItem.Size = new Size(114, 24);
запускToolStripMenuItem.Text = "Запуск работ";
запускToolStripMenuItem.Click += запускToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(14, 36);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(845, 548);
dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(886, 73);
buttonCreateOrder.Margin = new Padding(3, 4, 3, 4);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(181, 43);
buttonCreateOrder.TabIndex = 2;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(886, 147);
buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(181, 43);
buttonIssuedOrder.TabIndex = 3;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonRef
//
buttonRef.Location = new Point(886, 220);
buttonRef.Margin = new Padding(3, 4, 3, 4);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(181, 43);
buttonRef.TabIndex = 6;
buttonRef.Text = "Обновить список";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1102, 600);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 4, 3, 4);
Name = "FormMain";
Text = "Цветочный магазин";
Load += FormMain_Load;
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
@ -206,6 +34,7 @@
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem();
исполнителиToolStripMenuItem1 = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
списокЦветковToolStripMenuItem = new ToolStripMenuItem();
компонентыПоЦветамToolStripMenuItem = new ToolStripMenuItem();
@ -213,14 +42,13 @@
списокМагазиновToolStripMenuItem = new ToolStripMenuItem();
загруженностьМагазиновToolStripMenuItem = new ToolStripMenuItem();
заказыПоДатамToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
продажаЦветовToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -228,7 +56,7 @@
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаЦветовToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаЦветовToolStripMenuItem, запускРаботToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
@ -238,7 +66,7 @@
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem, клиентыToolStripMenuItem });
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem1 });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
@ -246,31 +74,38 @@
// ЦветыToolStripMenuItem
//
ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem";
ЦветыToolStripMenuItem.Size = new Size(182, 26);
ЦветыToolStripMenuItem.Size = new Size(224, 26);
ЦветыToolStripMenuItem.Text = "Цветы";
ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click;
//
// КомпонентыToolStripMenuItem
//
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
КомпонентыToolStripMenuItem.Size = new Size(182, 26);
КомпонентыToolStripMenuItem.Size = new Size(224, 26);
КомпонентыToolStripMenuItem.Text = "Компоненты";
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(182, 26);
клиентыToolStripMenuItem.Size = new Size(224, 26);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
//
// исполнителиToolStripMenuItem1
//
исполнителиToolStripMenuItem1.Name = сполнителиToolStripMenuItem1";
исполнителиToolStripMenuItem1.Size = new Size(224, 26);
исполнителиToolStripMenuItem1.Text = "Исполнители";
исполнителиToolStripMenuItem1.Click += исполнителиToolStripMenuItem1_Click;
//
// отчётыToolStripMenuItem
//
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЦветковToolStripMenuItem, компонентыПоЦветамToolStripMenuItem, списокЗаказовToolStripMenuItem, списокМагазиновToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem });
@ -320,6 +155,27 @@
заказыПоДатамToolStripMenuItem.Text = "Заказы по датам";
заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click;
//
// пополнениеМагазинаToolStripMenuItem
//
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24);
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click;
//
// продажаЦветовToolStripMenuItem
//
продажаЦветовToolStripMenuItem.Name = "продажаЦветовToolStripMenuItem";
продажаЦветовToolStripMenuItem.Size = new Size(139, 24);
продажаЦветовToolStripMenuItem.Text = "Продажа цветов";
продажаЦветовToolStripMenuItem.Click += продажаЦветовToolStripMenuItem_Click;
//
// запускРаботToolStripMenuItem
//
запускРаботToolStripMenuItem.Name = апускРаботToolStripMenuItem";
запускРаботToolStripMenuItem.Size = new Size(114, 24);
запускРаботToolStripMenuItem.Text = "Запуск работ";
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = Color.White;
@ -343,31 +199,9 @@
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(886, 147);
buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(181, 45);
buttonTakeOrderInWork.TabIndex = 3;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(886, 224);
buttonOrderReady.Margin = new Padding(3, 4, 3, 4);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(181, 45);
buttonOrderReady.TabIndex = 4;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(886, 307);
buttonIssuedOrder.Location = new Point(886, 146);
buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(181, 45);
@ -378,7 +212,7 @@
//
// buttonRef
//
buttonRef.Location = new Point(886, 385);
buttonRef.Location = new Point(886, 224);
buttonRef.Margin = new Padding(3, 4, 3, 4);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(181, 45);
@ -387,20 +221,6 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// пополнениеМагазинаToolStripMenuItem
//
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24);
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click;
//
// продажаЦветовToolStripMenuItem
//
продажаЦветовToolStripMenuItem.Name = "продажаЦветовToolStripMenuItem";
продажаЦветовToolStripMenuItem.Size = new Size(139, 24);
продажаЦветовToolStripMenuItem.Text = "Продажа цветов";
продажаЦветовToolStripMenuItem.Click += продажаЦветовToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -408,8 +228,6 @@
ClientSize = new Size(1102, 600);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
@ -425,22 +243,12 @@
PerformLayout();
}
#endregion
private void ПродажаЦветовToolStripMenuItem_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem ЦветыToolStripMenuItem;
private ToolStripMenuItem КомпонентыToolStripMenuItem;
private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem ЦветыToolStripMenuItem;
private ToolStripMenuItem КомпонентыToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem списокЦветковToolStripMenuItem;
private ToolStripMenuItem компонентыПоЦветамToolStripMenuItem;
@ -449,25 +257,14 @@
private Button buttonCreateOrder;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem списокЦветковToolStripMenuItem;
private ToolStripMenuItem компонентыПоЦветамToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускToolStripMenuItem;
}
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem списокМагазиновToolStripMenuItem;
private ToolStripMenuItem загруженностьМагазиновToolStripMenuItem;
private ToolStripMenuItem заказыПоДатамToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаЦветовToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem1;
private ToolStripMenuItem запускРаботToolStripMenuItem;
}
}

View File

@ -4,109 +4,19 @@ using Microsoft.Extensions.Logging;
namespace FlowerShopView
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
}
private void FormMain_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["FlowerId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ЦветыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
if (service is FormFlowers form)
{
form.ShowDialog();
}
}
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 ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
}
private void FormMain_Load(object sender, EventArgs e)
{
@ -123,6 +33,7 @@ namespace FlowerShopView
dataGridView.DataSource = list;
dataGridView.Columns["FlowerId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
}
}
catch (Exception ex)
@ -156,55 +67,6 @@ namespace FlowerShopView
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{ Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
@ -285,30 +147,15 @@ namespace FlowerShopView
}
}
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void запускToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders));
@ -327,14 +174,6 @@ namespace FlowerShopView
}
}
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMakeSupply));
@ -352,5 +191,20 @@ namespace FlowerShopView
form.ShowDialog();
}
}
private void исполнителиToolStripMenuItem1_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

View File

@ -32,6 +32,7 @@ namespace FlowerShopView
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ViewFlowers"].Visible = false;
dataGridView.Columns["ShopFlowers"].Visible = false;
}
_logger.LogInformation("Shops loading");

View File

@ -13,12 +13,11 @@ namespace FlowerShopBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
static readonly object _locker = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IFlowerStorage _flowerStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IFlowerStorage flowerStorage, IShopStorage shopStorage, IShopLogic shopLogic)
static readonly object _locker = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IFlowerStorage flowerStorage, IShopStorage shopStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
@ -110,9 +109,10 @@ namespace FlowerShopBusinessLogic.BusinessLogics
model.Count = element.Count;
model.Sum = element.Sum;
if (model.Status != orderStatus - 1)
if ((model.Status + 1 != orderStatus && model.Status != OrderStatus.Ожидание)
|| (model.Status == OrderStatus.Ожидание && orderStatus != OrderStatus.Выдан))
{
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
_logger.LogWarning("Change status operation failed");
return false;
}
if (orderStatus == OrderStatus.Выдан)
@ -124,12 +124,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics
}
if (!SupplyFlowers(flower, model.Count))
{
_logger.LogWarning("Change status operation failed. Flowers delivery operation failed");
return false;
}
_logger.LogWarning("Change status operation failed. Ice creams delivery operation failed");
model.Status = OrderStatus.Ожидание;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
}
return false;
}
}
model.Status = orderStatus;
if (model.Status == OrderStatus.Готов)
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
}

View File

@ -19,84 +19,86 @@ namespace FlowerShopBusinessLogic.BusinessLogics
_rnd = new Random(1000);
}
public void DoWork(IImplementerLogic ImplementerLogic, IOrderLogic OrderLogic)
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
{
_orderLogic = OrderLogic;
var Implementers = ImplementerLogic.ReadList(null);
if (Implementers == null)
_orderLogic = orderLogic;
var implementers = implementerLogic.ReadList(null);
if (implementers == null)
{
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var Orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
var BeingProcessedOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется });
if (Orders == null || BeingProcessedOrders == null || (Orders.Count == 0 && BeingProcessedOrders.Count == 0))
List<OrderViewModel>? orders = new();
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Принят }) ?? new());
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Выполняется }) ?? new());
orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Ожидание }) ?? new());
if (orders.Count == 0)
{
_logger.LogWarning("DoWork. Orders is null or empty");
_logger.LogWarning("DoWork. Orders is empty");
return;
}
_logger.LogDebug("DoWork for {Count} orders", Orders.Count);
foreach (var Implementer in Implementers)
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
foreach (var implementer in implementers)
{
Task.Run(() => WorkerWorkAsync(Implementer, Orders));
Task.Run(() => WorkerWorkAsync(implementer, orders));
}
}
private async Task WorkerWorkAsync(ImplementerViewModel Implementer, List<OrderViewModel> Orders)
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
{
if (_orderLogic == null || Implementer == null)
if (_orderLogic == null || implementer == null)
{
return;
}
await RunOrderInWork(Implementer);
await RunWaitingOrders(implementer);
await RunOrderInWork(implementer);
await Task.Run(() =>
{
foreach (var Order in Orders)
foreach (var order in orders)
{
try
{
_logger.LogDebug("WorkerWorkAsync. Worker {Id} try get order {Order}", Implementer.Id, Order.Id);
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
bool AcquireResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = Order.Id,
ImplementerId = Implementer.Id
Id = order.Id,
ImplementerId = implementer.Id
});
if (!AcquireResult)
{
_logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", Implementer.Id, Order.Id);
_logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", implementer.Id, order.Id);
continue;
}
Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 1000) * Order.Count);
_logger.LogDebug("WorkerWorkAsync. Worker {Id} finish order {Order}", Implementer.Id, Order.Id);
// делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = Order.Id
Id = order.Id
});
Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100));
}
_logger.LogDebug("DoWork. Order {Order} delivery", order.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = order.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
// кто-то мог уже перехватить заказ, игнорируем ошибку
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
// заканчиваем выполнение имитации в случае иной ошибки
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
});
}
@ -127,7 +129,11 @@ namespace FlowerShopBusinessLogic.BusinessLogics
{
Id = RunOrder.Id
});
_logger.LogDebug("DoWork. Order {Order} delivery", RunOrder.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = RunOrder.Id
});
Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100));
}
@ -142,5 +148,48 @@ namespace FlowerShopBusinessLogic.BusinessLogics
throw;
}
}
private async Task RunWaitingOrders(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel
{
ImplementerId = implementer.Id,
Status = OrderStatus.Ожидание
}));
if (waitingOrders == null || waitingOrders.Count == 0)
{
return;
}
_logger.LogDebug("RunWaitingOrders for {Count} orders. Implementer: {id}.", waitingOrders.Count, implementer.Id);
foreach (var waitingOrder in waitingOrders)
{
try
{
_logger.LogInformation("RunWaitingOrders. Order {Order} delivery", waitingOrder.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = waitingOrder.Id
});
_logger.LogDebug("DoWork. Order {Order} delivery", waitingOrder.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = waitingOrder.Id
});
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}
}

View File

@ -6,6 +6,7 @@
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
Выдан = 3,
Ожидание = 4
}
}

View File

@ -12,11 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FlowerShopDatabaseImplement.Migrations
{
[DbContext(typeof(FlowerShopDatabase))]
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.Designer.cs
[Migration("20240517110214_InitCreate")]
========
[Migration("20240422161656_InitCreate")]
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.Designer.cs
[Migration("20240617101659_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -264,11 +260,7 @@ namespace FlowerShopDatabaseImplement.Migrations
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client")
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.Designer.cs
.WithMany("Orders")
========
.WithMany()
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.Designer.cs
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -279,10 +271,15 @@ namespace FlowerShopDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.Designer.cs
b.HasOne("FlowerShopDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Order")
.HasForeignKey("ImplementerId");
b.Navigation("Client");
b.Navigation("Flower");
b.Navigation("Implementer");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
@ -307,17 +304,6 @@ namespace FlowerShopDatabaseImplement.Migrations
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
========
b.HasOne("FlowerShopDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Order")
.HasForeignKey("ImplementerId");
b.Navigation("Client");
b.Navigation("Flower");
b.Navigation("Implementer");
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.Designer.cs
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
@ -332,15 +318,14 @@ namespace FlowerShopDatabaseImplement.Migrations
b.Navigation("Orders");
});
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.Designer.cs
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Flowers");
========
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Order");
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.Designer.cs
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Flowers");
});
#pragma warning restore 612, 618
}

View File

@ -54,25 +54,11 @@ namespace FlowerShopDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.cs
name: "Shops",
========
name: "Implementers",
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.cs
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.cs
ShopName = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
DateOpening = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
MaximumFlowers = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
========
ImplementerFIO = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
WorkExperience = table.Column<int>(type: "integer", nullable: false),
@ -81,7 +67,22 @@ namespace FlowerShopDatabaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.cs
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShopName = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
DateOpening = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
MaximumFlowers = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
@ -196,7 +197,11 @@ namespace FlowerShopDatabaseImplement.Migrations
column: "FlowerId");
migrationBuilder.CreateIndex(
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.cs
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
migrationBuilder.CreateIndex(
name: "IX_ShopFlowers_FlowerId",
table: "ShopFlowers",
column: "FlowerId");
@ -205,11 +210,6 @@ namespace FlowerShopDatabaseImplement.Migrations
name: "IX_ShopFlowers_ShopId",
table: "ShopFlowers",
column: "ShopId");
========
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.cs
}
protected override void Down(MigrationBuilder migrationBuilder)
@ -229,15 +229,14 @@ namespace FlowerShopDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Implementers");
migrationBuilder.DropTable(
name: "Flowers");
migrationBuilder.DropTable(
<<<<<<<< HEAD:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240517110214_InitCreate.cs
name: "Shops");
========
name: "Implementers");
>>>>>>>> origin/lab6:FlowerShop/FlowerShopDatabaseImplement/Migrations/20240422161656_InitCreate.cs
}
}
}

View File

@ -258,7 +258,7 @@ namespace FlowerShopDatabaseImplement.Migrations
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client")
.WithMany()
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -280,6 +280,30 @@ namespace FlowerShopDatabaseImplement.Migrations
b.Navigation("Implementer");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
{
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
.WithMany()
.HasForeignKey("FlowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FlowerShopDatabaseImplement.Models.Shop", "Shop")
.WithMany("Flowers")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Flower");
b.Navigation("Shop");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("FlowerComponents");
@ -296,6 +320,11 @@ namespace FlowerShopDatabaseImplement.Migrations
{
b.Navigation("Order");
});
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Flowers");
});
#pragma warning restore 612, 618
}
}

View File

@ -10,15 +10,13 @@ namespace FlowerShopDatabaseImplement.Models
{
public int Id { get; private set; }
[Required]
public virtual Flower Flower { get; set; }
public int FlowerId { get; private set; }
public virtual Flower Flower { get; set; }
public virtual Flower Flower { get; set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; set; }
public int? ImplementerId { get; private set; }
public virtual Implementer? Implementer { get; set; }
public virtual Client Client { get; set; }
[Required]
public int Count { get; set; }
[Required]