From 0755012abd534704b75cda7033de92f99bd80e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Thu, 15 Feb 2024 17:10:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=9B?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/JewelryStore/JewelryStore.csproj | 9 + JewelryStore/JewelryStore/JewelryStore.sln | 55 +++++ .../Properties/launchSettings.json | 28 +++ .../JewelryStore/appsettings.Development.json | 8 + JewelryStore/JewelryStore/appsettings.json | 9 + .../BusinessLogics/ComponentLogic.cs | 109 +++++++++ .../BusinessLogics/JewelLogic.cs | 121 ++++++++++ .../BusinessLogics/OrderLogic.cs | 136 +++++++++++ .../JewelryStoreBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/JewelBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 22 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IJewelLogic.cs | 21 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../JewelryStoreContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 15 ++ .../SearchModels/JewelSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IJewelStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 22 ++ .../ViewModels/ComponentViewModel.cs | 22 ++ .../ViewModels/JewelViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 37 +++ .../DataListSingleton.cs | 33 +++ .../Implements/ComponentStorage.cs | 114 +++++++++ .../Implements/JewelStorage.cs | 113 +++++++++ .../Implements/OrderStorage.cs | 126 ++++++++++ .../JewelryStoreListImplement.csproj | 14 ++ .../Models/Component.cs | 49 ++++ .../JewelryStoreListImplement/Models/Jewel.cs | 53 +++++ .../JewelryStoreListImplement/Models/Order.cs | 65 +++++ .../Enums/OrderStatus.cs | 17 ++ JewelryStore/JewerlyStoreDataModels/IId.cs | 14 ++ .../JewerlyStoreDataModels.csproj | 9 + .../Models/IComponentModel.cs | 16 ++ .../Models/IJewelModel.cs | 17 ++ .../Models/IOrderModel.cs | 20 ++ .../FormComponent.Designer.cs | 117 +++++++++ .../JewerlyStoreView/FormComponent.cs | 81 +++++++ .../JewerlyStoreView/FormComponent.resx | 120 ++++++++++ .../FormComponents.Designer.cs | 113 +++++++++ .../JewerlyStoreView/FormComponents.cs | 109 +++++++++ .../JewerlyStoreView/FormComponents.resx | 120 ++++++++++ .../FormCreateOrder.Designer.cs | 142 +++++++++++ .../JewerlyStoreView/FormCreateOrder.cs | 122 ++++++++++ .../JewerlyStoreView/FormCreateOrder.resx | 120 ++++++++++ .../JewerlyStoreView/FormJewel.Designer.cs | 222 ++++++++++++++++++ JewelryStore/JewerlyStoreView/FormJewel.cs | 215 +++++++++++++++++ JewelryStore/JewerlyStoreView/FormJewel.resx | 138 +++++++++++ .../FormJewelComponent.Designer.cs | 118 ++++++++++ .../JewerlyStoreView/FormJewelComponent.cs | 80 +++++++ .../JewerlyStoreView/FormJewelComponent.resx | 120 ++++++++++ .../JewerlyStoreView/FormJewels.Designer.cs | 113 +++++++++ JewelryStore/JewerlyStoreView/FormJewels.cs | 115 +++++++++ JewelryStore/JewerlyStoreView/FormJewels.resx | 120 ++++++++++ .../JewerlyStoreView/FormMain.Designer.cs | 176 ++++++++++++++ JewelryStore/JewerlyStoreView/FormMain.cs | 181 ++++++++++++++ JewelryStore/JewerlyStoreView/FormMain.resx | 126 ++++++++++ .../JewerlyStoreView/JewerlyStoreView.csproj | 23 ++ JewelryStore/JewerlyStoreView/Program.cs | 53 +++++ 62 files changed, 4318 insertions(+) create mode 100644 JewelryStore/JewelryStore/JewelryStore.csproj create mode 100644 JewelryStore/JewelryStore/JewelryStore.sln create mode 100644 JewelryStore/JewelryStore/Properties/launchSettings.json create mode 100644 JewelryStore/JewelryStore/appsettings.Development.json create mode 100644 JewelryStore/JewelryStore/appsettings.json create mode 100644 JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs create mode 100644 JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj create mode 100644 JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs create mode 100644 JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj create mode 100644 JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs create mode 100644 JewelryStore/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs create mode 100644 JewelryStore/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs create mode 100644 JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs create mode 100644 JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs create mode 100644 JewelryStore/JewelryStoreListImplement/DataListSingleton.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs create mode 100644 JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj create mode 100644 JewelryStore/JewelryStoreListImplement/Models/Component.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Models/Jewel.cs create mode 100644 JewelryStore/JewelryStoreListImplement/Models/Order.cs create mode 100644 JewelryStore/JewerlyStoreDataModels/Enums/OrderStatus.cs create mode 100644 JewelryStore/JewerlyStoreDataModels/IId.cs create mode 100644 JewelryStore/JewerlyStoreDataModels/JewerlyStoreDataModels.csproj create mode 100644 JewelryStore/JewerlyStoreDataModels/Models/IComponentModel.cs create mode 100644 JewelryStore/JewerlyStoreDataModels/Models/IJewelModel.cs create mode 100644 JewelryStore/JewerlyStoreDataModels/Models/IOrderModel.cs create mode 100644 JewelryStore/JewerlyStoreView/FormComponent.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormComponent.cs create mode 100644 JewelryStore/JewerlyStoreView/FormComponent.resx create mode 100644 JewelryStore/JewerlyStoreView/FormComponents.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormComponents.cs create mode 100644 JewelryStore/JewerlyStoreView/FormComponents.resx create mode 100644 JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormCreateOrder.cs create mode 100644 JewelryStore/JewerlyStoreView/FormCreateOrder.resx create mode 100644 JewelryStore/JewerlyStoreView/FormJewel.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewel.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewel.resx create mode 100644 JewelryStore/JewerlyStoreView/FormJewelComponent.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewelComponent.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewelComponent.resx create mode 100644 JewelryStore/JewerlyStoreView/FormJewels.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewels.cs create mode 100644 JewelryStore/JewerlyStoreView/FormJewels.resx create mode 100644 JewelryStore/JewerlyStoreView/FormMain.Designer.cs create mode 100644 JewelryStore/JewerlyStoreView/FormMain.cs create mode 100644 JewelryStore/JewerlyStoreView/FormMain.resx create mode 100644 JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj create mode 100644 JewelryStore/JewerlyStoreView/Program.cs diff --git a/JewelryStore/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore/JewelryStore.csproj new file mode 100644 index 0000000..c78c9c7 --- /dev/null +++ b/JewelryStore/JewelryStore/JewelryStore.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/JewelryStore/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore/JewelryStore.sln new file mode 100644 index 0000000..9d3921e --- /dev/null +++ b/JewelryStore/JewelryStore/JewelryStore.sln @@ -0,0 +1,55 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStore", "JewelryStore.csproj", "{AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{F3E87835-779D-4974-96D4-51A6723C37D3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{76C0344A-4C9E-42D1-84DB-6D39D595B57D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewerlyStoreDataModels", "..\JewerlyStoreDataModels\JewerlyStoreDataModels.csproj", "{4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewerlyStoreView", "..\JewerlyStoreView\JewerlyStoreView.csproj", "{F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}.Release|Any CPU.Build.0 = Release|Any CPU + {7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}.Release|Any CPU.Build.0 = Release|Any CPU + {F3E87835-779D-4974-96D4-51A6723C37D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3E87835-779D-4974-96D4-51A6723C37D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3E87835-779D-4974-96D4-51A6723C37D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3E87835-779D-4974-96D4-51A6723C37D3}.Release|Any CPU.Build.0 = Release|Any CPU + {76C0344A-4C9E-42D1-84DB-6D39D595B57D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76C0344A-4C9E-42D1-84DB-6D39D595B57D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76C0344A-4C9E-42D1-84DB-6D39D595B57D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76C0344A-4C9E-42D1-84DB-6D39D595B57D}.Release|Any CPU.Build.0 = Release|Any CPU + {4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}.Release|Any CPU.Build.0 = Release|Any CPU + {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7DC518F4-F7F1-41B5-9A18-FA8467DD79C6} + EndGlobalSection +EndGlobal diff --git a/JewelryStore/JewelryStore/Properties/launchSettings.json b/JewelryStore/JewelryStore/Properties/launchSettings.json new file mode 100644 index 0000000..ad976f9 --- /dev/null +++ b/JewelryStore/JewelryStore/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:21977", + "sslPort": 44362 + } + }, + "profiles": { + "JewelryStore": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7209;http://localhost:5260", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/JewelryStore/JewelryStore/appsettings.Development.json b/JewelryStore/JewelryStore/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/JewelryStore/JewelryStore/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/JewelryStore/JewelryStore/appsettings.json b/JewelryStore/JewelryStore/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/JewelryStore/JewelryStore/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..d5f8b57 --- /dev/null +++ b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,109 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.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/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs new file mode 100644 index 0000000..6a4a18a --- /dev/null +++ b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -0,0 +1,121 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + public class JewelLogic : IJewelLogic + { + private readonly ILogger _logger; + private readonly IJewelStorage _jewelStorage; + + public JewelLogic(ILogger logger, IJewelStorage jewelStorage) + { + _logger = logger; + _jewelStorage = jewelStorage; + } + + public List? ReadList(JewelSearchModel? model) + { + _logger.LogInformation("ReadList. JewelName:{JewelName}. Id:{Id}", model?.JewelName, model?.Id); + var list = model == null ? _jewelStorage.GetFullList() : _jewelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public JewelViewModel? ReadElement(JewelSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. JewelName:{JewelName}. Id:{Id}", model.JewelName, model.Id); + var element = _jewelStorage.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(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(JewelBindingModel model) + { + CheckModel(model); + if (_jewelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(JewelBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_jewelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(JewelBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.JewelName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.JewelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + if (model.JewelComponents == null || model.JewelComponents.Count == 0) + { + throw new ArgumentNullException("Нет компонентов изделия", nameof(model.JewelComponents)); + } + _logger.LogInformation("Jewel. JewelName:{JewelName}. Cost:{Cost}. Id:{Id}", model.JewelName, model.Price, model.Id); + var element = _jewelStorage.GetElement(new JewelSearchModel { JewelName = model.JewelName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..20e480f --- /dev/null +++ b/JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,136 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.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.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{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; + } + public dynamic ElementForOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + return element; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + var element = ElementForOrder(model); + if (element.Status != OrderStatus.Готов) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); + } + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + var element = ElementForOrder(model); + if (element.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); + } + model.Status = OrderStatus.Готов; + _orderStorage.Update(model); + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + var element = ElementForOrder(model); + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + model.Status = OrderStatus.Выполняется; + _orderStorage.Update(model); + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Заказ с таким ID уже существует"); + } + } + } +} diff --git a/JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj new file mode 100644 index 0000000..cb90ecb --- /dev/null +++ b/JewelryStore/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs b/JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..10919a4 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs b/JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs new file mode 100644 index 0000000..6fd822e --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BindingModels/JewelBindingModel.cs @@ -0,0 +1,18 @@ +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class JewelBindingModel : IJewelModel + { + public int Id { get; set; } + public string JewelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary JewelComponents { get; set; } = new(); + } + +} diff --git a/JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..78ce217 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using JewerlyStoreDataModels.Enums; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int JewelId { get; set; } + 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/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..9d6cc03 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs new file mode 100644 index 0000000..d2e7827 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IJewelLogic.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IJewelLogic + { + List? ReadList(JewelSearchModel? model); + JewelViewModel? ReadElement(JewelSearchModel model); + bool Create(JewelBindingModel model); + bool Update(JewelBindingModel model); + bool Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..a403f30 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj b/JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj new file mode 100644 index 0000000..e4c7f5b --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/JewelryStoreContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs b/JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..896de06 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } + +} diff --git a/JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs b/JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs new file mode 100644 index 0000000..277c72c --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/SearchModels/JewelSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class JewelSearchModel + { + public int? Id { get; set; } + public string? JewelName { get; set; } + } + +} diff --git a/JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..be8178a --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } + +} diff --git a/JewelryStore/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs b/JewelryStore/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..e144390 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs b/JewelryStore/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs new file mode 100644 index 0000000..fa5d4da --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/StoragesContracts/IJewelStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IJewelStorage + { + List GetFullList(); + List GetFilteredList(JewelSearchModel model); + JewelViewModel? GetElement(JewelSearchModel model); + JewelViewModel? Insert(JewelBindingModel model); + JewelViewModel? Update(JewelBindingModel model); + JewelViewModel? Delete(JewelBindingModel model); + } + +} diff --git a/JewelryStore/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs b/JewelryStore/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..3fb94e2 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs b/JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..f1b9409 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,22 @@ +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.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/JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs b/JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs new file mode 100644 index 0000000..638e84f --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/ViewModels/JewelViewModel.cs @@ -0,0 +1,23 @@ +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class JewelViewModel : IJewelModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string JewelName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary JewelComponents { get; set; } = new(); + } + +} diff --git a/JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c8e5990 --- /dev/null +++ b/JewelryStore/JewelryStoreContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using JewerlyStoreDataModels.Enums; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int JewelId { get; set; } + + [DisplayName("Изделие")] + public string JewelName { 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/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs new file mode 100644 index 0000000..d9a2839 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/DataListSingleton.cs @@ -0,0 +1,33 @@ +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Jewels { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Jewels = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs b/JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..aa9193a --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,114 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.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; + } + } +} \ No newline at end of file diff --git a/JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs b/JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..4bc99e6 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Implements/JewelStorage.cs @@ -0,0 +1,113 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class JewelStorage : IJewelStorage + { + private readonly DataListSingleton _source; + + public JewelStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var jewel in _source.Jewels) + { + result.Add(jewel.GetViewModel); + } + return result; + } + + public List GetFilteredList(JewelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.JewelName)) + { + return result; + } + foreach (var jewel in _source.Jewels) + { + if (jewel.JewelName.Contains(model.JewelName)) + { + result.Add(jewel.GetViewModel); + } + } + return result; + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + foreach (var jewel in _source.Jewels) + { + if ((!string.IsNullOrEmpty(model.JewelName) && jewel.JewelName == model.JewelName) || + (model.Id.HasValue && jewel.Id == model.Id)) + { + return jewel.GetViewModel; + } + } + return null; + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = 1; + foreach (var jewel in _source.Jewels) + { + if (model.Id <= jewel.Id) + { + model.Id = jewel.Id + 1; + } + } + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + _source.Jewels.Add(newJewel); + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.Id) + { + jewel.Update(model); + return jewel.GetViewModel; + } + } + return null; + } + + public JewelViewModel? Delete(JewelBindingModel model) + { + for (int i = 0; i < _source.Jewels.Count; ++i) + { + if (_source.Jewels[i].Id == model.Id) + { + var element = _source.Jewels[i]; + _source.Jewels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs b/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..5e41d32 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Implements/OrderStorage.cs @@ -0,0 +1,126 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace JewelryStoreListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AccessJewelStorage(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AccessJewelStorage(order.GetViewModel)); + } + } + return result; + } + + 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 AccessJewelStorage(order.GetViewModel); + } + } + return null; + } + + 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 AccessJewelStorage(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AccessJewelStorage(order.GetViewModel); + } + } + return null; + } + + 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 AccessJewelStorage(element.GetViewModel); + } + } + return null; + } + + public OrderViewModel AccessJewelStorage(OrderViewModel model) + { + foreach (var jewel in _source.Jewels) + { + if (jewel.Id == model.JewelId) + { + model.JewelName = jewel.JewelName; + break; + } + } + return model; + } + } +} diff --git a/JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj new file mode 100644 index 0000000..eaba351 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/JewelryStore/JewelryStoreListImplement/Models/Component.cs b/JewelryStore/JewelryStoreListImplement/Models/Component.cs new file mode 100644 index 0000000..99f9404 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Models/Component.cs @@ -0,0 +1,49 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public 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/JewelryStore/JewelryStoreListImplement/Models/Jewel.cs b/JewelryStore/JewelryStoreListImplement/Models/Jewel.cs new file mode 100644 index 0000000..36adefc --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Models/Jewel.cs @@ -0,0 +1,53 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Jewel : IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary JewelComponents { get; private set; } = new Dictionary(); + + public static Jewel? Create(JewelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + JewelComponents = model.JewelComponents + }; + } + + public void Update(JewelBindingModel? model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + JewelComponents = model.JewelComponents; + } + + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + } +} \ No newline at end of file diff --git a/JewelryStore/JewelryStoreListImplement/Models/Order.cs b/JewelryStore/JewelryStoreListImplement/Models/Order.cs new file mode 100644 index 0000000..6da2fd7 --- /dev/null +++ b/JewelryStore/JewelryStoreListImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Enums; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int JewelId { 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 static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + 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; + if (model.DateImplement.HasValue) + { + DateImplement = model.DateImplement; + } + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreDataModels/Enums/OrderStatus.cs b/JewelryStore/JewerlyStoreDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..d96e203 --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/JewelryStore/JewerlyStoreDataModels/IId.cs b/JewelryStore/JewerlyStoreDataModels/IId.cs new file mode 100644 index 0000000..6390f63 --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/IId.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreDataModels +{ + public interface IId + { + int Id { get; } + } + +} diff --git a/JewelryStore/JewerlyStoreDataModels/JewerlyStoreDataModels.csproj b/JewelryStore/JewerlyStoreDataModels/JewerlyStoreDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/JewerlyStoreDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/JewelryStore/JewerlyStoreDataModels/Models/IComponentModel.cs b/JewelryStore/JewerlyStoreDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..6e7481a --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/Models/IComponentModel.cs @@ -0,0 +1,16 @@ +using JewerlyStoreDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } + +} diff --git a/JewelryStore/JewerlyStoreDataModels/Models/IJewelModel.cs b/JewelryStore/JewerlyStoreDataModels/Models/IJewelModel.cs new file mode 100644 index 0000000..4e344df --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/Models/IJewelModel.cs @@ -0,0 +1,17 @@ +using JewerlyStoreDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreDataModels.Models +{ + public interface IJewelModel : IId + { + string JewelName { get; } + double Price { get; } + Dictionary JewelComponents { get; } + } + +} diff --git a/JewelryStore/JewerlyStoreDataModels/Models/IOrderModel.cs b/JewelryStore/JewerlyStoreDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..0d41670 --- /dev/null +++ b/JewelryStore/JewerlyStoreDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using JewerlyStoreDataModels; +using JewerlyStoreDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreDataModels.Models +{ + public interface IOrderModel : IId + { + int JewelId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/JewelryStore/JewerlyStoreView/FormComponent.Designer.cs b/JewelryStore/JewerlyStoreView/FormComponent.Designer.cs new file mode 100644 index 0000000..3c1ddb3 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace JewelryStoreView +{ + 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() + { + textBoxPriceComponent = new TextBox(); + textBoxNameComponent = new TextBox(); + labelNameComponent = new Label(); + labelPriceComponent = new Label(); + buttonSaveComponent = new Button(); + buttonCancelComponent = new Button(); + SuspendLayout(); + // + // textBoxPriceComponent + // + textBoxPriceComponent.Location = new Point(94, 47); + textBoxPriceComponent.Name = "textBoxPriceComponent"; + textBoxPriceComponent.Size = new Size(111, 23); + textBoxPriceComponent.TabIndex = 0; + // + // textBoxNameComponent + // + textBoxNameComponent.Location = new Point(94, 17); + textBoxNameComponent.Name = "textBoxNameComponent"; + textBoxNameComponent.Size = new Size(111, 23); + textBoxNameComponent.TabIndex = 1; + // + // labelNameComponent + // + labelNameComponent.AutoSize = true; + labelNameComponent.Location = new Point(26, 20); + labelNameComponent.Name = "labelNameComponent"; + labelNameComponent.Size = new Size(62, 15); + labelNameComponent.TabIndex = 2; + labelNameComponent.Text = "Название:"; + // + // labelPriceComponent + // + labelPriceComponent.AutoSize = true; + labelPriceComponent.Location = new Point(26, 50); + labelPriceComponent.Name = "labelPriceComponent"; + labelPriceComponent.Size = new Size(38, 15); + labelPriceComponent.TabIndex = 3; + labelPriceComponent.Text = "Цена:"; + // + // buttonSaveComponent + // + buttonSaveComponent.Location = new Point(40, 84); + buttonSaveComponent.Name = "buttonSaveComponent"; + buttonSaveComponent.Size = new Size(90, 23); + buttonSaveComponent.TabIndex = 4; + buttonSaveComponent.Text = "Сохранить"; + buttonSaveComponent.UseVisualStyleBackColor = true; + buttonSaveComponent.Click += ButtonSave_Click; + // + // buttonCancelComponent + // + buttonCancelComponent.Location = new Point(136, 84); + buttonCancelComponent.Name = "buttonCancelComponent"; + buttonCancelComponent.Size = new Size(91, 23); + buttonCancelComponent.TabIndex = 5; + buttonCancelComponent.Text = "Отмена"; + buttonCancelComponent.UseVisualStyleBackColor = true; + buttonCancelComponent.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(244, 119); + Controls.Add(buttonCancelComponent); + Controls.Add(buttonSaveComponent); + Controls.Add(labelPriceComponent); + Controls.Add(labelNameComponent); + Controls.Add(textBoxNameComponent); + Controls.Add(textBoxPriceComponent); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPriceComponent; + private TextBox textBoxNameComponent; + private Label labelNameComponent; + private Label labelPriceComponent; + private Button buttonSaveComponent; + private Button buttonCancelComponent; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormComponent.cs b/JewelryStore/JewerlyStoreView/FormComponent.cs new file mode 100644 index 0000000..3501ad5 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponent.cs @@ -0,0 +1,81 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + 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) + { + textBoxNameComponent.Text = view.ComponentName; + textBoxPriceComponent.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(textBoxNameComponent.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxNameComponent.Text, + Cost = Convert.ToDouble(textBoxPriceComponent.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(); + } + + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormComponent.resx b/JewelryStore/JewerlyStoreView/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs b/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs new file mode 100644 index 0000000..9bb464b --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs @@ -0,0 +1,113 @@ +namespace JewelryStoreView +{ + 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(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(423, 426); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(465, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(117, 41); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(465, 59); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(117, 40); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(465, 105); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(117, 40); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(465, 151); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(117, 36); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(616, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormComponents.cs b/JewelryStore/JewerlyStoreView/FormComponents.cs new file mode 100644 index 0000000..ecf1e3f --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponents.cs @@ -0,0 +1,109 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + 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/JewelryStore/JewerlyStoreView/FormComponents.resx b/JewelryStore/JewerlyStoreView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs b/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..cca7c25 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs @@ -0,0 +1,142 @@ +namespace JewelryStoreView +{ + 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() + { + labelJewel = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxJewel = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelJewel + // + labelJewel.AutoSize = true; + labelJewel.Location = new Point(12, 19); + labelJewel.Name = "labelJewel"; + labelJewel.Size = new Size(53, 15); + labelJewel.TabIndex = 0; + labelJewel.Text = "Изделие"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 45); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(72, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 72); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(45, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма"; + // + // comboBoxJewel + // + comboBoxJewel.FormattingEnabled = true; + comboBoxJewel.Location = new Point(101, 16); + comboBoxJewel.Name = "comboBoxJewel"; + comboBoxJewel.Size = new Size(158, 23); + comboBoxJewel.TabIndex = 3; + // + // textBoxCount + // + textBoxCount.Location = new Point(101, 45); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(158, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(101, 74); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(158, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(77, 103); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(84, 32); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(167, 103); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(92, 32); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(286, 166); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxJewel); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelJewel); + Name = "FormCreateOrder"; + Text = "Создать заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelJewel; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxJewel; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormCreateOrder.cs b/JewelryStore/JewerlyStoreView/FormCreateOrder.cs new file mode 100644 index 0000000..5dbd9a4 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormCreateOrder.cs @@ -0,0 +1,122 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logicJ; + private readonly IOrderLogic _logicO; + private List? _list; + + public FormCreateOrder(ILogger logger, IJewelLogic logicJ, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicJ = logicJ; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + _list = _logicJ.ReadList(null); + if (_list != null) + { + + comboBoxJewel.DisplayMember = "JewelName"; + comboBoxJewel.ValueMember = "Id"; + comboBoxJewel.DataSource = _list; + comboBoxJewel.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxJewel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1; + var Jewel = _logicJ.ReadElement(new JewelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Jewel?.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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxJewel.SelectedValue == null) + { + MessageBox.Show("Выберите драгоценность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + JewelId = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1, + 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 ComboBoxJewel_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/JewelryStore/JewerlyStoreView/FormCreateOrder.resx b/JewelryStore/JewerlyStoreView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/JewelryStore/JewerlyStoreView/FormJewel.Designer.cs b/JewelryStore/JewerlyStoreView/FormJewel.Designer.cs new file mode 100644 index 0000000..82989a8 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewel.Designer.cs @@ -0,0 +1,222 @@ +namespace JewelryStoreView +{ + partial class FormJewel + { + /// + /// 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(); + groupBoxJewels = new GroupBox(); + buttonRefresh = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnID = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxJewels.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 24); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 61); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(35, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена"; + // + // textBoxName + // + textBoxName.Location = new Point(90, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(151, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(90, 58); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(151, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxJewels + // + groupBoxJewels.Controls.Add(buttonRefresh); + groupBoxJewels.Controls.Add(buttonDel); + groupBoxJewels.Controls.Add(buttonEdit); + groupBoxJewels.Controls.Add(buttonAdd); + groupBoxJewels.Controls.Add(dataGridView); + groupBoxJewels.Location = new Point(12, 87); + groupBoxJewels.Name = "groupBoxJewels"; + groupBoxJewels.Size = new Size(470, 294); + groupBoxJewels.TabIndex = 4; + groupBoxJewels.TabStop = false; + groupBoxJewels.Text = "Изделия"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(343, 188); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(104, 36); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDel + // + buttonDel.Location = new Point(343, 130); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(104, 36); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDelete_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(343, 75); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(104, 36); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(343, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(104, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnComponent, ColumnCount }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(311, 265); + dataGridView.TabIndex = 0; + // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.Name = "ColumnID"; + ColumnID.Visible = false; + // + // ColumnComponent + // + ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Location = new Point(258, 387); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(104, 36); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(378, 387); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(104, 36); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormJewel + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(509, 436); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxJewels); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormJewel"; + Text = "Изделие"; + groupBoxJewels.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxJewels; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonRefresh; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormJewel.cs b/JewelryStore/JewerlyStoreView/FormJewel.cs new file mode 100644 index 0000000..51f6525 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewel.cs @@ -0,0 +1,215 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using Microsoft.Extensions.Logging; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + + +namespace JewelryStoreView +{ + public partial class FormJewel : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + private int? _id; + private Dictionary _JewelComponents; + public int Id { set { _id = value; } } + + public FormJewel(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _JewelComponents = new Dictionary(); + } + + private void FormJewel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new JewelSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.JewelName; + textBoxPrice.Text = view.Price.ToString(); + _JewelComponents = view.JewelComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонентов изделия"); + try + { + if (_JewelComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var jc in _JewelComponents) + { + dataGridView.Rows.Add(new object[] { jc.Key, jc.Value.Item1.ComponentName, jc.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(FormJewelComponent)); + if (service is FormJewelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_JewelComponents.ContainsKey(form.Id)) + { + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _JewelComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewelComponent)); + if (service is FormJewelComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _JewelComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _JewelComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDelete_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); + _JewelComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpdate_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 (_JewelComponents == null || _JewelComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new JewelBindingModel + { + Id = _id ?? 0, + JewelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + JewelComponents = _JewelComponents + }; + 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 _JewelComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/JewelryStore/JewerlyStoreView/FormJewel.resx b/JewelryStore/JewerlyStoreView/FormJewel.resx new file mode 100644 index 0000000..9206bff --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewel.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormJewelComponent.Designer.cs b/JewelryStore/JewerlyStoreView/FormJewelComponent.Designer.cs new file mode 100644 index 0000000..e2c0db0 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewelComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace JewelryStoreView +{ + partial class FormJewelComponent + { + /// + /// 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(12, 20); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(69, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 50); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(72, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 17); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(140, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 46); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(140, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(33, 87); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(95, 27); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(134, 87); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(96, 27); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormJewelComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(249, 133); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormJewelComponent"; + Text = "КомпонентИзделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormJewelComponent.cs b/JewelryStore/JewerlyStoreView/FormJewelComponent.cs new file mode 100644 index 0000000..e539b40 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewelComponent.cs @@ -0,0 +1,80 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + public partial class FormJewelComponent : 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 FormJewelComponent(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/JewelryStore/JewerlyStoreView/FormJewelComponent.resx b/JewelryStore/JewerlyStoreView/FormJewelComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewelComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs b/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs new file mode 100644 index 0000000..8b1e38e --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs @@ -0,0 +1,113 @@ +namespace JewelryStoreView +{ + partial class FormJewels + { + /// + /// 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(); + buttonEdit = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(376, 262); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(413, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 30); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(413, 59); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(116, 31); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonUpdate_Click; + // + // buttonDel + // + buttonDel.Location = new Point(413, 108); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(116, 32); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDelete_Click; + // + // buttonRef + // + buttonRef.Location = new Point(413, 156); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(116, 31); + buttonRef.TabIndex = 4; + buttonRef.Text = "ОБновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRefresh_Click; + // + // FormJewels + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(561, 305); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormJewels"; + Text = "Изделия"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormJewels.cs b/JewelryStore/JewerlyStoreView/FormJewels.cs new file mode 100644 index 0000000..a571d6c --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewels.cs @@ -0,0 +1,115 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + public partial class FormJewels : Form + { + private readonly ILogger _logger; + private readonly IJewelLogic _logic; + + public FormJewels(ILogger logger, IJewelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["JewelComponents"].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(FormJewel)); + if (service is FormJewel form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormJewel)); + if (service is FormJewel form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_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 JewelBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormJewels_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/JewelryStore/JewerlyStoreView/FormJewels.resx b/JewelryStore/JewerlyStoreView/FormJewels.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormJewels.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/JewelryStore/JewerlyStoreView/FormMain.Designer.cs b/JewelryStore/JewerlyStoreView/FormMain.Designer.cs new file mode 100644 index 0000000..941df78 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormMain.Designer.cs @@ -0,0 +1,176 @@ +namespace JewelryStoreView +{ + 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() + { + dataGridView = new DataGridView(); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(762, 407); + dataGridView.TabIndex = 0; + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1039, 24); + menuStrip1.TabIndex = 2; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(145, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click_1; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(145, 22); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(836, 31); + buttonCreateOrder.Margin = new Padding(2); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(147, 34); + buttonCreateOrder.TabIndex = 3; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(836, 81); + buttonTakeOrderInWork.Margin = new Padding(2); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(147, 36); + buttonTakeOrderInWork.TabIndex = 4; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(836, 132); + buttonOrderReady.Margin = new Padding(2); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(147, 34); + buttonOrderReady.TabIndex = 5; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(836, 183); + buttonIssuedOrder.Margin = new Padding(2); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(147, 35); + buttonIssuedOrder.TabIndex = 6; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(836, 234); + buttonRefresh.Margin = new Padding(2); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(147, 39); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1039, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(menuStrip1); + Controls.Add(dataGridView); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Ювелирный"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormMain.cs b/JewelryStore/JewerlyStoreView/FormMain.cs new file mode 100644 index 0000000..9bccddc --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormMain.cs @@ -0,0 +1,181 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewerlyStoreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewelryStoreView +{ + 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() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["JewelId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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, + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + 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.FinishOrder(new OrderBindingModel + { + Id = id, + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + 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.DeliveryOrder(new OrderBindingModel + { + Id = id, + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), + 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 ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void компонентыToolStripMenuItem_Click_1(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(FormJewels)); + if (service is FormJewels form) + { + form.ShowDialog(); + } + } + } +} diff --git a/JewelryStore/JewerlyStoreView/FormMain.resx b/JewelryStore/JewerlyStoreView/FormMain.resx new file mode 100644 index 0000000..1cd2ba1 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormMain.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 40, 22 + + + 64 + + \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj b/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj new file mode 100644 index 0000000..ea0fd13 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj @@ -0,0 +1,23 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/Program.cs b/JewelryStore/JewerlyStoreView/Program.cs new file mode 100644 index 0000000..528100e --- /dev/null +++ b/JewelryStore/JewerlyStoreView/Program.cs @@ -0,0 +1,53 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using JewelryStoreBusinessLogic.BusinessLogics; +using System.Drawing; + +namespace JewelryStoreView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI + // settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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