diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs index 8aaec56..6dc8edb 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -15,15 +15,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class ImplementerLogic : IImplementerLogic { private readonly ILogger _logger; - private readonly IImplementerStorage _implementerStorage; - public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) { _logger = logger; _implementerStorage = implementerStorage; } - public List? ReadList(ImplementerSearchModel? model) { _logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model?.ImplementerFIO, model?.Id); @@ -36,7 +33,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } - public ImplementerViewModel? ReadElement(ImplementerSearchModel model) { if (model == null) @@ -53,7 +49,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); return element; } - public bool Create(ImplementerBindingModel model) { CheckModel(model); @@ -64,7 +59,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - public bool Update(ImplementerBindingModel model) { CheckModel(model); @@ -75,7 +69,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - public bool Delete(ImplementerBindingModel model) { CheckModel(model, false); @@ -87,7 +80,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - private void CheckModel(ImplementerBindingModel model, bool withParams = true) { if (model == null) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs index 39b9bd6..1c9f899 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -15,18 +15,15 @@ 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) + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic + orderLogic) { _orderLogic = orderLogic; var implementers = implementerLogic.ReadList(null); @@ -35,7 +32,11 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is 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,27 +48,26 @@ namespace ComputersShopBusinessLogic.BusinessLogics Task.Run(() => WorkerWorkAsync(implementer, orders)); } } - /// /// Иммитация работы исполнителя /// /// /// - private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + private async Task WorkerWorkAsync(ImplementerViewModel implementer, + List orders) { if (_orderLogic == null || implementer == null) { 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,7 +76,7 @@ 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 @@ -98,7 +98,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } }); } - /// /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) /// @@ -112,7 +111,8 @@ namespace ComputersShopBusinessLogic.BusinessLogics } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new + OrderSearchModel { ImplementerId = implementer.Id, Status = OrderStatus.Выполняется @@ -121,7 +121,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/FormCreateOrder.cs b/ComputersShop/ComputersShopView/FormCreateOrder.cs index 378155e..fcfaaa1 100644 --- a/ComputersShop/ComputersShopView/FormCreateOrder.cs +++ b/ComputersShop/ComputersShopView/FormCreateOrder.cs @@ -51,7 +51,7 @@ namespace ComputersShopView _logger.LogInformation("Loading clients for order"); try { - var clientList = _logicC.ReadList(null); + var clientList = _logicCl.ReadList(null); if (clientList != null) { comboBoxClient.DisplayMember = "ClientFIO"; diff --git a/ComputersShop/ComputersShopView/FormImplementers.Designer.cs b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs index dcb4c14..9f8fd1a 100644 --- a/ComputersShop/ComputersShopView/FormImplementers.Designer.cs +++ b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs @@ -98,6 +98,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormImplementers"; this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false);