diff --git a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs index 5f611de..1358529 100644 --- a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs +++ b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs @@ -66,7 +66,7 @@ namespace AircraftPlantListImplement.Implements return result; } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if(model.ClientId.HasValue && !model.Id.HasValue) { foreach (var order in _source.Orders) { @@ -74,6 +74,27 @@ namespace AircraftPlantListImplement.Implements } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(GetViewModel(order)); + } + } + } + foreach (var order in _source.Orders) { if (order.Id == model.Id) @@ -90,7 +111,7 @@ namespace AircraftPlantListImplement.Implements /// public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -101,6 +122,14 @@ namespace AircraftPlantListImplement.Implements { return GetViewModel(order); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return GetViewModel(order); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return GetViewModel(order); + } } return null; } diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs index d8891a6..ee0439a 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -30,6 +30,8 @@ namespace AircraftPlantBusinessLogic.BusinessLogics /// private readonly IOrderStorage _orderStorage; + static readonly object locker = new(); + /// /// Взаимодействие с хранилищем клиентов /// @@ -132,9 +134,13 @@ namespace AircraftPlantBusinessLogic.BusinessLogics /// /// /// + public bool TakeOrderInWork(OrderBindingModel model) { - return StatusUpdate(model, OrderStatus.Выполняется); + lock (locker) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } } /// @@ -211,6 +217,10 @@ namespace AircraftPlantBusinessLogic.BusinessLogics model.Status = newStatus; + if (element.ImplementerId.HasValue) + { + model.ImplementerId = element.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/WorkModeling.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/WorkModeling.cs index bd3b364..276b3b5 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/WorkModeling.cs @@ -84,6 +84,9 @@ namespace AircraftPlantBusinessLogic.BusinessLogics { Id = order.Id }); + + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex) @@ -97,8 +100,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics throw; } - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs index 1a86b27..951dcdb 100644 --- a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs @@ -38,17 +38,6 @@ namespace AircraftPlantDatabaseImplement.Implements .ToList(); } - if (model.Status.HasValue) - { - return context.Orders - .Include(x => x.Plane) - .Include(x => x.Client) - .Include(x => x.Implementer) - .Where(x => x.Status == model.Status) - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.ClientId.HasValue) { return context.Orders @@ -59,7 +48,16 @@ namespace AircraftPlantDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - + if (model.Status.HasValue) + { + return context.Orders + .Include(x => x.Plane) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status == model.Status) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Orders .Include(x => x.Plane) .Include(x => x.Client) @@ -104,7 +102,6 @@ namespace AircraftPlantDatabaseImplement.Implements .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) ?.GetViewModel; } - return null; } diff --git a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs index f01c83a..b49e040 100644 --- a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs @@ -28,29 +28,47 @@ namespace AircraftPlantFileImplement.Implements { return new(); } - if (model.DateFrom.HasValue) + else if (model.DateFrom.HasValue) { return _source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)) .ToList(); } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if (model.ClientId.HasValue && !model.Id.HasValue) { return _source.Orders .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return _source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return _source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + var order = _source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? order.GetViewModel : null; } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs index 1f4e405..0c1dd7a 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.cs @@ -118,7 +118,6 @@ namespace AircraftPlantView /// private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic )) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); }