From 7502d15b693a5f6ceb961f0dc434762dac7e4fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D1=83=D0=BD=D0=BE=D0=B2?= Date: Fri, 31 Mar 2023 19:55:55 +0400 Subject: [PATCH] First Labs --- GiftShop/GiftShop.sln | 26 +- .../BusinessLogics/ComponentLogic.cs | 109 ++++++++ .../BusinessLogics/GiftLogic.cs | 137 ++++++++++ .../BusinessLogics/OrderLogic.cs | 137 ++++++++++ .../GiftShopBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 13 + .../BindingModels/GiftBindingModel.cs | 15 ++ .../BindingModels/OrderBindingModel.cs | 24 ++ .../IComponentLogic.cs | 17 ++ .../BusinessLogicsContracts/IGiftLogic.cs | 17 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 19 ++ .../GiftShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 9 + .../SearchModels/GiftSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IGiftStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 17 ++ .../ViewModels/GiftViewModel.cs | 19 ++ .../ViewModels/OrderViewModel.cs | 38 +++ .../GiftShopDataModels/Enums/OrderStatus.cs | 15 ++ .../GiftShopDataModels.csproj | 9 + GiftShop/GiftShopDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 9 + .../GiftShopDataModels/Models/IGiftModel.cs | 11 + .../GiftShopDataModels/Models/IOrderModel.cs | 19 ++ .../DataListSingleton.cs | 27 ++ .../GiftShopListImplement.csproj | 14 ++ .../Implements/ComponentStorage.cs | 102 ++++++++ .../Implements/GiftStorage.cs | 121 +++++++++ .../Implements/OrderStorage.cs | 119 +++++++++ .../GiftShopListImplement/Models/Component.cs | 41 +++ GiftShop/GiftShopListImplement/Models/Gift.cs | 51 ++++ .../GiftShopListImplement/Models/Order.cs | 67 +++++ GiftShop/GiftShopView/Form1.Designer.cs | 39 --- GiftShop/GiftShopView/Form1.cs | 10 - GiftShop/GiftShopView/Form1.resx | 120 --------- .../GiftShopView/FormComponent.Designer.cs | 117 +++++++++ GiftShop/GiftShopView/FormComponent.cs | 93 +++++++ GiftShop/GiftShopView/FormComponent.resx | 60 +++++ .../GiftShopView/FormComponents.Designer.cs | 115 +++++++++ GiftShop/GiftShopView/FormComponents.cs | 114 +++++++++ GiftShop/GiftShopView/FormComponents.resx | 60 +++++ .../GiftShopView/FormCreateOrder.Designer.cs | 145 +++++++++++ GiftShop/GiftShopView/FormCreateOrder.cs | 127 ++++++++++ GiftShop/GiftShopView/FormCreateOrder.resx | 60 +++++ GiftShop/GiftShopView/FormGift.Designer.cs | 238 ++++++++++++++++++ GiftShop/GiftShopView/FormGift.cs | 221 ++++++++++++++++ GiftShop/GiftShopView/FormGift.resx | 69 +++++ .../FormGiftComponent.Designer.cs | 119 +++++++++ GiftShop/GiftShopView/FormGiftComponent.cs | 77 ++++++ GiftShop/GiftShopView/FormGiftComponent.resx | 60 +++++ GiftShop/GiftShopView/FormGifts.Designer.cs | 115 +++++++++ GiftShop/GiftShopView/FormGifts.cs | 108 ++++++++ GiftShop/GiftShopView/FormGifts.resx | 60 +++++ GiftShop/GiftShopView/FormMain.Designer.cs | 176 +++++++++++++ GiftShop/GiftShopView/FormMain.cs | 180 +++++++++++++ GiftShop/GiftShopView/FormMain.resx | 66 +++++ GiftShop/GiftShopView/GiftShopView.csproj | 23 ++ GiftShop/GiftShopView/Program.cs | 42 +++- GiftShop/GiftShopView/nlog.config | 15 ++ 62 files changed, 3771 insertions(+), 176 deletions(-) create mode 100644 GiftShop/GiftShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 GiftShop/GiftShopBusinessLogic/BusinessLogics/GiftLogic.cs create mode 100644 GiftShop/GiftShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 GiftShop/GiftShopBusinessLogic/GiftShopBusinessLogic.csproj create mode 100644 GiftShop/GiftShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 GiftShop/GiftShopContracts/BindingModels/GiftBindingModel.cs create mode 100644 GiftShop/GiftShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 GiftShop/GiftShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 GiftShop/GiftShopContracts/BusinessLogicsContracts/IGiftLogic.cs create mode 100644 GiftShop/GiftShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 GiftShop/GiftShopContracts/GiftShopContracts.csproj create mode 100644 GiftShop/GiftShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 GiftShop/GiftShopContracts/SearchModels/GiftSearchModel.cs create mode 100644 GiftShop/GiftShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 GiftShop/GiftShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 GiftShop/GiftShopContracts/StoragesContracts/IGiftStorage.cs create mode 100644 GiftShop/GiftShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 GiftShop/GiftShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 GiftShop/GiftShopContracts/ViewModels/GiftViewModel.cs create mode 100644 GiftShop/GiftShopContracts/ViewModels/OrderViewModel.cs create mode 100644 GiftShop/GiftShopDataModels/Enums/OrderStatus.cs create mode 100644 GiftShop/GiftShopDataModels/GiftShopDataModels.csproj create mode 100644 GiftShop/GiftShopDataModels/IId.cs create mode 100644 GiftShop/GiftShopDataModels/Models/IComponentModel.cs create mode 100644 GiftShop/GiftShopDataModels/Models/IGiftModel.cs create mode 100644 GiftShop/GiftShopDataModels/Models/IOrderModel.cs create mode 100644 GiftShop/GiftShopListImplement/DataListSingleton.cs create mode 100644 GiftShop/GiftShopListImplement/GiftShopListImplement.csproj create mode 100644 GiftShop/GiftShopListImplement/Implements/ComponentStorage.cs create mode 100644 GiftShop/GiftShopListImplement/Implements/GiftStorage.cs create mode 100644 GiftShop/GiftShopListImplement/Implements/OrderStorage.cs create mode 100644 GiftShop/GiftShopListImplement/Models/Component.cs create mode 100644 GiftShop/GiftShopListImplement/Models/Gift.cs create mode 100644 GiftShop/GiftShopListImplement/Models/Order.cs delete mode 100644 GiftShop/GiftShopView/Form1.Designer.cs delete mode 100644 GiftShop/GiftShopView/Form1.cs delete mode 100644 GiftShop/GiftShopView/Form1.resx create mode 100644 GiftShop/GiftShopView/FormComponent.Designer.cs create mode 100644 GiftShop/GiftShopView/FormComponent.cs create mode 100644 GiftShop/GiftShopView/FormComponent.resx create mode 100644 GiftShop/GiftShopView/FormComponents.Designer.cs create mode 100644 GiftShop/GiftShopView/FormComponents.cs create mode 100644 GiftShop/GiftShopView/FormComponents.resx create mode 100644 GiftShop/GiftShopView/FormCreateOrder.Designer.cs create mode 100644 GiftShop/GiftShopView/FormCreateOrder.cs create mode 100644 GiftShop/GiftShopView/FormCreateOrder.resx create mode 100644 GiftShop/GiftShopView/FormGift.Designer.cs create mode 100644 GiftShop/GiftShopView/FormGift.cs create mode 100644 GiftShop/GiftShopView/FormGift.resx create mode 100644 GiftShop/GiftShopView/FormGiftComponent.Designer.cs create mode 100644 GiftShop/GiftShopView/FormGiftComponent.cs create mode 100644 GiftShop/GiftShopView/FormGiftComponent.resx create mode 100644 GiftShop/GiftShopView/FormGifts.Designer.cs create mode 100644 GiftShop/GiftShopView/FormGifts.cs create mode 100644 GiftShop/GiftShopView/FormGifts.resx create mode 100644 GiftShop/GiftShopView/FormMain.Designer.cs create mode 100644 GiftShop/GiftShopView/FormMain.cs create mode 100644 GiftShop/GiftShopView/FormMain.resx create mode 100644 GiftShop/GiftShopView/nlog.config diff --git a/GiftShop/GiftShop.sln b/GiftShop/GiftShop.sln index 211cfe2..0e16c7c 100644 --- a/GiftShop/GiftShop.sln +++ b/GiftShop/GiftShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GiftShopView", "GiftShopView\GiftShopView.csproj", "{D9DB6CD0-80AE-4E15-905A-C65E5B5E5C6F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GiftShopView", "GiftShopView\GiftShopView.csproj", "{D9DB6CD0-80AE-4E15-905A-C65E5B5E5C6F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GiftShopDataModels", "GiftShopDataModels\GiftShopDataModels.csproj", "{CC3AC359-F8C1-47C1-959D-804D8DF1F681}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GiftShopContracts", "GiftShopContracts\GiftShopContracts.csproj", "{3800C66D-1BCD-4A8B-A9E1-1C578A49DF00}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GiftShopListImplement", "GiftShopListImplement\GiftShopListImplement.csproj", "{5B83AC94-55AC-45CA-8C44-0D0F34E17666}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GiftShopBusinessLogic", "GiftShopBusinessLogic\GiftShopBusinessLogic.csproj", "{07C14020-5905-4CCC-9DAC-53507C8F28F8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {D9DB6CD0-80AE-4E15-905A-C65E5B5E5C6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D9DB6CD0-80AE-4E15-905A-C65E5B5E5C6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D9DB6CD0-80AE-4E15-905A-C65E5B5E5C6F}.Release|Any CPU.Build.0 = Release|Any CPU + {CC3AC359-F8C1-47C1-959D-804D8DF1F681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC3AC359-F8C1-47C1-959D-804D8DF1F681}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC3AC359-F8C1-47C1-959D-804D8DF1F681}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC3AC359-F8C1-47C1-959D-804D8DF1F681}.Release|Any CPU.Build.0 = Release|Any CPU + {3800C66D-1BCD-4A8B-A9E1-1C578A49DF00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3800C66D-1BCD-4A8B-A9E1-1C578A49DF00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3800C66D-1BCD-4A8B-A9E1-1C578A49DF00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3800C66D-1BCD-4A8B-A9E1-1C578A49DF00}.Release|Any CPU.Build.0 = Release|Any CPU + {5B83AC94-55AC-45CA-8C44-0D0F34E17666}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B83AC94-55AC-45CA-8C44-0D0F34E17666}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B83AC94-55AC-45CA-8C44-0D0F34E17666}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B83AC94-55AC-45CA-8C44-0D0F34E17666}.Release|Any CPU.Build.0 = Release|Any CPU + {07C14020-5905-4CCC-9DAC-53507C8F28F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07C14020-5905-4CCC-9DAC-53507C8F28F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07C14020-5905-4CCC-9DAC-53507C8F28F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07C14020-5905-4CCC-9DAC-53507C8F28F8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GiftShop/GiftShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/GiftShop/GiftShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..7652c7d --- /dev/null +++ b/GiftShop/GiftShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,109 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace GiftShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id} ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/GiftShop/GiftShopBusinessLogic/BusinessLogics/GiftLogic.cs b/GiftShop/GiftShopBusinessLogic/BusinessLogics/GiftLogic.cs new file mode 100644 index 0000000..054af07 --- /dev/null +++ b/GiftShop/GiftShopBusinessLogic/BusinessLogics/GiftLogic.cs @@ -0,0 +1,137 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace GiftShopBusinessLogic.BusinessLogics +{ + public class GiftLogic : IGiftLogic + { + private readonly ILogger _logger; + + private readonly IGiftStorage _giftStorage; + + public GiftLogic(ILogger logger, IGiftStorage giftStorage) + { + _logger = logger; + _giftStorage = giftStorage; + } + + public bool Create(GiftBindingModel model) + { + CheckModel(model); + + if (_giftStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(GiftBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_giftStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public GiftViewModel? ReadElement(GiftSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. GiftName:{GiftName}.Id:{ Id}", model.GiftName, model.Id); + + var element = _giftStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(GiftSearchModel? model) + { + _logger.LogInformation("ReadList. GiftName:{GiftName}.Id:{ Id}", model?.GiftName, model?.Id); + + var list = model == null ? _giftStorage.GetFullList() : _giftStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool Update(GiftBindingModel model) + { + CheckModel(model); + + if (_giftStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(GiftBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.GiftName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.GiftName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Gift. GiftName:{GiftName}.Price:{ Cost}. Id: { Id}", model.GiftName, model.Price, model.Id); + + var element = _giftStorage.GetElement(new GiftSearchModel + { + GiftName = model.GiftName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/GiftShop/GiftShopBusinessLogic/BusinessLogics/OrderLogic.cs b/GiftShop/GiftShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..c218de0 --- /dev/null +++ b/GiftShop/GiftShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,137 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using GiftShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace GiftShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + //CheckModel(model); + + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.GiftId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.GiftId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. EngineId: { EngineId}", model.Id, model.Sum, model.GiftId); + } + } +} diff --git a/GiftShop/GiftShopBusinessLogic/GiftShopBusinessLogic.csproj b/GiftShop/GiftShopBusinessLogic/GiftShopBusinessLogic.csproj new file mode 100644 index 0000000..10ddb30 --- /dev/null +++ b/GiftShop/GiftShopBusinessLogic/GiftShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/GiftShop/GiftShopContracts/BindingModels/ComponentBindingModel.cs b/GiftShop/GiftShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..ffb1bfc --- /dev/null +++ b/GiftShop/GiftShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,13 @@ +using GiftShopDataModels.Models; + +namespace GiftShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + + public string ComponentName { get; set; } = string.Empty; + + public double Cost { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/BindingModels/GiftBindingModel.cs b/GiftShop/GiftShopContracts/BindingModels/GiftBindingModel.cs new file mode 100644 index 0000000..5b49715 --- /dev/null +++ b/GiftShop/GiftShopContracts/BindingModels/GiftBindingModel.cs @@ -0,0 +1,15 @@ +using GiftShopDataModels.Models; + +namespace GiftShopContracts.BindingModels +{ + public class GiftBindingModel : IGiftModel + { + public int Id { get; set; } + + public string GiftName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary GiftComponents { get; set; } = new(); + } +} diff --git a/GiftShop/GiftShopContracts/BindingModels/OrderBindingModel.cs b/GiftShop/GiftShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..75f6b59 --- /dev/null +++ b/GiftShop/GiftShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,24 @@ +using GiftShopDataModels.Enums; +using GiftShopDataModels.Models; + +namespace GiftShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id {get; set;} + + public int GiftId { get; set; } + + public string GiftName { get; set; } = string.Empty; + + public int Count { get; set; } + + public double Sum { get; set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..aa16feb --- /dev/null +++ b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,17 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + + ComponentViewModel? ReadElement(ComponentSearchModel model); + + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/BusinessLogicsContracts/IGiftLogic.cs b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IGiftLogic.cs new file mode 100644 index 0000000..076c1fc --- /dev/null +++ b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IGiftLogic.cs @@ -0,0 +1,17 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.BusinessLogicsContracts +{ + public interface IGiftLogic + { + List? ReadList(GiftSearchModel? model); + + GiftViewModel? ReadElement(GiftSearchModel model); + + bool Create(GiftBindingModel model); + bool Update(GiftBindingModel model); + bool Delete(GiftBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..486d713 --- /dev/null +++ b/GiftShop/GiftShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,19 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + + bool CreateOrder(OrderBindingModel model); + + bool TakeOrderInWork(OrderBindingModel model); + + bool FinishOrder(OrderBindingModel model); + + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/GiftShopContracts.csproj b/GiftShop/GiftShopContracts/GiftShopContracts.csproj new file mode 100644 index 0000000..66d285f --- /dev/null +++ b/GiftShop/GiftShopContracts/GiftShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/GiftShop/GiftShopContracts/SearchModels/ComponentSearchModel.cs b/GiftShop/GiftShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..0c1b31d --- /dev/null +++ b/GiftShop/GiftShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace GiftShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + + public string? ComponentName { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/SearchModels/GiftSearchModel.cs b/GiftShop/GiftShopContracts/SearchModels/GiftSearchModel.cs new file mode 100644 index 0000000..6726de5 --- /dev/null +++ b/GiftShop/GiftShopContracts/SearchModels/GiftSearchModel.cs @@ -0,0 +1,9 @@ +namespace GiftShopContracts.SearchModels +{ + public class GiftSearchModel + { + public int? Id { get; set; } + + public string? GiftName { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/SearchModels/OrderSearchModel.cs b/GiftShop/GiftShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..7f387eb --- /dev/null +++ b/GiftShop/GiftShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace GiftShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/StoragesContracts/IComponentStorage.cs b/GiftShop/GiftShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..6d484ac --- /dev/null +++ b/GiftShop/GiftShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + + List GetFilteredList(ComponentSearchModel model); + + ComponentViewModel? GetElement(ComponentSearchModel model); + + ComponentViewModel? Insert(ComponentBindingModel model); + + ComponentViewModel? Update(ComponentBindingModel model); + + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/StoragesContracts/IGiftStorage.cs b/GiftShop/GiftShopContracts/StoragesContracts/IGiftStorage.cs new file mode 100644 index 0000000..94bd7d4 --- /dev/null +++ b/GiftShop/GiftShopContracts/StoragesContracts/IGiftStorage.cs @@ -0,0 +1,21 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.StoragesContracts +{ + public interface IGiftStorage + { + List GetFullList(); + + List GetFilteredList(GiftSearchModel model); + + GiftViewModel? GetElement(GiftSearchModel model); + + GiftViewModel? Insert(GiftBindingModel model); + + GiftViewModel? Update(GiftBindingModel model); + + GiftViewModel? Delete(GiftBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/StoragesContracts/IOrderStorage.cs b/GiftShop/GiftShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..6706f86 --- /dev/null +++ b/GiftShop/GiftShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.ViewModels; + +namespace GiftShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + + List GetFilteredList(OrderSearchModel model); + + OrderViewModel? GetElement(OrderSearchModel model); + + OrderViewModel? Insert(OrderBindingModel model); + + OrderViewModel? Update(OrderBindingModel model); + + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/GiftShop/GiftShopContracts/ViewModels/ComponentViewModel.cs b/GiftShop/GiftShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..5cd0840 --- /dev/null +++ b/GiftShop/GiftShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,17 @@ +using GiftShopDataModels.Models; +using System.ComponentModel; + +namespace GiftShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + + public double Cost { get; set; } + } +} diff --git a/GiftShop/GiftShopContracts/ViewModels/GiftViewModel.cs b/GiftShop/GiftShopContracts/ViewModels/GiftViewModel.cs new file mode 100644 index 0000000..deaa759 --- /dev/null +++ b/GiftShop/GiftShopContracts/ViewModels/GiftViewModel.cs @@ -0,0 +1,19 @@ +using GiftShopDataModels.Models; +using System.ComponentModel; + +namespace GiftShopContracts.ViewModels +{ + public class GiftViewModel : IGiftModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string GiftName { get; set; } = string.Empty; + + [DisplayName("Цена")] + + public double Price { get; set; } + + public Dictionary GiftComponents { get; set; } = new(); + } +} diff --git a/GiftShop/GiftShopContracts/ViewModels/OrderViewModel.cs b/GiftShop/GiftShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..88cc7a9 --- /dev/null +++ b/GiftShop/GiftShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,38 @@ +using GiftShopDataModels.Enums; +using GiftShopDataModels.Models; +using System.ComponentModel; + +namespace GiftShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + public int Id { get; set; } + + public int GiftId { get; set; } + + [DisplayName("Изделие")] + + public string GiftName { get; set; } = string.Empty; + + [DisplayName("Количество")] + + public int Count { get; set; } + + [DisplayName("Сумма")] + + public double Sum { get; set; } + + [DisplayName("Статус")] + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + + public DateTime DateCreate { get; set; } = DateTime.Now; + + + [DisplayName("Дата выполнения")] + + public DateTime? DateImplement { get; set; } + } +} diff --git a/GiftShop/GiftShopDataModels/Enums/OrderStatus.cs b/GiftShop/GiftShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..065cc4f --- /dev/null +++ b/GiftShop/GiftShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,15 @@ +namespace GiftShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/GiftShop/GiftShopDataModels/GiftShopDataModels.csproj b/GiftShop/GiftShopDataModels/GiftShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/GiftShop/GiftShopDataModels/GiftShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/GiftShop/GiftShopDataModels/IId.cs b/GiftShop/GiftShopDataModels/IId.cs new file mode 100644 index 0000000..aa7af3a --- /dev/null +++ b/GiftShop/GiftShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace GiftShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/GiftShop/GiftShopDataModels/Models/IComponentModel.cs b/GiftShop/GiftShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..05166fe --- /dev/null +++ b/GiftShop/GiftShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,9 @@ +namespace GiftShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + } +} diff --git a/GiftShop/GiftShopDataModels/Models/IGiftModel.cs b/GiftShop/GiftShopDataModels/Models/IGiftModel.cs new file mode 100644 index 0000000..1a70b0b --- /dev/null +++ b/GiftShop/GiftShopDataModels/Models/IGiftModel.cs @@ -0,0 +1,11 @@ +namespace GiftShopDataModels.Models +{ + public interface IGiftModel : IId + { + string GiftName { get; } + + double Price { get; } + + Dictionary GiftComponents { get; } + } +} diff --git a/GiftShop/GiftShopDataModels/Models/IOrderModel.cs b/GiftShop/GiftShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..f62ee41 --- /dev/null +++ b/GiftShop/GiftShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using GiftShopDataModels.Enums; + +namespace GiftShopDataModels.Models +{ + public interface IOrderModel : IId + { + int GiftId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} diff --git a/GiftShop/GiftShopListImplement/DataListSingleton.cs b/GiftShop/GiftShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..735e678 --- /dev/null +++ b/GiftShop/GiftShopListImplement/DataListSingleton.cs @@ -0,0 +1,27 @@ +using GiftShopListImplement.Models; + +namespace GiftShopListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Gifts { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Gifts = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/GiftShop/GiftShopListImplement/GiftShopListImplement.csproj b/GiftShop/GiftShopListImplement/GiftShopListImplement.csproj new file mode 100644 index 0000000..ec87bae --- /dev/null +++ b/GiftShop/GiftShopListImplement/GiftShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/GiftShop/GiftShopListImplement/Implements/ComponentStorage.cs b/GiftShop/GiftShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..55d2d2a --- /dev/null +++ b/GiftShop/GiftShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using GiftShopListImplement.Models; + +namespace GiftShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/GiftShop/GiftShopListImplement/Implements/GiftStorage.cs b/GiftShop/GiftShopListImplement/Implements/GiftStorage.cs new file mode 100644 index 0000000..425d4ed --- /dev/null +++ b/GiftShop/GiftShopListImplement/Implements/GiftStorage.cs @@ -0,0 +1,121 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using GiftShopListImplement.Models; + +namespace GiftShopListImplement.Implements +{ + public class GiftStorage : IGiftStorage + { + private readonly DataListSingleton _source; + + public GiftStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public GiftViewModel? Delete(GiftBindingModel model) + { + for (int i = 0; i < _source.Gifts.Count; ++i) + { + if (_source.Gifts[i].Id == model.Id) + { + var element = _source.Gifts[i]; + _source.Gifts.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + + public GiftViewModel? GetElement(GiftSearchModel model) + { + if (string.IsNullOrEmpty(model.GiftName) && !model.Id.HasValue) + { + return null; + } + + foreach (var package in _source.Gifts) + { + if ((!string.IsNullOrEmpty(model.GiftName) && package.GiftName == model.GiftName) || (model.Id.HasValue && package.Id == model.Id)) + { + return package.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(GiftSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.GiftName)) + { + return result; + } + + foreach (var package in _source.Gifts) + { + if (package.GiftName.Contains(model.GiftName)) + { + result.Add(package.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var package in _source.Gifts) + { + result.Add(package.GetViewModel); + } + + return result; + } + + public GiftViewModel? Insert(GiftBindingModel model) + { + model.Id = 1; + + foreach (var package in _source.Gifts) + { + if (model.Id <= package.Id) + { + model.Id = package.Id + 1; + } + } + + var newGift = Gift.Create(model); + + if (newGift == null) + { + return null; + } + + _source.Gifts.Add(newGift); + + return newGift.GetViewModel; + } + + public GiftViewModel? Update(GiftBindingModel model) + { + foreach (var package in _source.Gifts) + { + if (package.Id == model.Id) + { + package.Update(model); + return package.GetViewModel; + } + } + + return null; + } + } +} diff --git a/GiftShop/GiftShopListImplement/Implements/OrderStorage.cs b/GiftShop/GiftShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d415fa8 --- /dev/null +++ b/GiftShop/GiftShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,119 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.SearchModels; +using GiftShopContracts.StoragesContracts; +using GiftShopContracts.ViewModels; +using GiftShopListImplement.Models; + +namespace GiftShopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } + } +} diff --git a/GiftShop/GiftShopListImplement/Models/Component.cs b/GiftShop/GiftShopListImplement/Models/Component.cs new file mode 100644 index 0000000..db52d2d --- /dev/null +++ b/GiftShop/GiftShopListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.ViewModels; +using GiftShopDataModels.Models; + +namespace GiftShopListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/GiftShop/GiftShopListImplement/Models/Gift.cs b/GiftShop/GiftShopListImplement/Models/Gift.cs new file mode 100644 index 0000000..f1b3b9a --- /dev/null +++ b/GiftShop/GiftShopListImplement/Models/Gift.cs @@ -0,0 +1,51 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.ViewModels; +using GiftShopDataModels.Models; + +namespace GiftShopListImplement.Models +{ + internal class Gift : IGiftModel + { + public int Id { get; private set; } + + public string GiftName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary GiftComponents { get; private set; } = new Dictionary(); + + public static Gift? Create(GiftBindingModel? model) + { + if (model == null) + { + return null; + } + return new Gift() + { + Id = model.Id, + GiftName = model.GiftName, + Price = model.Price, + GiftComponents = model.GiftComponents + }; + } + + public void Update(GiftBindingModel? model) + { + if (model == null) + { + return; + } + GiftName = model.GiftName; + Price = model.Price; + GiftComponents = model.GiftComponents; + } + + public GiftViewModel GetViewModel => new() + { + Id = Id, + GiftName = GiftName, + Price = Price, + GiftComponents = GiftComponents + }; + } +} diff --git a/GiftShop/GiftShopListImplement/Models/Order.cs b/GiftShop/GiftShopListImplement/Models/Order.cs new file mode 100644 index 0000000..90a9a36 --- /dev/null +++ b/GiftShop/GiftShopListImplement/Models/Order.cs @@ -0,0 +1,67 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.ViewModels; +using GiftShopDataModels.Enums; +using GiftShopDataModels.Models; + +namespace GiftShopListImplement.Models +{ + internal class Order : IOrderModel + { + public int GiftId { get; private set; } + + public string GiftName { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + GiftId = model.GiftId, + GiftName = model.GiftName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + GiftId = GiftId, + GiftName = GiftName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/GiftShop/GiftShopView/Form1.Designer.cs b/GiftShop/GiftShopView/Form1.Designer.cs deleted file mode 100644 index c09707c..0000000 --- a/GiftShop/GiftShopView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace GiftShopView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/GiftShop/GiftShopView/Form1.cs b/GiftShop/GiftShopView/Form1.cs deleted file mode 100644 index c9a60f8..0000000 --- a/GiftShop/GiftShopView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace GiftShopView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/GiftShop/GiftShopView/Form1.resx b/GiftShop/GiftShopView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/GiftShop/GiftShopView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormComponent.Designer.cs b/GiftShop/GiftShopView/FormComponent.Designer.cs new file mode 100644 index 0000000..2fb881e --- /dev/null +++ b/GiftShop/GiftShopView/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace GiftShopView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(140, 130); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(119, 45); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(287, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(119, 45); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(61, 25); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(61, 83); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(86, 20); + labelCost.TabIndex = 3; + labelCost.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(186, 22); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(220, 27); + textBoxName.TabIndex = 4; + // + // textBoxCost + // + textBoxCost.Location = new Point(186, 80); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(220, 27); + textBoxCost.TabIndex = 5; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(483, 205); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormComponent.cs b/GiftShop/GiftShopView/FormComponent.cs new file mode 100644 index 0000000..38177c4 --- /dev/null +++ b/GiftShop/GiftShopView/FormComponent.cs @@ -0,0 +1,93 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GiftShop/GiftShopView/FormComponent.resx b/GiftShop/GiftShopView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GiftShop/GiftShopView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormComponents.Designer.cs b/GiftShop/GiftShopView/FormComponents.Designer.cs new file mode 100644 index 0000000..0bb7856 --- /dev/null +++ b/GiftShop/GiftShopView/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace GiftShopView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(407, 456); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(457, 63); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(165, 51); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(457, 153); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(165, 51); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(457, 245); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(165, 51); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(457, 336); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(165, 51); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(660, 489); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormComponents.cs b/GiftShop/GiftShopView/FormComponents.cs new file mode 100644 index 0000000..9e1d88e --- /dev/null +++ b/GiftShop/GiftShopView/FormComponents.cs @@ -0,0 +1,114 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении.Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GiftShop/GiftShopView/FormComponents.resx b/GiftShop/GiftShopView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GiftShop/GiftShopView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormCreateOrder.Designer.cs b/GiftShop/GiftShopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..cc20d94 --- /dev/null +++ b/GiftShop/GiftShopView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace GiftShopView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelGift = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxGift = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelGift + // + labelGift.AutoSize = true; + labelGift.Location = new Point(34, 44); + labelGift.Name = "labelGift"; + labelGift.Size = new Size(71, 20); + labelGift.TabIndex = 0; + labelGift.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(34, 112); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(34, 171); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(58, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // comboBoxGift + // + comboBoxGift.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxGift.FormattingEnabled = true; + comboBoxGift.Location = new Point(141, 41); + comboBoxGift.Name = "comboBoxGift"; + comboBoxGift.Size = new Size(369, 28); + comboBoxGift.TabIndex = 3; + comboBoxGift.SelectedIndexChanged += ComboBoxGift_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(141, 109); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(369, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(141, 171); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(369, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(197, 245); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(144, 45); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(384, 245); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(126, 45); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(539, 308); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxGift); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelGift); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelGift; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxGift; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormCreateOrder.cs b/GiftShop/GiftShopView/FormCreateOrder.cs new file mode 100644 index 0000000..6a7e005 --- /dev/null +++ b/GiftShop/GiftShopView/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IGiftLogic _logicP; + + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IGiftLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxGift.DisplayMember = "GiftName"; + comboBoxGift.ValueMember = "ID"; + comboBoxGift.DataSource = list; + comboBoxGift.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxGift.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxGift.SelectedValue); + var product = _logicP.ReadElement(new GiftSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxGift_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxGift.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + GiftId = Convert.ToInt32(comboBoxGift.SelectedValue), + GiftName = comboBoxGift.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GiftShop/GiftShopView/FormCreateOrder.resx b/GiftShop/GiftShopView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GiftShop/GiftShopView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGift.Designer.cs b/GiftShop/GiftShopView/FormGift.Designer.cs new file mode 100644 index 0000000..c756aa5 --- /dev/null +++ b/GiftShop/GiftShopView/FormGift.Designer.cs @@ -0,0 +1,238 @@ +namespace GiftShopView +{ + partial class FormGift + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(86, 18); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(86, 74); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(86, 20); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(185, 18); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(253, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(185, 74); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(253, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Controls.Add(buttonRef); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Location = new Point(12, 121); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(636, 299); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компонент"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(12, 25); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(414, 268); + dataGridView.TabIndex = 5; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // buttonRef + // + buttonRef.Location = new Point(462, 218); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(155, 39); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(462, 159); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(155, 39); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(462, 102); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(155, 39); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(462, 42); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(155, 39); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonSave + // + buttonSave.Location = new Point(311, 438); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(127, 39); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(474, 438); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(115, 39); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormGift + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(660, 502); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormGift"; + Text = "Изделие"; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private DataGridView dataGridView; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGift.cs b/GiftShop/GiftShopView/FormGift.cs new file mode 100644 index 0000000..3a65c6f --- /dev/null +++ b/GiftShop/GiftShopView/FormGift.cs @@ -0,0 +1,221 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.SearchModels; +using GiftShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormGift : Form + { + private readonly ILogger _logger; + + private readonly IGiftLogic _logic; + + private int? _id; + + private Dictionary _giftComponents; + + public int Id { set { _id = value; } } + + public FormGift(ILogger logger, IGiftLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _giftComponents = new Dictionary(); + } + + private void FormGift_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new GiftSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.GiftName; + textBoxPrice.Text = view.Price.ToString(); + _giftComponents = view.GiftComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_giftComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _giftComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGiftComponent)); + if (service is FormGiftComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_giftComponents.ContainsKey(form.Id)) + { + _giftComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _giftComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormGiftComponent)); + if (service is FormGiftComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _giftComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _giftComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _giftComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_giftComponents == null || _giftComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new GiftBindingModel + { + Id = _id ?? 0, + GiftName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + GiftComponents = _giftComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _giftComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/GiftShop/GiftShopView/FormGift.resx b/GiftShop/GiftShopView/FormGift.resx new file mode 100644 index 0000000..72380a4 --- /dev/null +++ b/GiftShop/GiftShopView/FormGift.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGiftComponent.Designer.cs b/GiftShop/GiftShopView/FormGiftComponent.Designer.cs new file mode 100644 index 0000000..0d396c7 --- /dev/null +++ b/GiftShop/GiftShopView/FormGiftComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace GiftShopView +{ + partial class FormGiftComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(23, 35); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(91, 20); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(21, 85); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(128, 35); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(265, 28); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(128, 82); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(265, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(128, 130); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(114, 40); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(277, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 40); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormGiftComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(440, 207); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormGiftComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGiftComponent.cs b/GiftShop/GiftShopView/FormGiftComponent.cs new file mode 100644 index 0000000..4cb59af --- /dev/null +++ b/GiftShop/GiftShopView/FormGiftComponent.cs @@ -0,0 +1,77 @@ +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.ViewModels; +using GiftShopDataModels.Models; + +namespace GiftShopView +{ + public partial class FormGiftComponent : Form + { + private readonly List? _list; + + public int Id + { + get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } + set { comboBoxComponent.SelectedValue = value; } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormGiftComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GiftShop/GiftShopView/FormGiftComponent.resx b/GiftShop/GiftShopView/FormGiftComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GiftShop/GiftShopView/FormGiftComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGifts.Designer.cs b/GiftShop/GiftShopView/FormGifts.Designer.cs new file mode 100644 index 0000000..adc065f --- /dev/null +++ b/GiftShop/GiftShopView/FormGifts.Designer.cs @@ -0,0 +1,115 @@ +namespace GiftShopView +{ + partial class FormGifts + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(444, 380); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(517, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(131, 42); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(517, 111); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(131, 42); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(517, 187); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(131, 42); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(517, 265); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(131, 42); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormGifts + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(709, 407); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormGifts"; + Text = "Изделия"; + Load += FormGifts_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormGifts.cs b/GiftShop/GiftShopView/FormGifts.cs new file mode 100644 index 0000000..5067af1 --- /dev/null +++ b/GiftShop/GiftShopView/FormGifts.cs @@ -0,0 +1,108 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormGifts : Form + { + private readonly ILogger _logger; + + private readonly IGiftLogic _logic; + + public FormGifts(ILogger logger, IGiftLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormGifts_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["GiftName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["GiftComponents"].Visible = false; + } + _logger.LogInformation("Загрузка изделий"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGift)); + if (service is FormGift form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGift)); + if (service is FormGift form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + try + { + if (!_logic.Delete(new GiftBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GiftShop/GiftShopView/FormGifts.resx b/GiftShop/GiftShopView/FormGifts.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/GiftShop/GiftShopView/FormGifts.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormMain.Designer.cs b/GiftShop/GiftShopView/FormMain.Designer.cs new file mode 100644 index 0000000..4f97c54 --- /dev/null +++ b/GiftShop/GiftShopView/FormMain.Designer.cs @@ -0,0 +1,176 @@ +namespace GiftShopView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + 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.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip1"; + this.menuStrip.Size = new System.Drawing.Size(1367, 28); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 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(182, 26); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 41); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(1123, 423); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(1155, 67); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(189, 41); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1155, 136); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(189, 41); + 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(1155, 211); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(189, 41); + 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(1155, 290); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(189, 41); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1155, 356); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(189, 41); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1367, 471); + 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.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Магазин подарков"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/GiftShop/GiftShopView/FormMain.cs b/GiftShop/GiftShopView/FormMain.cs new file mode 100644 index 0000000..67e8bdf --- /dev/null +++ b/GiftShop/GiftShopView/FormMain.cs @@ -0,0 +1,180 @@ +using GiftShopContracts.BindingModels; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace GiftShopView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["GiftId"].Visible = false; + dataGridView.Columns["GiftName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormGifts)); + + if (service is FormGifts form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + 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, + GiftId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["GiftId"].Value), + GiftName = dataGridView.SelectedRows[0].Cells["GiftName"].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("Ошибка при сохранении. Дополнительная информация в логах."); + } + 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.DeliveryOrder(new OrderBindingModel + { + Id = id, + GiftId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["GiftId"].Value), + GiftName = dataGridView.SelectedRows[0].Cells["GiftName"].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("Ошибка при сохранении. Дополнительная информация в логах."); + } + 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) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + GiftId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["GiftId"].Value), + GiftName = dataGridView.SelectedRows[0].Cells["GiftName"].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("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/GiftShop/GiftShopView/FormMain.resx b/GiftShop/GiftShopView/FormMain.resx new file mode 100644 index 0000000..f272885 --- /dev/null +++ b/GiftShop/GiftShopView/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 37 + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/GiftShopView.csproj b/GiftShop/GiftShopView/GiftShopView.csproj index b57c89e..93649a3 100644 --- a/GiftShop/GiftShopView/GiftShopView.csproj +++ b/GiftShop/GiftShopView/GiftShopView.csproj @@ -8,4 +8,27 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GiftShop/GiftShopView/Program.cs b/GiftShop/GiftShopView/Program.cs index 549ad69..d9e281e 100644 --- a/GiftShop/GiftShopView/Program.cs +++ b/GiftShop/GiftShopView/Program.cs @@ -1,17 +1,47 @@ +using GiftShopBusinessLogic.BusinessLogics; +using GiftShopContracts.BusinessLogicsContracts; +using GiftShopContracts.StoragesContracts; +using GiftShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace GiftShopView { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/GiftShop/GiftShopView/nlog.config b/GiftShop/GiftShopView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/GiftShop/GiftShopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1