From c0e55f82278c33bff6e7c71eaad886343a77e1db Mon Sep 17 00:00:00 2001 From: Zyzf Date: Tue, 7 Feb 2023 13:49:54 +0400 Subject: [PATCH] done --- .../BindingModels/OrderBindingModel.cs | 1 + .../Implements/OrderStorage.cs | 39 ++++++++-------- .../BlacksmithListImplement/Models/Order.cs | 11 ++--- .../{ => BusinessLogics}/ComponentLogic.cs | 0 .../{ => BusinessLogics}/ManufactureLogic.cs | 2 +- .../{ => BusinessLogics}/OrderLogic.cs | 23 ++++------ .../BlacksmithWorkshopView/FormCreateOrder.cs | 1 + .../BlacksmithWorkshopView/FormMain.cs | 44 ++++++++++++++++--- .../BlacksmithWorkshopView/Program.cs | 2 - 9 files changed, 71 insertions(+), 52 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/{ => BusinessLogics}/ComponentLogic.cs (100%) rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/{ => BusinessLogics}/ManufactureLogic.cs (98%) rename BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/{ => BusinessLogics}/OrderLogic.cs (95%) diff --git a/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs index afe345e..68d72fe 100644 --- a/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } public int ManufactureId { get; set; } + public string ManufactureName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs index a734c01..004c4af 100644 --- a/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs @@ -8,10 +8,9 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopListImplement; using BlacksmithWorkshopListImplement.Models; -namespace OrdersShopListImplement.Implements +namespace BlacksmithWorkshopListImplement.Implements { public class OrderStorage : IOrderStorage { @@ -25,7 +24,7 @@ namespace OrdersShopListImplement.Implements var result = new List(); foreach (var Order in _source.Orders) { - result.Add(AttachManufactureName(Order.GetViewModel)); + result.Add(Order.GetViewModel); } return result; } @@ -40,7 +39,7 @@ namespace OrdersShopListImplement.Implements { if (Order.Id == model.Id) { - result.Add(AttachManufactureName(Order.GetViewModel)); + result.Add(Order.GetViewModel); } } return result; @@ -55,7 +54,7 @@ namespace OrdersShopListImplement.Implements { if (model.Id.HasValue && Order.Id == model.Id) { - return AttachManufactureName(Order.GetViewModel); + return Order.GetViewModel; } } return null; @@ -76,7 +75,7 @@ namespace OrdersShopListImplement.Implements return null; } _source.Orders.Add(newOrder); - return AttachManufactureName(newOrder.GetViewModel); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { @@ -85,7 +84,7 @@ namespace OrdersShopListImplement.Implements if (Order.Id == model.Id) { Order.Update(model); - return AttachManufactureName(Order.GetViewModel); + return Order.GetViewModel; } } return null; @@ -98,22 +97,22 @@ namespace OrdersShopListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return AttachManufactureName(element.GetViewModel); + return element.GetViewModel; } } return null; } - private OrderViewModel AttachManufactureName(OrderViewModel model) - { - foreach (var manufacture in _source.Manufactures) - { - if (manufacture.Id == model.ManufactureId) - { - model.ManufactureName = manufacture.ManufactureName; - return model; - } - } - return model; - } + //private OrderViewModel AttachManufactureName(OrderViewModel model) + //{ + // foreach (var manufacture in _source.Manufactures) + // { + // if (manufacture.Id == model.ManufactureId) + // { + // model.ManufactureName = manufacture.ManufactureName; + // return model; + // } + // } + // return model; + //} } } diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs index 99c55e0..a4671a0 100644 --- a/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs @@ -16,19 +16,13 @@ namespace BlacksmithWorkshopListImplement.Models public class Order : IOrderModel { public int Id { get; private set; } - public int ManufactureId { get; private set; } - + public string ManufactureName { get; private set; } = string.Empty; public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -39,6 +33,7 @@ namespace BlacksmithWorkshopListImplement.Models { Id = model.Id, ManufactureId = model.ManufactureId, + ManufactureName = model.ManufactureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -54,6 +49,7 @@ namespace BlacksmithWorkshopListImplement.Models return; } ManufactureId = model.ManufactureId; + ManufactureName = model.ManufactureName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -64,6 +60,7 @@ namespace BlacksmithWorkshopListImplement.Models { Id = Id, ManufactureId = ManufactureId, + ManufactureName = ManufactureName, Count = Count, Sum = Sum, Status = Status, diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs similarity index 100% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ComponentLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs similarity index 98% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs index 3818063..40eeddc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs @@ -11,7 +11,7 @@ using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace BlacksmithWorkshopBusinessLogic +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { public class ManufactureLogic : IManufactureLogic { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs similarity index 95% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 774e55c..634c0cf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,19 +12,17 @@ using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; -namespace BlacksmithWorkshopBusinessLogic +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } - public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); @@ -37,7 +35,6 @@ namespace BlacksmithWorkshopBusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -49,28 +46,24 @@ namespace BlacksmithWorkshopBusinessLogic } return true; } - public bool TakeOrderInWork(OrderBindingModel model) { CheckModel(model); if (!CheckStatus(model, OrderStatus.Выполняется)) return false; return true; } - public bool DeliveryOrder(OrderBindingModel model) - { - CheckModel(model); - if (!CheckStatus(model, OrderStatus.Готов)) return false; - return true; - } - - public bool FinishOrder(OrderBindingModel model) { CheckModel(model); if (!CheckStatus(model, OrderStatus.Выдан)) return false; return true; } - + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + if (!CheckStatus(model, OrderStatus.Готов)) return false; + return true; + } private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -93,7 +86,7 @@ namespace BlacksmithWorkshopBusinessLogic { throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. ManufactureId: { ManufactureId}", model.Id, model.Sum, model.ManufactureId); + _logger.LogInformation("Order. OrderId: {Id}.Sum: {Sum}. ManufactureId: {ManufactureId}", model.Id, model.Sum, model.ManufactureId); } private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs index 539b11a..bdc0acf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs @@ -87,6 +87,7 @@ namespace BlacksmithWorkshopView var operationResult = _logicO.CreateOrder(new OrderBindingModel { ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue), + ManufactureName = comboBoxManufacture.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs index 868f154..17f8866 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging; using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopDataModels.Enums; namespace BlacksmithWorkshopView { @@ -78,10 +79,19 @@ namespace BlacksmithWorkshopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()), + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -100,10 +110,20 @@ namespace BlacksmithWorkshopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'Готов'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()), + DateImplement = DateTime.Now, + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -122,15 +142,25 @@ namespace BlacksmithWorkshopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'Выдан'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].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()), + DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()), + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Заказ No{id} выдан", id); + _logger.LogInformation("Заказ No {id} выдан", id); LoadData(); } catch (Exception ex) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs index 93df0ab..27c63a3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs @@ -1,12 +1,10 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; -using BlacksmithWorkshopBusinessLogic; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopListImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using OrdersShopListImplement.Implements; namespace BlacksmithWorkshopView {