From c3d8dfd646fa5fe66288149ab2c93c833143e7eb Mon Sep 17 00:00:00 2001 From: 111 <0@yandex.ru> Date: Mon, 13 Feb 2023 09:02:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssembly/FormMain.cs | 22 +++---------- .../OrderLogic.cs | 33 ++++++++++++++++++- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 75a4e3c..62e043a 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -84,7 +84,7 @@ namespace FurnitureAssembly _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(GetOrderBindingModel()); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -109,7 +109,7 @@ namespace FurnitureAssembly id); try { - var operationResult = _orderLogic.FinishOrder(GetOrderBindingModel()); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -134,7 +134,7 @@ namespace FurnitureAssembly id); try { - var operationResult = _orderLogic.DeliveryOrder(GetOrderBindingModel()); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -153,20 +153,6 @@ namespace FurnitureAssembly private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); - } - - private OrderBindingModel GetOrderBindingModel() - { - return new OrderBindingModel - { - Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value), - FurnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value), - FurnitureName = dataGridView.SelectedRows[0].Cells["FurnitureName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) - }; - } + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs index a4bb14f..bbe6d31 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs @@ -37,7 +37,7 @@ namespace FurnitureAssemblyBusinessLogic public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - + if (!ChangeStatus(model, OrderStatus.Принят)) { _logger.LogWarning("Order's status is wrong"); @@ -55,6 +55,11 @@ namespace FurnitureAssemblyBusinessLogic public bool TakeOrderInWork(OrderBindingModel model) { + model = Find(model); + if (model == null) + { + return false; + } if (!ChangeStatus(model, OrderStatus.Выполняется)) { _logger.LogWarning("Order's status is wrong"); @@ -66,6 +71,10 @@ namespace FurnitureAssemblyBusinessLogic public bool FinishOrder(OrderBindingModel model) { + model = Find(model); + if (model == null) { + return false; + } if (!ChangeStatus(model, OrderStatus.Готов)) { _logger.LogWarning("Order's status is wrong"); @@ -77,6 +86,11 @@ namespace FurnitureAssemblyBusinessLogic public bool DeliveryOrder(OrderBindingModel model) { + model = Find(model); + if (model == null) + { + return false; + } if (!ChangeStatus(model, OrderStatus.Выдан)) { _logger.LogWarning("Order's status is wrong"); @@ -128,5 +142,22 @@ namespace FurnitureAssemblyBusinessLogic "FurnitureId:{FurnitureId}. FurnitureName:{FurnitureName}. Count:{ Count}. Sum:{ Sum}. ", model.Id, model.Status, model.DateCreate, model.FurnitureId, model.FurnitureName, model.Count, model.Sum); } + + private OrderBindingModel Find(OrderBindingModel model) + { + var modelView = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (modelView == null) + { + return null; + } + model.FurnitureId = modelView.FurnitureId; + model.DateCreate = modelView.DateCreate; + model.Count = modelView.Count; + model.Sum = modelView.Sum; + model.FurnitureId = model.FurnitureId; + model.FurnitureName = modelView.FurnitureName; + model.Status = modelView.Status; + return model; + } } }