diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs index ae832cf..298c00e 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -15,27 +15,26 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class WorkModeling : IWorkProcess { private readonly ILogger _logger; - private readonly Random _rnd; - private IOrderLogic? _orderLogic; - public WorkModeling(ILogger logger) { _logger = logger; _rnd = new Random(1000); } - public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) { _orderLogic = orderLogic; var implementers = implementerLogic.ReadList(null); if (implementers == null) { - _logger.LogWarning("DoWork. Implementers is null"); + _logger.LogWarning("DoWork. Исполнитель равен null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + var orders = _orderLogic.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); @@ -47,7 +46,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics Task.Run(() => WorkerWorkAsync(implementer, orders)); } } - /// /// Иммитация работы исполнителя /// @@ -60,14 +58,13 @@ namespace ComputersShopBusinessLogic.BusinessLogics return; } await RunOrderInWork(implementer); - await Task.Run(() => { foreach (var order in orders) { try { - _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + _logger.LogDebug("DoWork. Worker {Id} try get order {Order} ", implementer.Id, order.Id); // пытаемся назначить заказ на исполнителя _orderLogic.TakeOrderInWork(new OrderBindingModel { @@ -76,10 +73,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics }); // делаем работу Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _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)); @@ -95,11 +92,9 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogError(ex, "Error while do work"); throw; } - } }); } - /// /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) /// @@ -122,7 +117,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics { return; } - _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); // доделываем работу Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index c467ce2..22957f7 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -41,8 +41,6 @@ this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); @@ -76,28 +74,28 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // // исполнителиToolStripMenuItem // this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.исполнителиToolStripMenuItem.Text = "Исполнители"; this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ИсполнителиToolStripMenuItem_Click); // @@ -163,29 +161,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(951, 94); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(184, 29); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(951, 142); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(184, 29); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(951, 191); + this.buttonIssuedOrder.Location = new System.Drawing.Point(951, 94); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(184, 29); this.buttonIssuedOrder.TabIndex = 5; @@ -195,7 +173,7 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(951, 239); + this.buttonRef.Location = new System.Drawing.Point(951, 152); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(184, 29); this.buttonRef.TabIndex = 6; @@ -210,8 +188,6 @@ this.ClientSize = new System.Drawing.Size(1147, 316); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -233,8 +209,6 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; private ToolStripMenuItem компонентыToolStripMenuItem; diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index f98b112..32c59e7 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -83,57 +83,6 @@ namespace ComputersShopView 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)