From 451059c026f3719a4b4f8c4d320b76138ddaa886 Mon Sep 17 00:00:00 2001 From: Leozillo73 <76777036+Leozillo73@users.noreply.github.com> Date: Sun, 25 Feb 2024 14:03:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=201=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/FishFactory.sln | 34 ++- FishFactory/FishFactory/FishFactory.csproj | 11 - FishFactory/FishFactory/Form1.Designer.cs | 39 --- FishFactory/FishFactory/Form1.cs | 10 - FishFactory/FishFactory/Program.cs | 17 -- .../BusinessLogics/CannedLogic.cs | 112 ++++++++ .../BusinessLogics/ComponentLogic.cs | 111 ++++++++ .../BusinessLogics/OrderLogic.cs | 123 +++++++++ .../FishFactoryBusinessLogic.csproj | 17 ++ .../BindingModels/CannedBindingModel.cs | 17 ++ .../BindingModels/ComponentBindingModel.cs | 12 + .../BindingModels/OrderBindingModel.cs | 17 ++ .../BisinessLogicsContracts/ICannedLogic.cs | 16 ++ .../IComponentLogic.cs | 16 ++ .../BisinessLogicsContracts/IOrderLogic.cs | 16 ++ .../FishFactoryContracts.csproj | 13 + .../SearchModels/CannedSearchModel.cs | 9 + .../SearchModels/ComponentSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/ICannedStorage.cs | 16 ++ .../StoragesContracts/IComponentStorage.cs | 17 ++ .../StoragesContracts/IOrderStorage.cs | 17 ++ .../ViewModels/CannedViewModel.cs | 19 ++ .../ViewModels/ComponentViewModel.cs | 14 + .../ViewModels/OrderViewModel.cs | 25 ++ .../Enums/OrderStatus.cs | 11 + .../FishFactoryDataModels.csproj | 9 + FishFactory/FishFactoryDataModels/IId.cs | 8 + .../Models/ICannedModel.cs | 10 + .../Models/IComponentModel.cs | 8 + .../Models/IOrderModel.cs | 14 + .../DataListSingleton.cs | 32 +++ .../FishFactoryListImplement.csproj | 14 + .../Implements/ComponentStorage.cs | 106 ++++++++ .../Implements/OrderStorage.cs | 105 ++++++++ .../Implements/ReinforcedStorage.cs | 106 ++++++++ .../Models/Component.cs | 46 ++++ .../FishFactoryListImplement/Models/Order.cs | 62 +++++ .../Models/Reinforced.cs | 50 ++++ .../FishFactoryView/FishFacoryView.csproj | 34 +++ .../FishFactoryView/FormCanned.Designer.cs | 249 ++++++++++++++++++ FishFactory/FishFactoryView/FormCanned.cs | 213 +++++++++++++++ FishFactory/FishFactoryView/FormCanned.resx | 60 +++++ .../FormCannedComponent.Designer.cs | 125 +++++++++ .../FishFactoryView/FormCannedComponent.cs | 83 ++++++ .../FishFactoryView/FormCannedComponent.resx | 60 +++++ .../FishFactoryView/FormCanneds.Designer.cs | 138 ++++++++++ FishFactory/FishFactoryView/FormCanneds.cs | 109 ++++++++ FishFactory/FishFactoryView/FormCanneds.resx | 60 +++++ .../FishFactoryView/FormComponent.Designer.cs | 124 +++++++++ FishFactory/FishFactoryView/FormComponent.cs | 90 +++++++ .../FishFactoryView/FormComponent.resx | 60 +++++ .../FormComponents.Designer.cs | 138 ++++++++++ FishFactory/FishFactoryView/FormComponents.cs | 113 ++++++++ .../FishFactoryView/FormComponents.resx | 60 +++++ .../FormCreateOrder.Designer.cs | 153 +++++++++++ .../FishFactoryView/FormCreateOrder.cs | 127 +++++++++ .../FishFactoryView/FormCreateOrder.resx | 60 +++++ .../FishFactoryView/FormMain.Designer.cs | 184 +++++++++++++ FishFactory/FishFactoryView/FormMain.cs | 156 +++++++++++ .../FormMain.resx} | 53 ++-- FishFactory/FishFactoryView/Program.cs | 55 ++++ FishFactory/FishFactoryView/nlog.config | 15 ++ 63 files changed, 3707 insertions(+), 107 deletions(-) delete mode 100644 FishFactory/FishFactory/FishFactory.csproj delete mode 100644 FishFactory/FishFactory/Form1.Designer.cs delete mode 100644 FishFactory/FishFactory/Form1.cs delete mode 100644 FishFactory/FishFactory/Program.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj create mode 100644 FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/ComponentBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BisinessLogicsContracts/ICannedLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BisinessLogicsContracts/IComponentLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BisinessLogicsContracts/IOrderLogic.cs create mode 100644 FishFactory/FishFactoryContracts/FishFactoryContracts.csproj create mode 100644 FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/ComponentSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IComponentStorage.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs create mode 100644 FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj create mode 100644 FishFactory/FishFactoryDataModels/IId.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/ICannedModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IComponentModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IOrderModel.cs create mode 100644 FishFactory/FishFactoryListImplement/DataListSingleton.cs create mode 100644 FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj create mode 100644 FishFactory/FishFactoryListImplement/Implements/ComponentStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/ReinforcedStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Component.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Order.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Reinforced.cs create mode 100644 FishFactory/FishFactoryView/FishFacoryView.csproj create mode 100644 FishFactory/FishFactoryView/FormCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCanned.cs create mode 100644 FishFactory/FishFactoryView/FormCanned.resx create mode 100644 FishFactory/FishFactoryView/FormCannedComponent.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCannedComponent.cs create mode 100644 FishFactory/FishFactoryView/FormCannedComponent.resx create mode 100644 FishFactory/FishFactoryView/FormCanneds.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCanneds.cs create mode 100644 FishFactory/FishFactoryView/FormCanneds.resx create mode 100644 FishFactory/FishFactoryView/FormComponent.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormComponent.cs create mode 100644 FishFactory/FishFactoryView/FormComponent.resx create mode 100644 FishFactory/FishFactoryView/FormComponents.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormComponents.cs create mode 100644 FishFactory/FishFactoryView/FormComponents.resx create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.cs create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.resx create mode 100644 FishFactory/FishFactoryView/FormMain.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormMain.cs rename FishFactory/{FishFactory/Form1.resx => FishFactoryView/FormMain.resx} (91%) create mode 100644 FishFactory/FishFactoryView/Program.cs create mode 100644 FishFactory/FishFactoryView/nlog.config diff --git a/FishFactory/FishFactory.sln b/FishFactory/FishFactory.sln index 0cb3deb..c4113bf 100644 --- a/FishFactory/FishFactory.sln +++ b/FishFactory/FishFactory.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactory", "FishFactory\FishFactory.csproj", "{7D6246E7-96CD-455F-81EE-81A04D8845A3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{905C1D79-DDB9-4D7A-91B6-DBB8CE1758CB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{26D7F5A0-91FF-4076-84FE-8351FA7D1622}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{63E1CA2D-8794-434D-9C89-3B159C12FAC2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{A1205FD1-95CF-4B1F-9F83-4969059ED5A9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFacoryView", "FishFactoryView\FishFacoryView.csproj", "{C7F45F63-C57C-4226-84F6-0A66D81C4540}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +19,26 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7D6246E7-96CD-455F-81EE-81A04D8845A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7D6246E7-96CD-455F-81EE-81A04D8845A3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7D6246E7-96CD-455F-81EE-81A04D8845A3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7D6246E7-96CD-455F-81EE-81A04D8845A3}.Release|Any CPU.Build.0 = Release|Any CPU + {905C1D79-DDB9-4D7A-91B6-DBB8CE1758CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {905C1D79-DDB9-4D7A-91B6-DBB8CE1758CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {905C1D79-DDB9-4D7A-91B6-DBB8CE1758CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {905C1D79-DDB9-4D7A-91B6-DBB8CE1758CB}.Release|Any CPU.Build.0 = Release|Any CPU + {26D7F5A0-91FF-4076-84FE-8351FA7D1622}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26D7F5A0-91FF-4076-84FE-8351FA7D1622}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26D7F5A0-91FF-4076-84FE-8351FA7D1622}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26D7F5A0-91FF-4076-84FE-8351FA7D1622}.Release|Any CPU.Build.0 = Release|Any CPU + {63E1CA2D-8794-434D-9C89-3B159C12FAC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63E1CA2D-8794-434D-9C89-3B159C12FAC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63E1CA2D-8794-434D-9C89-3B159C12FAC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63E1CA2D-8794-434D-9C89-3B159C12FAC2}.Release|Any CPU.Build.0 = Release|Any CPU + {A1205FD1-95CF-4B1F-9F83-4969059ED5A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1205FD1-95CF-4B1F-9F83-4969059ED5A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1205FD1-95CF-4B1F-9F83-4969059ED5A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1205FD1-95CF-4B1F-9F83-4969059ED5A9}.Release|Any CPU.Build.0 = Release|Any CPU + {C7F45F63-C57C-4226-84F6-0A66D81C4540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7F45F63-C57C-4226-84F6-0A66D81C4540}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7F45F63-C57C-4226-84F6-0A66D81C4540}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7F45F63-C57C-4226-84F6-0A66D81C4540}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FishFactory/FishFactory/FishFactory.csproj b/FishFactory/FishFactory/FishFactory.csproj deleted file mode 100644 index b57c89e..0000000 --- a/FishFactory/FishFactory/FishFactory.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/FishFactory/FishFactory/Form1.Designer.cs b/FishFactory/FishFactory/Form1.Designer.cs deleted file mode 100644 index 7a74c88..0000000 --- a/FishFactory/FishFactory/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FishFactory -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/FishFactory/FishFactory/Form1.cs b/FishFactory/FishFactory/Form1.cs deleted file mode 100644 index 44cbbae..0000000 --- a/FishFactory/FishFactory/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FishFactory -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FishFactory/FishFactory/Program.cs b/FishFactory/FishFactory/Program.cs deleted file mode 100644 index d1028c2..0000000 --- a/FishFactory/FishFactory/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace FishFactory -{ - internal static class Program - { - /// - /// 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(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs new file mode 100644 index 0000000..8d147fc --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class CannedLogic : ICannedLogic + { + private readonly ILogger _logger; + private readonly ICannedStorage _cannedStorage; + public CannedLogic(ILogger logger, ICannedStorage CannedStorage) + { + _logger = logger; + _cannedStorage = CannedStorage; + } + public List? ReadList(CannedSearchModel? model) + { + _logger.LogInformation("ReadList. CannedName:{CannedName}.Id:{ Id}", model?.CannedName, model?.Id); + var list = model == null ? _cannedStorage.GetFullList() : _cannedStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public CannedViewModel? ReadElement(CannedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement.CannedName:{CannedName}.Id:{ Id}", model.CannedName, model.Id); + var element = _cannedStorage.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(CannedBindingModel model) + { + CheckModel(model); + if (_cannedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(CannedBindingModel model) + { + CheckModel(model); + if (_cannedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(CannedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_cannedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(CannedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CannedName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.CannedName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Canned. CannedName:{CannedName}.Price:{Price}.Id: { Id}", model.CannedName, model.Price, model.Id); + var element = _cannedStorage.GetElement(new CannedSearchModel + { + CannedName = model.CannedName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..acee8ca --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,111 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +namespace FishFactoryBusinessLogic.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/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..5350b01 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,123 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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 bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model, false); + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Принят) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order?.Status != OrderStatus.Готов) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Выдан; + model.DateImplement = order.DateImplement; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + 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)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ReinforcedId: {ReinforcedId}", model.Id, model.Sum, model.CannedId); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким номером уже есть"); + } + } + } +} diff --git a/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj b/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj new file mode 100644 index 0000000..bc03b1a --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs new file mode 100644 index 0000000..f08b1b8 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs @@ -0,0 +1,17 @@ +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class CannedBindingModel : ICannedModel + { + public int Id { get; set; } + public string CannedName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary CannedComponents + { + get; + set; + } = new(); + } +} + diff --git a/FishFactory/FishFactoryContracts/BindingModels/ComponentBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..ea033c6 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,12 @@ + +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..8773191 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int CannedId { get; set; } + public string CannedName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/BisinessLogicsContracts/ICannedLogic.cs b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/ICannedLogic.cs new file mode 100644 index 0000000..83bd907 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/ICannedLogic.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface ICannedLogic + { + List? ReadList(CannedSearchModel? model); + CannedViewModel? ReadElement(CannedSearchModel model); + bool Create(CannedBindingModel model); + bool Update(CannedBindingModel model); + bool Delete(CannedBindingModel model); + } +} + diff --git a/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IComponentLogic.cs b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..46f63aa --- /dev/null +++ b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IOrderLogic.cs b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..af12025 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BisinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj new file mode 100644 index 0000000..4a17316 --- /dev/null +++ b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs new file mode 100644 index 0000000..2bcf533 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs @@ -0,0 +1,9 @@ +namespace FishFactoryContracts.SearchModels +{ + public class CannedSearchModel + { + public int? Id { get; set; } + public string? CannedName { get; set; } + } +} + diff --git a/FishFactory/FishFactoryContracts/SearchModels/ComponentSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..ccfa11a --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace FishFactoryContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} + diff --git a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..4d57da6 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace FishFactoryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs new file mode 100644 index 0000000..41add57 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface ICannedStorage + { + List GetFullList(); + List GetFilteredList(CannedSearchModel model); + CannedViewModel? GetElement(CannedSearchModel model); + CannedViewModel? Insert(CannedBindingModel model); + CannedViewModel? Update(CannedBindingModel model); + CannedViewModel? Delete(CannedBindingModel model); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IComponentStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..9850ff7 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..dae406c --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,17 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs new file mode 100644 index 0000000..049cb09 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs @@ -0,0 +1,19 @@ +using FishFactoryDataModels.Models; +using System.ComponentModel; +namespace FishFactoryContracts.ViewModels +{ + public class CannedViewModel : ICannedModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string CannedName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary CannedComponents + { + get; + set; + } = new(); + } +} + diff --git a/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..ff1dca1 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using FishFactoryDataModels.Models; +using System.ComponentModel; +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c741c6b --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; +using System.ComponentModel; +namespace FishFactoryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int CannedId { get; set; } + [DisplayName("Изделие")] + public string CannedName { 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/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs b/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..809cff6 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace FishFactoryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/FishFactory/FishFactoryDataModels/IId.cs b/FishFactory/FishFactoryDataModels/IId.cs new file mode 100644 index 0000000..ae22872 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/IId.cs @@ -0,0 +1,8 @@ +namespace FishFactoryDataModels +{ + public interface IId + { + int Id { get; } + } +} + diff --git a/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs b/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs new file mode 100644 index 0000000..6b51c3b --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs @@ -0,0 +1,10 @@ +namespace FishFactoryDataModels.Models +{ + public interface ICannedModel : IId + { + string CannedName { get; } + double Price { get; } + Dictionary CannedComponents { get; } + } +} + diff --git a/FishFactory/FishFactoryDataModels/Models/IComponentModel.cs b/FishFactory/FishFactoryDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..7abbea1 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace FishFactoryDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..130a247 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using FishFactoryDataModels.Enums; + +namespace FishFactoryDataModels.Models +{ + public interface IOrderModel : IId + { + int CannedId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..6838bd4 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Canneds { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Canneds = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + + } +} diff --git a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj new file mode 100644 index 0000000..35ac74e --- /dev/null +++ b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/FishFactory/FishFactoryListImplement/Implements/ComponentStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..a060483 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,106 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..91a5f0b --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.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(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 (model.Id.HasValue && order.Id == model.Id) + { + result.Add(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 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 newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Implements/ReinforcedStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..833cf47 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,106 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Implements +{ + public class CannedStorage : ICannedStorage + { + private readonly DataListSingleton _source; + public CannedStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var canned in _source.Canneds) + { + result.Add(canned.GetViewModel); + } + return result; + } + public List GetFilteredList(CannedSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.CannedName)) + { + return result; + } + foreach (var canned in _source.Canneds) + { + if (canned.CannedName.Contains(model.CannedName)) + { + result.Add(canned.GetViewModel); + } + } + return result; + } + public CannedViewModel? GetElement(CannedSearchModel model) + { + if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue) + { + return null; + } + foreach (var canned in _source.Canneds) + { + if ((!string.IsNullOrEmpty(model.CannedName) && canned.CannedName == model.CannedName) || + (model.Id.HasValue && canned.Id == model.Id)) + { + return canned.GetViewModel; + } + } + return null; + } + public CannedViewModel? Insert(CannedBindingModel model) + { + model.Id = 1; + foreach (var canned in _source.Canneds) + { + if (model.Id <= canned.Id) + { + model.Id = canned.Id + 1; + } + } + var newCanned = Canned.Create(model); + if (newCanned == null) + { + return null; + } + _source.Canneds.Add(newCanned); + return newCanned.GetViewModel; + } + public CannedViewModel? Update(CannedBindingModel model) + { + foreach (var canned in _source.Canneds) + { + if (canned.Id == model.Id) + { + canned.Update(model); + return canned.GetViewModel; + } + } + return null; + } + public CannedViewModel? Delete(CannedBindingModel model) + { + for (int i = 0; i < _source.Canneds.Count; ++i) + { + if (_source.Canneds[i].Id == model.Id) + { + var element = _source.Canneds[i]; + _source.Canneds.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Component.cs b/FishFactory/FishFactoryListImplement/Models/Component.cs new file mode 100644 index 0000000..f578395 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; private 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/FishFactory/FishFactoryListImplement/Models/Order.cs b/FishFactory/FishFactoryListImplement/Models/Order.cs new file mode 100644 index 0000000..f7f94c1 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int CannedId { get; private set; } + public string CannedName { get; private set; } = String.Empty; + 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, + CannedId = model.CannedId, + CannedName = model.CannedName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + CannedId = CannedId, + CannedName = CannedName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Reinforced.cs b/FishFactory/FishFactoryListImplement/Models/Reinforced.cs new file mode 100644 index 0000000..ff7efe9 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Reinforced.cs @@ -0,0 +1,50 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Models +{ + public class Canned : ICannedModel + { + public int Id { get; private set; } + public string CannedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary CannedComponents { get; private set; } = new Dictionary(); + public static Canned? Create(CannedBindingModel? model) + { + if (model == null) + { + return null; + } + return new Canned() + { + Id = model.Id, + CannedName = model.CannedName, + Price = model.Price, + CannedComponents = model.CannedComponents + }; + } + public void Update(CannedBindingModel? model) + { + if (model == null) + { + return; + } + CannedName = model.CannedName; + Price = model.Price; + CannedComponents = model.CannedComponents; + } + public CannedViewModel GetViewModel => new() + { + Id = Id, + CannedName = CannedName, + Price = Price, + CannedComponents = CannedComponents + }; + } +} diff --git a/FishFactory/FishFactoryView/FishFacoryView.csproj b/FishFactory/FishFactoryView/FishFacoryView.csproj new file mode 100644 index 0000000..1f8f51c --- /dev/null +++ b/FishFactory/FishFactoryView/FishFacoryView.csproj @@ -0,0 +1,34 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanned.Designer.cs b/FishFactory/FishFactoryView/FormCanned.Designer.cs new file mode 100644 index 0000000..718af80 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.Designer.cs @@ -0,0 +1,249 @@ +namespace FishFactoryView +{ + partial class FormCanned + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 11); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(65, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 9); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(246, 23); + this.textBoxName.TabIndex = 1; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 38); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(73, 15); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(98, 38); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(135, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(10, 63); + this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxComponents.Size = new System.Drawing.Size(562, 239); + this.groupBoxComponents.TabIndex = 4; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(439, 158); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 26); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(439, 118); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 26); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(439, 76); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 26); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(439, 35); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 26); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(416, 215); + this.dataGridView.TabIndex = 0; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(361, 313); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(245, 313); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 26); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCanned + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(599, 347); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCanned"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormCanned_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelPrice; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn id; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanned.cs b/FishFactory/FishFactoryView/FormCanned.cs new file mode 100644 index 0000000..b58b24d --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.cs @@ -0,0 +1,213 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryDataModels.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 FishFactoryView +{ + public partial class FormCanned : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + private int? _id; + private Dictionary _CannedComponents; + public int Id { set { _id = value; } } + public FormCanned(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _CannedComponents = new Dictionary(); + } + private void FormCanned_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new CannedSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.CannedName; + textBoxPrice.Text = view.Price.ToString(); + _CannedComponents = view.CannedComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_CannedComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _CannedComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); + if (service is FormCannedComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_CannedComponents.ContainsKey(form.Id)) + { + _CannedComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _CannedComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCannedComponent)); + if (service is FormCannedComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _CannedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _CannedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _CannedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_CannedComponents == null || _CannedComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new CannedBindingModel + { + Id = _id ?? 0, + CannedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + CannedComponents = _CannedComponents + }; + 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 _CannedComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FishFactory/FishFactoryView/FormCanned.resx b/FishFactory/FishFactoryView/FormCanned.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCannedComponent.Designer.cs b/FishFactory/FishFactoryView/FormCannedComponent.Designer.cs new file mode 100644 index 0000000..e865ec6 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedComponent.Designer.cs @@ -0,0 +1,125 @@ +namespace FishFactoryView +{ + partial class FormCannedComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelComponent = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(10, 7); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(72, 15); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(104, 7); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(235, 23); + this.comboBoxComponent.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 38); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(104, 38); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(235, 23); + this.textBoxCount.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(253, 70); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(86, 31); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 70); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 31); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormReinforcedComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 110); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelComponent); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormReinforcedComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCannedComponent.cs b/FishFactory/FishFactoryView/FormCannedComponent.cs new file mode 100644 index 0000000..a72f3a7 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedComponent.cs @@ -0,0 +1,83 @@ +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.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 FishFactoryView +{ + public partial class FormCannedComponent : 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 FormCannedComponent(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/FishFactory/FishFactoryView/FormCannedComponent.resx b/FishFactory/FishFactoryView/FormCannedComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanneds.Designer.cs b/FishFactory/FishFactoryView/FormCanneds.Designer.cs new file mode 100644 index 0000000..22739eb --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanneds.Designer.cs @@ -0,0 +1,138 @@ +namespace FishFactoryView +{ + partial class FormCanneds + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.dataGridView); + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(-1, -1); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(717, 361); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(534, 173); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(534, 125); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(534, 76); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(534, 31); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(516, 359); + this.dataGridView.TabIndex = 2; + // + // FormCanneds + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(707, 359); + this.Controls.Add(this.ToolsPanel); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCanneds"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormCanneds_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanneds.cs b/FishFactory/FishFactoryView/FormCanneds.cs new file mode 100644 index 0000000..01fddb3 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanneds.cs @@ -0,0 +1,109 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +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 FishFactoryView +{ + public partial class FormCanneds : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + public FormCanneds(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormCanneds_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["CannedComponents"].Visible = false; + dataGridView.Columns["CannedName"].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(FormCanned)); + if (service is FormCanned 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(FormCanned)); + if (service is FormCanned 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 CannedBindingModel + { + 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/FishFactory/FishFactoryView/FormCanneds.resx b/FishFactory/FishFactoryView/FormCanneds.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanneds.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormComponent.Designer.cs b/FishFactory/FishFactoryView/FormComponent.Designer.cs new file mode 100644 index 0000000..22758ef --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponent.Designer.cs @@ -0,0 +1,124 @@ +namespace FishFactoryView +{ + 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() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(275, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(86, 32); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(122, 23); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(10, 32); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(143, 72); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 26); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(245, 72); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(97, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormComponent.cs b/FishFactory/FishFactoryView/FormComponent.cs new file mode 100644 index 0000000..1741296 --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponent.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +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 FishFactoryView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");//При обновлении, может быть, тоже ошибка появиться.. + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormComponent.resx b/FishFactory/FishFactoryView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormComponents.Designer.cs b/FishFactory/FishFactoryView/FormComponents.Designer.cs new file mode 100644 index 0000000..7399ba3 --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponents.Designer.cs @@ -0,0 +1,138 @@ +namespace FishFactoryView +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 2); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(519, 360); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.dataGridView); + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(-1, -1); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(675, 364); + this.ToolsPanel.TabIndex = 1; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(528, 155); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(528, 107); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(528, 58); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(528, 13); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(673, 361); + this.Controls.Add(this.ToolsPanel); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormComponents.cs b/FishFactory/FishFactoryView/FormComponents.cs new file mode 100644 index 0000000..18bafdc --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponents.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +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 FishFactoryView +{ + 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/FishFactory/FishFactoryView/FormComponents.resx b/FishFactory/FishFactoryView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs b/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..ff4aea3 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs @@ -0,0 +1,153 @@ +namespace FishFactoryView +{ + 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() + { + this.labelReinforced = new System.Windows.Forms.Label(); + this.comboBoxCanned = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelSumm = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelReinforced + // + this.labelReinforced.AutoSize = true; + this.labelReinforced.Location = new System.Drawing.Point(10, 11); + this.labelReinforced.Name = "labelReinforced"; + this.labelReinforced.Size = new System.Drawing.Size(59, 15); + this.labelReinforced.TabIndex = 0; + this.labelReinforced.Text = "Изделие: "; + // + // comboBoxReinforced + // + this.comboBoxCanned.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxCanned.FormattingEnabled = true; + this.comboBoxCanned.Location = new System.Drawing.Point(101, 9); + this.comboBoxCanned.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxCanned.Name = "comboBoxReinforced"; + this.comboBoxCanned.Size = new System.Drawing.Size(200, 23); + this.comboBoxCanned.TabIndex = 1; + this.comboBoxCanned.SelectedIndexChanged += new System.EventHandler(this.ComboBoxCanned_SelectedIndexChanged); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 37); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(78, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(101, 34); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(200, 23); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelSumm + // + this.labelSumm.AutoSize = true; + this.labelSumm.Location = new System.Drawing.Point(10, 60); + this.labelSumm.Name = "labelSumm"; + this.labelSumm.Size = new System.Drawing.Size(51, 15); + this.labelSumm.TabIndex = 4; + this.labelSumm.Text = "Сумма: "; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(101, 60); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(200, 23); + this.textBoxSum.TabIndex = 5; + this.textBoxSum.Click += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(203, 87); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(96, 24); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(101, 87); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 24); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(315, 118); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelSumm); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxCanned); + this.Controls.Add(this.labelReinforced); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelReinforced; + private ComboBox comboBoxCanned; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSumm; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCreateOrder.cs b/FishFactory/FishFactoryView/FormCreateOrder.cs new file mode 100644 index 0000000..95c180a --- /dev/null +++ b/FishFactory/FishFactoryView/FormCreateOrder.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +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 FishFactoryView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logicR; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ICannedLogic logicR, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicR = logicR; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logicR.ReadList(null); + if (list != null) + { + comboBoxCanned.DisplayMember = "CannedName"; + comboBoxCanned.ValueMember = "Id"; + comboBoxCanned.DataSource = list; + comboBoxCanned.SelectedItem = null; + } + _logger.LogInformation("Загрузка изделий для заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxCanned.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxCanned.SelectedValue); + var Canned = _logicR.ReadElement(new CannedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Canned?.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 ComboBoxCanned_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCanned.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue), + CannedName = comboBoxCanned.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormCreateOrder.resx b/FishFactory/FishFactoryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.Designer.cs b/FishFactory/FishFactoryView/FormMain.Designer.cs new file mode 100644 index 0000000..65ff79e --- /dev/null +++ b/FishFactory/FishFactoryView/FormMain.Designer.cs @@ -0,0 +1,184 @@ +namespace FishFactoryView +{ + 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() + { + menuStrip1 = new MenuStrip(); + справочникToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(5, 2, 0, 2); + menuStrip1.Size = new Size(1099, 24); + menuStrip1.TabIndex = 0; + 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; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(145, 22); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 23); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(861, 297); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(867, 40); + buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(216, 22); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(867, 91); + buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(216, 22); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(867, 143); + buttonOrderReady.Margin = new Padding(3, 2, 3, 2); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(216, 22); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(867, 191); + buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(216, 22); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(867, 232); + buttonRef.Margin = new Padding(3, 2, 3, 2); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(216, 22); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1099, 320); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 2, 3, 2); + Name = "FormMain"; + Text = "Рыбный завод"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.cs b/FishFactory/FishFactoryView/FormMain.cs new file mode 100644 index 0000000..db205a7 --- /dev/null +++ b/FishFactory/FishFactoryView/FormMain.cs @@ -0,0 +1,156 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +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 FishFactoryView +{ + 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["CannedId"].Visible = false; + dataGridView.Columns["CannedName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCanneds)); + if (service is FormCanneds form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id + }); + 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("Заказ No{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id + }); + 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("Заказ No{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FishFactory/FishFactory/Form1.resx b/FishFactory/FishFactoryView/FormMain.resx similarity index 91% rename from FishFactory/FishFactory/Form1.resx rename to FishFactory/FishFactoryView/FormMain.resx index 1af7de1..a0623c8 100644 --- a/FishFactory/FishFactory/Form1.resx +++ b/FishFactory/FishFactoryView/FormMain.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs new file mode 100644 index 0000000..bb6bf2f --- /dev/null +++ b/FishFactory/FishFactoryView/Program.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using FishFactoryBusinessLogic.BusinessLogics; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; +using FishFactoryListImplement.Implements; +using System; + +namespace FishFactoryView +{ + 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 diff --git a/FishFactory/FishFactoryView/nlog.config b/FishFactory/FishFactoryView/nlog.config new file mode 100644 index 0000000..dcd37c8 --- /dev/null +++ b/FishFactory/FishFactoryView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file