From f48e7670b925af4392dd162a2328cb7c7d587741 Mon Sep 17 00:00:00 2001 From: Ekaterina Date: Fri, 3 May 2024 20:17:56 +0400 Subject: [PATCH] L1 --- ComputersShop/ComputersShop.sln | 38 ++- .../ComputersShop/ComputersShop.csproj | 11 - ComputersShop/ComputersShop/Form1.Designer.cs | 39 --- ComputersShop/ComputersShop/Form1.cs | 10 - ComputersShop/ComputersShop/Form1.resx | 120 --------- ComputersShop/ComputersShop/Program.cs | 17 -- .../BusinessLogics/ComponentLogic.cs | 112 +++++++++ .../BusinessLogics/ComputerLogic.cs | 112 +++++++++ .../BusinessLogics/OrderLogic.cs | 124 +++++++++ .../ComputersShopBusinessLogic.csproj | 13 + .../BindingModels/ComponentBindingModel.cs | 18 ++ .../BindingModels/ComputerBindingModel.cs | 17 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IComputerLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../ComputersShopContracts.csproj | 22 ++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/ComputerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IComputerStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 20 ++ .../ViewModels/ComputerViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 37 +++ .../ComputersShopDataModels.csproj | 18 ++ .../Enums/OrderStatus.cs | 17 ++ ComputersShop/ComputersShopDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 15 ++ .../Models/IComputerModel.cs | 16 ++ .../Models/IOrderModel.cs | 19 ++ .../ComputersShopListImplement.csproj | 23 ++ .../DataListSingleton.cs | 31 +++ .../Implements/ComponentStorage.cs | 108 ++++++++ .../Implements/ComputerStorage.cs | 109 ++++++++ .../Implements/OrderStorage.cs | 116 +++++++++ .../Models/Component.cs | 47 ++++ .../Models/Computer.cs | 55 ++++ .../Models/Order.cs | 65 +++++ .../ComputersShopView.csproj | 36 +++ .../FormComponent.Designer.cs | 119 +++++++++ .../ComputersShopView/FormComponent.cs | 97 +++++++ .../ComputersShopView/FormComponent.resx | 60 +++++ .../FormComponents.Designer.cs | 115 +++++++++ .../ComputersShopView/FormComponents.cs | 117 +++++++++ .../ComputersShopView/FormComponents.resx | 60 +++++ .../FormComputer.Designer.cs | 236 ++++++++++++++++++ .../ComputersShopView/FormComputer.cs | 223 +++++++++++++++++ .../ComputersShopView/FormComputer.resx | 69 +++++ .../FormComputerComponent.Designer.cs | 119 +++++++++ .../FormComputerComponent.cs | 92 +++++++ .../FormComputerComponent.resx | 60 +++++ .../FormComputers.Designer.cs | 117 +++++++++ .../ComputersShopView/FormComputers.cs | 111 ++++++++ .../ComputersShopView/FormComputers.resx | 60 +++++ .../FormCreateOrder.Designer.cs | 144 +++++++++++ .../ComputersShopView/FormCreateOrder.cs | 130 ++++++++++ .../ComputersShopView/FormCreateOrder.resx | 60 +++++ .../ComputersShopView/FormMain.Designer.cs | 179 +++++++++++++ ComputersShop/ComputersShopView/FormMain.cs | 161 ++++++++++++ ComputersShop/ComputersShopView/FormMain.resx | 63 +++++ ComputersShop/ComputersShopView/Program.cs | 54 ++++ ComputersShop/ComputersShopView/nlog.config | 15 ++ 64 files changed, 3867 insertions(+), 204 deletions(-) delete mode 100644 ComputersShop/ComputersShop/ComputersShop.csproj delete mode 100644 ComputersShop/ComputersShop/Form1.Designer.cs delete mode 100644 ComputersShop/ComputersShop/Form1.cs delete mode 100644 ComputersShop/ComputersShop/Form1.resx delete mode 100644 ComputersShop/ComputersShop/Program.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj create mode 100644 ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs create mode 100644 ComputersShop/ComputersShopDataModels/IId.cs create mode 100644 ComputersShop/ComputersShopDataModels/Models/IComponentModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs create mode 100644 ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj create mode 100644 ComputersShop/ComputersShopListImplement/DataListSingleton.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Component.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Computer.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Order.cs create mode 100644 ComputersShop/ComputersShopView/ComputersShopView.csproj create mode 100644 ComputersShop/ComputersShopView/FormComponent.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormComponent.cs create mode 100644 ComputersShop/ComputersShopView/FormComponent.resx create mode 100644 ComputersShop/ComputersShopView/FormComponents.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormComponents.cs create mode 100644 ComputersShop/ComputersShopView/FormComponents.resx create mode 100644 ComputersShop/ComputersShopView/FormComputer.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormComputer.cs create mode 100644 ComputersShop/ComputersShopView/FormComputer.resx create mode 100644 ComputersShop/ComputersShopView/FormComputerComponent.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormComputerComponent.cs create mode 100644 ComputersShop/ComputersShopView/FormComputerComponent.resx create mode 100644 ComputersShop/ComputersShopView/FormComputers.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormComputers.cs create mode 100644 ComputersShop/ComputersShopView/FormComputers.resx create mode 100644 ComputersShop/ComputersShopView/FormCreateOrder.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormCreateOrder.cs create mode 100644 ComputersShop/ComputersShopView/FormCreateOrder.resx create mode 100644 ComputersShop/ComputersShopView/FormMain.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormMain.cs create mode 100644 ComputersShop/ComputersShopView/FormMain.resx create mode 100644 ComputersShop/ComputersShopView/Program.cs create mode 100644 ComputersShop/ComputersShopView/nlog.config diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln index 5c46177..67640d1 100644 --- a/ComputersShop/ComputersShop.sln +++ b/ComputersShop/ComputersShop.sln @@ -1,9 +1,17 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.3.32922.545 +VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop\ComputersShop.csproj", "{7679626E-6138-4DEA-B9A2-05ED676B865A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopView", "ComputersShopView\ComputersShopView.csproj", "{664326C7-7E5E-4086-BAC5-736449BDFBB9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopDataModels", "ComputersShopDataModels\ComputersShopDataModels.csproj", "{C6455380-5492-471C-AD68-160DBB6F8FD4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{4583131C-49AC-4DC3-B8E0-B3ADF49FEA03}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopListImplement", "ComputersShopListImplement\ComputersShopListImplement.csproj", "{38DB323F-5C39-44A6-921C-BB1D0C330B5B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{E8E8A4F7-E499-48CB-B3FB-25DCF234DC7F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +19,31 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7679626E-6138-4DEA-B9A2-05ED676B865A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7679626E-6138-4DEA-B9A2-05ED676B865A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7679626E-6138-4DEA-B9A2-05ED676B865A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7679626E-6138-4DEA-B9A2-05ED676B865A}.Release|Any CPU.Build.0 = Release|Any CPU + {664326C7-7E5E-4086-BAC5-736449BDFBB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {664326C7-7E5E-4086-BAC5-736449BDFBB9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {664326C7-7E5E-4086-BAC5-736449BDFBB9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {664326C7-7E5E-4086-BAC5-736449BDFBB9}.Release|Any CPU.Build.0 = Release|Any CPU + {C6455380-5492-471C-AD68-160DBB6F8FD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6455380-5492-471C-AD68-160DBB6F8FD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6455380-5492-471C-AD68-160DBB6F8FD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6455380-5492-471C-AD68-160DBB6F8FD4}.Release|Any CPU.Build.0 = Release|Any CPU + {4583131C-49AC-4DC3-B8E0-B3ADF49FEA03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4583131C-49AC-4DC3-B8E0-B3ADF49FEA03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4583131C-49AC-4DC3-B8E0-B3ADF49FEA03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4583131C-49AC-4DC3-B8E0-B3ADF49FEA03}.Release|Any CPU.Build.0 = Release|Any CPU + {38DB323F-5C39-44A6-921C-BB1D0C330B5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38DB323F-5C39-44A6-921C-BB1D0C330B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38DB323F-5C39-44A6-921C-BB1D0C330B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38DB323F-5C39-44A6-921C-BB1D0C330B5B}.Release|Any CPU.Build.0 = Release|Any CPU + {E8E8A4F7-E499-48CB-B3FB-25DCF234DC7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8E8A4F7-E499-48CB-B3FB-25DCF234DC7F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8E8A4F7-E499-48CB-B3FB-25DCF234DC7F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8E8A4F7-E499-48CB-B3FB-25DCF234DC7F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0ECD31FD-7D01-4D35-B500-416B428BC8EC} + SolutionGuid = {96DEC388-8FBA-4902-A051-43496E42AC19} EndGlobalSection EndGlobal diff --git a/ComputersShop/ComputersShop/ComputersShop.csproj b/ComputersShop/ComputersShop/ComputersShop.csproj deleted file mode 100644 index b57c89e..0000000 --- a/ComputersShop/ComputersShop/ComputersShop.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Form1.Designer.cs b/ComputersShop/ComputersShop/Form1.Designer.cs deleted file mode 100644 index 8127802..0000000 --- a/ComputersShop/ComputersShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ComputersShop -{ - 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/ComputersShop/ComputersShop/Form1.cs b/ComputersShop/ComputersShop/Form1.cs deleted file mode 100644 index 85dadf8..0000000 --- a/ComputersShop/ComputersShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ComputersShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Form1.resx b/ComputersShop/ComputersShop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/ComputersShop/ComputersShop/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Program.cs b/ComputersShop/ComputersShop/Program.cs deleted file mode 100644 index 6394a0e..0000000 --- a/ComputersShop/ComputersShop/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ComputersShop -{ - 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/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..35a0d59 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.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.GetFiltredList(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("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs new file mode 100644 index 0000000..36a308c --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class ComputerLogic : IComputerLogic + { + private readonly ILogger _logger; + private readonly IComputerStorage _computerStorage; + public ComputerLogic(ILogger logger, IComputerStorage computerStorage) + { + _logger = logger; + _computerStorage = computerStorage; + } + public List? ReadList(ComputerSearchModel? model) + { + _logger.LogInformation("ReadList. ComputerName:{ComputerName}. Id:{Id}", model?.ComputerName, model?.Id); + var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFiltredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComputerViewModel? ReadElement(ComputerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComputerName:{ComputerName}. Id:{Id}", model.ComputerName, model.Id); + var element = _computerStorage.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(ComputerBindingModel model) + { + CheckModel(model); + if (_computerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComputerBindingModel model) + { + CheckModel(model); + if (_computerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComputerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_computerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComputerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComputerName)) + { + throw new ArgumentNullException("Нет названия компьютера", nameof(model.ComputerName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Computer. ComputerName:{ComputerName}. Cost:{Cost}. Id:{Id}", model.ComputerName, model.Price, model.Id); + var element = _computerStorage.GetElement(new ComputerSearchModel + { + ComputerName = model.ComputerName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компьютер с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..0070a56 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.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.GetFiltredList(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("Wrong order status. Insert operation failed"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(viewModel)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Status change operation failed"); + return false; + } + + model.Status = newStatus; + model.ComputerId = viewModel.ComputerId; + model.Count = viewModel.Count; + model.Sum = viewModel.Sum; + model.DateCreate = viewModel.DateCreate; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Status change operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.DateImplement != null && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException("Дата завершения не может быть раньше даты начала"); + } + _logger.LogInformation("Order. Id:{Id}. Sum:{Sum}. ComputerId:{ComputerId}", model.Id, model.Sum, model.ComputerId); + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj new file mode 100644 index 0000000..4e29547 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..2e6ab61 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs new file mode 100644 index 0000000..b7ba1e6 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class ComputerBindingModel : IComputerModel + { + public int Id { get; set; } + public string ComputerName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ComputerComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..dc3a2da --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ComputerId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..42896d2 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs new file mode 100644 index 0000000..f2cd941 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IComputerLogic + { + List? ReadList(ComputerSearchModel? model); + ComputerViewModel? ReadElement(ComputerSearchModel model); + bool Create(ComputerBindingModel model); + bool Update(ComputerBindingModel model); + bool Delete(ComputerBindingModel model); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..54f9079 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj new file mode 100644 index 0000000..7ff5503 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..612b030 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs new file mode 100644 index 0000000..2d45208 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ComputerSearchModel + { + public int? Id { get; set; } + public string? ComputerName { get; set; } + } + +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..77e423b --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } + +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..d819f35 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFiltredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs new file mode 100644 index 0000000..2dcf346 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComputerStorage + { + List GetFullList(); + List GetFiltredList(ComputerSearchModel model); + ComputerViewModel? GetElement(ComputerSearchModel model); + ComputerViewModel? Insert(ComputerBindingModel model); + ComputerViewModel? Update(ComputerBindingModel model); + ComputerViewModel? Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..c986423 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFiltredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..dc4627a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; +using System.ComponentModel; + + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs new file mode 100644 index 0000000..b75fe37 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.ViewModels +{ + public class ComputerViewModel : IComputerModel + { + public int Id { get; set; } + + [DisplayName("Название компьютера")] + public string ComputerName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary ComputerComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..8db9a95 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int ComputerId { get; set; } + + [DisplayName("Компьютер")] + public string ComputerName { 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; } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj new file mode 100644 index 0000000..8ee6bda --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs b/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..3d8cd83 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/ComputersShop/ComputersShopDataModels/IId.cs b/ComputersShop/ComputersShopDataModels/IId.cs new file mode 100644 index 0000000..99b74e8 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IComponentModel.cs b/ComputersShop/ComputersShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..b20a3fb --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } + +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs b/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs new file mode 100644 index 0000000..0f78079 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Models +{ + public interface IComputerModel : IId + { + string ComputerName { get; } + double Price { get; } + Dictionary ComputerComponents { get; } + } + +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..b674c42 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Enums; + +namespace ComputersShopDataModels.Models +{ + public interface IOrderModel : IId + { + int ComputerId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj new file mode 100644 index 0000000..31f657b --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/ComputersShopListImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..3337082 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopListImplement.Models; + +namespace AbstractShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Computers { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Computers = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..d9e9843 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractShopListImplement; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.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 GetFiltredList(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/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs new file mode 100644 index 0000000..df4ced8 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractShopListImplement; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.Implements +{ + public class ComputerStorage : IComputerStorage + { + private readonly DataListSingleton _source; + public ComputerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var computer in _source.Computers) + { + result.Add(computer.GetViewModel); + } + return result; + } + public List GetFiltredList(ComputerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComputerName)) + { + return result; + } + foreach (var computer in _source.Computers) + { + if (computer.ComputerName.Contains(model.ComputerName)) + { + result.Add(computer.GetViewModel); + } + } + return result; + } + public ComputerViewModel? GetElement(ComputerSearchModel model) + { + if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue) + { + return null; + } + foreach (var computer in _source.Computers) + { + if ((!string.IsNullOrEmpty(model.ComputerName) + && computer.ComputerName == model.ComputerName) + || (model.Id.HasValue && computer.Id == model.Id)) + { + return computer.GetViewModel; + } + } + return null; + } + public ComputerViewModel? Insert(ComputerBindingModel model) + { + model.Id = 1; + foreach (var computer in _source.Computers) + { + if (model.Id <= computer.Id) + { + model.Id = computer.Id + 1; + } + } + var newComputer = Computer.Create(model); + if (newComputer == null) + { + return null; + } + _source.Computers.Add(newComputer); + return newComputer.GetViewModel; + } + public ComputerViewModel? Update(ComputerBindingModel model) + { + foreach (var computer in _source.Computers) + { + if (computer.Id == model.Id) + { + computer.Update(model); + return computer.GetViewModel; + } + } + return null; + } + public ComputerViewModel? Delete(ComputerBindingModel model) + { + for (int i = 0; i < _source.Computers.Count; ++i) + { + if (_source.Computers[i].Id == model.Id) + { + var element = _source.Computers[i]; + _source.Computers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} + diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..56af78b --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractShopListImplement; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.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(AddComputerName(order.GetViewModel)); + } + return result; + } + public List GetFiltredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AddComputerName(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 AddComputerName(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 AddComputerName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddComputerName(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 AddComputerName(element.GetViewModel); + } + } + return null; + } + private OrderViewModel AddComputerName(OrderViewModel model) + { + var selectedComputer = _source.Computers.Find(computer => computer.Id == model.ComputerId); + if (selectedComputer != null) + { + model.ComputerName = selectedComputer.ComputerName; + } + return model; + } + } +} + diff --git a/ComputersShop/ComputersShopListImplement/Models/Component.cs b/ComputersShop/ComputersShopListImplement/Models/Component.cs new file mode 100644 index 0000000..df71d8f --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Computer.cs b/ComputersShop/ComputersShopListImplement/Models/Computer.cs new file mode 100644 index 0000000..eaea470 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Computer.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; + + +namespace ComputersShopListImplement.Models +{ + public class Computer : IComputerModel + { + public int Id { get; private set; } + public string ComputerName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ComputerComponents + { + get; + private set; + } = new Dictionary(); + public static Computer? Create(ComputerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Computer() + { + Id = model.Id, + ComputerName = model.ComputerName, + Price = model.Price, + ComputerComponents = model.ComputerComponents + }; + } + public void Update(ComputerBindingModel? model) + { + if (model == null) + { + return; + } + ComputerName = model.ComputerName; + Price = model.Price; + ComputerComponents = model.ComputerComponents; + } + public ComputerViewModel GetViewModel => new() + { + Id = Id, + ComputerName = ComputerName, + Price = Price, + ComputerComponents = ComputerComponents + }; + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Order.cs b/ComputersShop/ComputersShopListImplement/Models/Order.cs new file mode 100644 index 0000000..8853423 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ComputerId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ComputerId = model.ComputerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + ComputerId = model.ComputerId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ComputerId = ComputerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/ComputersShopView.csproj b/ComputersShop/ComputersShopView/ComputersShopView.csproj new file mode 100644 index 0000000..ed255c7 --- /dev/null +++ b/ComputersShop/ComputersShopView/ComputersShopView.csproj @@ -0,0 +1,36 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComponent.Designer.cs b/ComputersShop/ComputersShopView/FormComponent.Designer.cs new file mode 100644 index 0000000..dcf4072 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ComputersShopView +{ + 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.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + 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(12, 27); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 72); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(48, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 27); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(263, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(98, 69); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(130, 27); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(174, 117); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + 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(290, 117); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + 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(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(411, 172); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComponent.cs b/ComputersShop/ComputersShopView/FormComponent.cs new file mode 100644 index 0000000..70045f5 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComponent.cs @@ -0,0 +1,97 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + + +namespace ComputersShopView +{ + 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/ComputersShop/ComputersShopView/FormComponent.resx b/ComputersShop/ComputersShopView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormComponents.Designer.cs b/ComputersShop/ComputersShopView/FormComponents.Designer.cs new file mode 100644 index 0000000..c57558f --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace ComputersShopView +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(517, 451); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(542, 29); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(119, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(542, 79); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(119, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(542, 131); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(119, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(542, 175); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(119, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(683, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComponents.cs b/ComputersShop/ComputersShopView/FormComponents.cs new file mode 100644 index 0000000..d8a97c4 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComponents.cs @@ -0,0 +1,117 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using Microsoft.Extensions.Logging; + + +namespace ComputersShopView +{ + 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/ComputersShop/ComputersShopView/FormComponents.resx b/ComputersShop/ComputersShopView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormComputer.Designer.cs b/ComputersShop/ComputersShopView/FormComputer.Designer.cs new file mode 100644 index 0000000..cc2d7ae --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputer.Designer.cs @@ -0,0 +1,236 @@ +namespace ComputersShopView +{ + partial class FormComputer + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Controls.Add(this.buttonUpd); + this.groupBox1.Controls.Add(this.buttonDel); + this.groupBox1.Controls.Add(this.buttonRef); + this.groupBox1.Controls.Add(this.buttonAdd); + this.groupBox1.Location = new System.Drawing.Point(12, 111); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(776, 292); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты"; + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(619, 259); + this.dataGridView.TabIndex = 6; + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(648, 98); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 3; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(648, 160); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 4; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(648, 220); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 5; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(648, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(513, 409); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(118, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(652, 409); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(111, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 30); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 6; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 75); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(86, 20); + this.labelPrice.TabIndex = 7; + this.labelPrice.Text = "Стоимость:"; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(110, 75); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(231, 27); + this.textBoxPrice.TabIndex = 8; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(110, 27); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(368, 27); + this.textBoxName.TabIndex = 9; + // + // ColumnId + // + this.ColumnId.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.Visible = false; + // + // ColumnComponent + // + this.ColumnComponent.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.MinimumWidth = 6; + this.ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + this.ColumnCount.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 100; + this.ColumnCount.Name = "ColumnCount"; + // + // FormComputer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBox1); + this.Name = "FormComputer"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormСomputer_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox groupBox1; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelPrice; + private TextBox textBoxPrice; + private TextBox textBoxName; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComputer.cs b/ComputersShop/ComputersShopView/FormComputer.cs new file mode 100644 index 0000000..3633451 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputer.cs @@ -0,0 +1,223 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopDataModels.Models; +using Microsoft.Extensions.Logging; + + +namespace ComputersShopView +{ + public partial class FormComputer : Form + { + private readonly ILogger _logger; + private readonly IComputerLogic _logic; + private int? _id; + private Dictionary _computerComponents; + public int Id { set { _id = value; } } + + public FormComputer(ILogger logger, IComputerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _computerComponents = new Dictionary(); + } + private void FormСomputer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ComputerSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComputerName; + textBoxPrice.Text = view.Price.ToString(); + _computerComponents = view.ComputerComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_computerComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _computerComponents) + { + 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(FormComputerComponent)); + if (service is FormComputerComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_computerComponents.ContainsKey(form.Id)) + { + _computerComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _computerComponents.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(FormComputerComponent)); + if (service is FormComputerComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _computerComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _computerComponents[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); + _computerComponents?.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 (_computerComponents == null || _computerComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ComputerBindingModel + { + Id = _id ?? 0, + ComputerName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ComputerComponents = _computerComponents + }; + 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 _computerComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormComputer.resx b/ComputersShop/ComputersShopView/FormComputer.resx new file mode 100644 index 0000000..30a7e11 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputer.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComputerComponent.Designer.cs b/ComputersShop/ComputersShopView/FormComputerComponent.Designer.cs new file mode 100644 index 0000000..2c07ec4 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputerComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ComputersShopView +{ + partial class FormComputerComponent + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(190, 136); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(306, 136); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(12, 28); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(91, 20); + this.labelComponent.TabIndex = 2; + this.labelComponent.Text = "Компонент:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 85); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(111, 85); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(263, 27); + this.textBoxCount.TabIndex = 4; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(111, 25); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(263, 28); + this.comboBoxComponent.TabIndex = 5; + // + // FormComputerComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(412, 177); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormComputerComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelComponent; + private Label labelCount; + private TextBox textBoxCount; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComputerComponent.cs b/ComputersShop/ComputersShopView/FormComputerComponent.cs new file mode 100644 index 0000000..595a604 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputerComponent.cs @@ -0,0 +1,92 @@ +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; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; + + +namespace ComputersShopView +{ + public partial class FormComputerComponent : 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 FormComputerComponent(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/ComputersShop/ComputersShopView/FormComputerComponent.resx b/ComputersShop/ComputersShopView/FormComputerComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputerComponent.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/ComputersShop/ComputersShopView/FormComputers.Designer.cs b/ComputersShop/ComputersShopView/FormComputers.Designer.cs new file mode 100644 index 0000000..57915cc --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputers.Designer.cs @@ -0,0 +1,117 @@ +using System.Windows.Forms; + +namespace ComputersShopView +{ + partial class FormComputers + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(517, 451); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(542, 29); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(119, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(542, 79); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(119, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(542, 131); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(119, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(542, 175); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(119, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComputers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(683, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComputers"; + this.Text = "Компьютеры"; + this.Load += new System.EventHandler(this.FormComputers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormComputers.cs b/ComputersShop/ComputersShopView/FormComputers.cs new file mode 100644 index 0000000..f481724 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputers.cs @@ -0,0 +1,111 @@ +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; +using Microsoft.Extensions.Logging; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; + +namespace ComputersShopView +{ + public partial class FormComputers : Form + { + private readonly ILogger _logger; + + private readonly IComputerLogic _logic; + public FormComputers(ILogger logger, IComputerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComputers_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["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ComputerComponents"].Visible = false; + } + _logger.LogInformation("Computers loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Computers loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComputer)); + if (service is FormComputer 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(FormComputer)); + if (service is FormComputer 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("Deletion of computer"); + try + { + if (!_logic.Delete(new ComputerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Computer deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormComputers.resx b/ComputersShop/ComputersShopView/FormComputers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormComputers.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/ComputersShop/ComputersShopView/FormCreateOrder.Designer.cs b/ComputersShop/ComputersShopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..c87a94b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace ComputersShopView +{ + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.comboBoxComputer = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(269, 158); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(369, 158); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 62); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 107); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(58, 20); + this.label3.TabIndex = 4; + this.label3.Text = "Сумма:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(111, 62); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(318, 27); + this.textBoxCount.TabIndex = 5; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(111, 104); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(318, 27); + this.textBoxSum.TabIndex = 6; + // + // comboBoxComputer + // + this.comboBoxComputer.FormattingEnabled = true; + this.comboBoxComputer.Location = new System.Drawing.Point(111, 15); + this.comboBoxComputer.Name = "comboBoxComputer"; + this.comboBoxComputer.Size = new System.Drawing.Size(318, 28); + this.comboBoxComputer.TabIndex = 7; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(475, 199); + this.Controls.Add(this.comboBoxComputer); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.label3); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label labelCount; + private Label label3; + private TextBox textBoxCount; + private TextBox textBoxSum; + private ComboBox comboBoxComputer; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormCreateOrder.cs b/ComputersShop/ComputersShopView/FormCreateOrder.cs new file mode 100644 index 0000000..6734fa3 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormCreateOrder.cs @@ -0,0 +1,130 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + + +namespace ComputersShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IComputerLogic _logicC; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IComputerLogic logicC, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicC = logicC; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var computerList = _logicC.ReadList(null); + if (computerList != null) + { + comboBoxComputer.DataSource = computerList; + comboBoxComputer.DisplayMember = "ComputerName"; + comboBoxComputer.ValueMember = "Id"; + comboBoxComputer.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при загрузке изделиц для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxComputer.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxComputer.SelectedValue); + var computer = _logicC.ReadElement(new ComputerSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (computer?.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 ComboBoxComputer_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 (comboBoxComputer.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ComputerId = Convert.ToInt32(comboBoxComputer.SelectedValue), + 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/ComputersShop/ComputersShopView/FormCreateOrder.resx b/ComputersShop/ComputersShopView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs new file mode 100644 index 0000000..72c4b76 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -0,0 +1,179 @@ +namespace ComputersShopView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1147, 28); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 31); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(921, 273); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(951, 44); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(184, 29); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(951, 94); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(184, 29); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(951, 142); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(184, 29); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(951, 191); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(184, 29); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(951, 239); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(184, 29); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1147, 316); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Компьютерный магазин"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs new file mode 100644 index 0000000..dbaadbf --- /dev/null +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -0,0 +1,161 @@ +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; +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ComputersShopView +{ + 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["ComputerId"].Visible = false; + dataGridView.Columns["ComputerName"].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(FormComputers)); + if (service is FormComputers form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} + diff --git a/ComputersShop/ComputersShopView/FormMain.resx b/ComputersShop/ComputersShopView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/ComputersShop/ComputersShopView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs new file mode 100644 index 0000000..6e41552 --- /dev/null +++ b/ComputersShop/ComputersShopView/Program.cs @@ -0,0 +1,54 @@ +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.StoragesContracts; +using ComputersShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + +namespace ComputersShopView +{ + 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/ComputersShop/ComputersShopView/nlog.config b/ComputersShop/ComputersShopView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/ComputersShop/ComputersShopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file