From 6043232a67ac01fae83ae2f9b293b06127d3170f Mon Sep 17 00:00:00 2001 From: "evasina2312@gmail.com" Date: Wed, 1 Mar 2023 10:48:56 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComputersShop/ComputersShop.sln | 34 ++- ComputersShop/ComputersShop/App.config | 6 - .../ComputersShop/ComputersShop.csproj | 80 ------ .../ComputersShop/ComputersShopView.csproj | 32 +++ ComputersShop/ComputersShop/Form1.Designer.cs | 40 --- ComputersShop/ComputersShop/Form1.cs | 20 -- .../ComputersShop/FormComponent.Designer.cs | 119 +++++++++ ComputersShop/ComputersShop/FormComponent.cs | 87 ++++++ .../ComputersShop/FormComponent.resx | 60 +++++ .../ComputersShop/FormComponents.Designer.cs | 121 +++++++++ ComputersShop/ComputersShop/FormComponents.cs | 98 +++++++ .../ComputersShop/FormComponents.resx | 63 +++++ .../ComputersShop/FormComputer.Designer.cs | 247 ++++++++++++++++++ ComputersShop/ComputersShop/FormComputer.cs | 198 ++++++++++++++ ComputersShop/ComputersShop/FormComputer.resx | 78 ++++++ .../FormComputerComponent.Designer.cs | 126 +++++++++ .../ComputersShop/FormComputerComponent.cs | 78 ++++++ .../ComputersShop/FormComputerComponent.resx | 60 +++++ .../ComputersShop/FormComputers.Designer.cs | 121 +++++++++ ComputersShop/ComputersShop/FormComputers.cs | 96 +++++++ .../ComputersShop/FormComputers.resx | 63 +++++ .../ComputersShop/FormCreateOrder.Designer.cs | 154 +++++++++++ .../ComputersShop/FormCreateOrder.cs | 103 ++++++++ .../ComputersShop/FormCreateOrder.resx | 60 +++++ .../ComputersShop/FormMain.Designer.cs | 188 +++++++++++++ ComputersShop/ComputersShop/FormMain.cs | 141 ++++++++++ ComputersShop/ComputersShop/FormMain.resx | 63 +++++ ComputersShop/ComputersShop/Program.cs | 52 +++- .../ComputersShop/Properties/AssemblyInfo.cs | 36 --- .../Properties/Resources.Designer.cs | 71 ----- .../ComputersShop/Properties/Resources.resx | 117 --------- .../Properties/Settings.Designer.cs | 30 --- .../Properties/Settings.settings | 7 - ComputersShop/ComputersShop/nlog.config | 14 + .../ComponentLogic.cs | 109 ++++++++ .../ComputerLogic.cs | 108 ++++++++ .../ComputersShopBusinessLogic.csproj | 17 ++ .../ComputersShopBusinessLogic/OrderLogic.cs | 114 ++++++++ .../BindingModels/ComponentBindingModel.cs | 12 + .../BindingModels/ComputerBindingModel.cs | 12 + .../BindingModels/OrderBindingModel.cs | 16 ++ .../IComponentLogic.cs | 15 ++ .../BusinessLogicsContracts/IComputerLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 16 ++ .../ComputersShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/ComputerSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 16 ++ .../StoragesContracts/IComputerStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../ViewModels/ComponentViewModel.cs | 15 ++ .../ViewModels/ComputerViewModel.cs | 15 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../ComputersShopDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 11 + ComputersShop/ComputersShopDataModels/IId.cs | 8 + .../Models/IComponentModel.cs | 8 + .../Models/IComputerModel.cs | 9 + .../Models/IOrderModel.cs | 14 + .../ComputersShopListImplement.csproj | 14 + .../DataListSingleton.cs | 26 ++ .../Implements/ComponentStorage.cs | 104 ++++++++ .../Implements/ComputerStorage.cs | 100 +++++++ .../Implements/OrderStorage.cs | 112 ++++++++ .../Models/Component.cs | 41 +++ .../ComputersShopImplement/Models/Computer.cs | 49 ++++ .../ComputersShopImplement/Models/Order.cs | 65 +++++ 68 files changed, 3581 insertions(+), 425 deletions(-) delete mode 100644 ComputersShop/ComputersShop/App.config delete mode 100644 ComputersShop/ComputersShop/ComputersShop.csproj create mode 100644 ComputersShop/ComputersShop/ComputersShopView.csproj delete mode 100644 ComputersShop/ComputersShop/Form1.Designer.cs delete mode 100644 ComputersShop/ComputersShop/Form1.cs create mode 100644 ComputersShop/ComputersShop/FormComponent.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComponent.cs create mode 100644 ComputersShop/ComputersShop/FormComponent.resx create mode 100644 ComputersShop/ComputersShop/FormComponents.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComponents.cs create mode 100644 ComputersShop/ComputersShop/FormComponents.resx create mode 100644 ComputersShop/ComputersShop/FormComputer.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComputer.cs create mode 100644 ComputersShop/ComputersShop/FormComputer.resx create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.cs create mode 100644 ComputersShop/ComputersShop/FormComputerComponent.resx create mode 100644 ComputersShop/ComputersShop/FormComputers.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormComputers.cs create mode 100644 ComputersShop/ComputersShop/FormComputers.resx create mode 100644 ComputersShop/ComputersShop/FormCreateOrder.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormCreateOrder.cs create mode 100644 ComputersShop/ComputersShop/FormCreateOrder.resx create mode 100644 ComputersShop/ComputersShop/FormMain.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormMain.cs create mode 100644 ComputersShop/ComputersShop/FormMain.resx delete mode 100644 ComputersShop/ComputersShop/Properties/AssemblyInfo.cs delete mode 100644 ComputersShop/ComputersShop/Properties/Resources.Designer.cs delete mode 100644 ComputersShop/ComputersShop/Properties/Resources.resx delete mode 100644 ComputersShop/ComputersShop/Properties/Settings.Designer.cs delete mode 100644 ComputersShop/ComputersShop/Properties/Settings.settings create mode 100644 ComputersShop/ComputersShop/nlog.config create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComponentLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComputerLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj create mode 100644 ComputersShop/ComputersShopBusinessLogic/OrderLogic.cs 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/ComputersShopImplement/ComputersShopListImplement.csproj create mode 100644 ComputersShop/ComputersShopImplement/DataListSingleton.cs create mode 100644 ComputersShop/ComputersShopImplement/Implements/ComponentStorage.cs create mode 100644 ComputersShop/ComputersShopImplement/Implements/ComputerStorage.cs create mode 100644 ComputersShop/ComputersShopImplement/Implements/OrderStorage.cs create mode 100644 ComputersShop/ComputersShopImplement/Models/Component.cs create mode 100644 ComputersShop/ComputersShopImplement/Models/Computer.cs create mode 100644 ComputersShop/ComputersShopImplement/Models/Order.cs diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln index 2afb7d3..cbd03be 100644 --- a/ComputersShop/ComputersShop.sln +++ b/ComputersShop/ComputersShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.32421.90 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShop", "ComputersShop\ComputersShop.csproj", "{2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopView", "ComputersShop\ComputersShopView.csproj", "{44901912-5016-4C1D-8FB0-B4AF6577D27D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopDataModels", "ComputersShopDataModels\ComputersShopDataModels.csproj", "{C89D20B1-2A19-4652-9477-C5EA596FAE58}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{188B642F-C773-4F09-A369-C64849A768AE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{946DAAFE-F189-4516-9DDB-3E77ED4B8665}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopListImplement", "ComputersShopImplement\ComputersShopListImplement.csproj", "{DA9CE365-F11F-4607-9003-C9EABE4198BB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +19,26 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA}.Release|Any CPU.Build.0 = Release|Any CPU + {44901912-5016-4C1D-8FB0-B4AF6577D27D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {44901912-5016-4C1D-8FB0-B4AF6577D27D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44901912-5016-4C1D-8FB0-B4AF6577D27D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {44901912-5016-4C1D-8FB0-B4AF6577D27D}.Release|Any CPU.Build.0 = Release|Any CPU + {C89D20B1-2A19-4652-9477-C5EA596FAE58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C89D20B1-2A19-4652-9477-C5EA596FAE58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C89D20B1-2A19-4652-9477-C5EA596FAE58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C89D20B1-2A19-4652-9477-C5EA596FAE58}.Release|Any CPU.Build.0 = Release|Any CPU + {188B642F-C773-4F09-A369-C64849A768AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {188B642F-C773-4F09-A369-C64849A768AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {188B642F-C773-4F09-A369-C64849A768AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {188B642F-C773-4F09-A369-C64849A768AE}.Release|Any CPU.Build.0 = Release|Any CPU + {946DAAFE-F189-4516-9DDB-3E77ED4B8665}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {946DAAFE-F189-4516-9DDB-3E77ED4B8665}.Debug|Any CPU.Build.0 = Debug|Any CPU + {946DAAFE-F189-4516-9DDB-3E77ED4B8665}.Release|Any CPU.ActiveCfg = Release|Any CPU + {946DAAFE-F189-4516-9DDB-3E77ED4B8665}.Release|Any CPU.Build.0 = Release|Any CPU + {DA9CE365-F11F-4607-9003-C9EABE4198BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA9CE365-F11F-4607-9003-C9EABE4198BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA9CE365-F11F-4607-9003-C9EABE4198BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA9CE365-F11F-4607-9003-C9EABE4198BB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComputersShop/ComputersShop/App.config b/ComputersShop/ComputersShop/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/ComputersShop/ComputersShop/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ComputersShop/ComputersShop/ComputersShop.csproj b/ComputersShop/ComputersShop/ComputersShop.csproj deleted file mode 100644 index c0b1e72..0000000 --- a/ComputersShop/ComputersShop/ComputersShop.csproj +++ /dev/null @@ -1,80 +0,0 @@ - - - - - Debug - AnyCPU - {2BAD8746-A1A3-44DD-B546-7F06A7B1DFEA} - WinExe - ComputersShop - ComputersShop - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - Form - - - Form1.cs - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - \ No newline at end of file diff --git a/ComputersShop/ComputersShop/ComputersShopView.csproj b/ComputersShop/ComputersShop/ComputersShopView.csproj new file mode 100644 index 0000000..9bbe2db --- /dev/null +++ b/ComputersShop/ComputersShop/ComputersShopView.csproj @@ -0,0 +1,32 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + \ 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 fea81a0..0000000 --- a/ComputersShop/ComputersShop/Form1.Designer.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace ComputersShop -{ - partial class Form1 - { - /// - /// Обязательная переменная конструктора. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Освободить все используемые ресурсы. - /// - /// истинно, если управляемый ресурс должен быть удален; иначе ложно. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Код, автоматически созданный конструктором форм Windows - - /// - /// Требуемый метод для поддержки конструктора — не изменяйте - /// содержимое этого метода с помощью редактора кода. - /// - 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 - } -} - diff --git a/ComputersShop/ComputersShop/Form1.cs b/ComputersShop/ComputersShop/Form1.cs deleted file mode 100644 index 396fd14..0000000 --- a/ComputersShop/ComputersShop/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ComputersShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ComputersShop/ComputersShop/FormComponent.Designer.cs b/ComputersShop/ComputersShop/FormComponent.Designer.cs new file mode 100644 index 0000000..99f0bd8 --- /dev/null +++ b/ComputersShop/ComputersShop/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.textBoxComponentName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelComponentName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.Load += new System.EventHandler(this.FormComponent_Load); + this.SuspendLayout(); + // + // textBoxComponentName + // + this.textBoxComponentName.Location = new System.Drawing.Point(105, 12); + this.textBoxComponentName.Name = "textBoxComponentName"; + this.textBoxComponentName.Size = new System.Drawing.Size(247, 27); + this.textBoxComponentName.TabIndex = 0; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(105, 45); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(122, 27); + this.textBoxCost.TabIndex = 1; + // + // labelComponentName + // + this.labelComponentName.AutoSize = true; + this.labelComponentName.Location = new System.Drawing.Point(19, 15); + this.labelComponentName.Name = "labelComponentName"; + this.labelComponentName.Size = new System.Drawing.Size(80, 20); + this.labelComponentName.TabIndex = 2; + this.labelComponentName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(19, 48); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(48, 20); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(146, 95); + 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(258, 95); + 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(364, 136); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelComponentName); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxComponentName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxComponentName; + private TextBox textBoxCost; + private Label labelComponentName; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComponent.cs b/ComputersShop/ComputersShop/FormComponent.cs new file mode 100644 index 0000000..4997f15 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponent.cs @@ -0,0 +1,87 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +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) + { + textBoxComponentName.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(textBoxComponentName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxComponentName.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/ComputersShop/FormComponent.resx b/ComputersShop/ComputersShop/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShop/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/ComputersShop/FormComponents.Designer.cs b/ComputersShop/ComputersShop/FormComponents.Designer.cs new file mode 100644 index 0000000..f15fb89 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.Designer.cs @@ -0,0 +1,121 @@ +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() + { + System.Windows.Forms.Button buttonRef; + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + buttonRef.Location = new System.Drawing.Point(637, 125); + buttonRef.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new System.Drawing.Size(159, 31); + buttonRef.TabIndex = 2; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, -1); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(630, 735); + this.dataGridView.TabIndex = 1; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(637, 86); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(159, 31); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(637, 48); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(159, 31); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(637, 9); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(159, 31); + this.buttonAdd.TabIndex = 5; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(807, 498); + this.Controls.Add(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 buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComponents.cs b/ComputersShop/ComputersShop/FormComponents.cs new file mode 100644 index 0000000..710838e --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.cs @@ -0,0 +1,98 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +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/ComputersShop/FormComponents.resx b/ComputersShop/ComputersShop/FormComponents.resx new file mode 100644 index 0000000..fa1d9b6 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComponents.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 + + + False + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputer.Designer.cs b/ComputersShop/ComputersShop/FormComputer.Designer.cs new file mode 100644 index 0000000..9550816 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputer.Designer.cs @@ -0,0 +1,247 @@ +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.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ManufactureId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.Load += new System.EventHandler(this.FormComputer_Load); + this.SuspendLayout(); + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(11, 90); + this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxComponents.Size = new System.Drawing.Size(887, 547); + this.groupBoxComponents.TabIndex = 7; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(710, 145); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(170, 31); + this.buttonRef.TabIndex = 1; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(710, 107); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(170, 31); + this.buttonDel.TabIndex = 1; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(710, 68); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(170, 31); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(710, 29); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(170, 31); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ManufactureId, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(7, 29); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(696, 509); + this.dataGridView.TabIndex = 0; + // + // ManufactureId + // + this.ManufactureId.HeaderText = "Id"; + this.ManufactureId.MinimumWidth = 6; + this.ManufactureId.Name = "ManufactureId"; + this.ManufactureId.Visible = false; + this.ManufactureId.Width = 125; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.Width = 125; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(15, 54); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(83, 20); + this.labelPrice.TabIndex = 5; + this.labelPrice.Text = "Стоимость"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(18, 16); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(77, 20); + this.labelName.TabIndex = 6; + this.labelName.Text = "Название"; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(104, 51); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(114, 27); + this.textBoxPrice.TabIndex = 3; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(104, 13); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 27); + this.textBoxName.TabIndex = 4; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(815, 642); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(86, 31); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(698, 642); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 31); + this.buttonSave.TabIndex = 9; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormComputer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(907, 686); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Name = "FormComputer"; + this.Text = "Изделие"; + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ManufactureId; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Label labelPrice; + private Label labelName; + private TextBox textBoxPrice; + private TextBox textBoxName; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputer.cs b/ComputersShop/ComputersShop/FormComputer.cs new file mode 100644 index 0000000..d13092f --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputer.cs @@ -0,0 +1,198 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +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 FormComputer_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/ComputersShop/FormComputer.resx b/ComputersShop/ComputersShop/FormComputer.resx new file mode 100644 index 0000000..da9bcdf --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputer.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs b/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs new file mode 100644 index 0000000..3a283f3 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputerComponent.Designer.cs @@ -0,0 +1,126 @@ +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.labelCount = new System.Windows.Forms.Label(); + this.labelComponent = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 56); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 8; + this.labelCount.Text = "Количество"; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(10, 17); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(88, 20); + this.labelComponent.TabIndex = 9; + this.labelComponent.Text = "Компонент"; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(277, 92); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(86, 31); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(164, 92); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(106, 31); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(106, 53); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(257, 27); + this.textBoxCount.TabIndex = 5; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(106, 14); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(257, 28); + this.comboBoxComponent.TabIndex = 4; + // + // FormComputerComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(381, 136); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Name = "FormComputerComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelCount; + private Label labelComponent; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputerComponent.cs b/ComputersShop/ComputersShop/FormComputerComponent.cs new file mode 100644 index 0000000..93d6317 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputerComponent.cs @@ -0,0 +1,78 @@ +using ComputersShopContracts.BusinessLogicsContracts; +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/ComputersShop/FormComputerComponent.resx b/ComputersShop/ComputersShop/FormComputerComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShop/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/ComputersShop/FormComputers.Designer.cs b/ComputersShop/ComputersShop/FormComputers.Designer.cs new file mode 100644 index 0000000..81b4a6e --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputers.Designer.cs @@ -0,0 +1,121 @@ +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() + { + System.Windows.Forms.Button buttonRef; + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + buttonRef.Location = new System.Drawing.Point(639, 124); + buttonRef.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new System.Drawing.Size(159, 31); + buttonRef.TabIndex = 7; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(639, 85); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(159, 31); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(639, 47); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(159, 31); + this.buttonUpd.TabIndex = 9; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(639, 8); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(159, 31); + this.buttonAdd.TabIndex = 10; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(3, -2); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(630, 735); + this.dataGridView.TabIndex = 6; + // + // FormComputers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 731); + this.Controls.Add(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 Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormComputers.cs b/ComputersShop/ComputersShop/FormComputers.cs new file mode 100644 index 0000000..10783e7 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputers.cs @@ -0,0 +1,96 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +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("Загрузка компьютеров"); + } + 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(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("Удаление компьютера"); + try + { + if (!_logic.Delete(new ComputerBindingModel { 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/ComputersShop/FormComputers.resx b/ComputersShop/ComputersShop/FormComputers.resx new file mode 100644 index 0000000..fa1d9b6 --- /dev/null +++ b/ComputersShop/ComputersShop/FormComputers.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 + + + False + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormCreateOrder.Designer.cs b/ComputersShop/ComputersShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..b9715e2 --- /dev/null +++ b/ComputersShop/ComputersShop/FormCreateOrder.Designer.cs @@ -0,0 +1,154 @@ +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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelSum = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelComputer = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxComputer = new System.Windows.Forms.ComboBox(); + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(289, 126); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(86, 31); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(180, 126); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(103, 31); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(14, 94); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(55, 20); + this.labelSum.TabIndex = 8; + this.labelSum.Text = "Сумма"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(14, 56); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 9; + this.labelCount.Text = "Количество"; + // + // labelComputer + // + this.labelComputer.AutoSize = true; + this.labelComputer.Location = new System.Drawing.Point(14, 17); + this.labelComputer.Name = "labelComputer"; + this.labelComputer.Size = new System.Drawing.Size(68, 20); + this.labelComputer.TabIndex = 10; + this.labelComputer.Text = "Изделие"; + // + // textBoxSum + // + this.textBoxSum.Enabled = false; + this.textBoxSum.Location = new System.Drawing.Point(122, 90); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(255, 27); + this.textBoxSum.TabIndex = 7; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(122, 52); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(255, 27); + this.textBoxCount.TabIndex = 6; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // comboBoxComputer + // + this.comboBoxComputer.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComputer.FormattingEnabled = true; + this.comboBoxComputer.Location = new System.Drawing.Point(122, 13); + this.comboBoxComputer.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxComputer.Name = "comboBoxComputer"; + this.comboBoxComputer.Size = new System.Drawing.Size(255, 28); + this.comboBoxComputer.TabIndex = 5; + this.comboBoxComputer.SelectedIndexChanged += new System.EventHandler(this.ComboBoxComputer_SelectedIndexChanged); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(387, 170); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComputer); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComputer); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label labelSum; + private Label labelCount; + private Label labelComputer; + private TextBox textBoxSum; + private TextBox textBoxCount; + private ComboBox comboBoxComputer; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormCreateOrder.cs b/ComputersShop/ComputersShop/FormCreateOrder.cs new file mode 100644 index 0000000..1526b61 --- /dev/null +++ b/ComputersShop/ComputersShop/FormCreateOrder.cs @@ -0,0 +1,103 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +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("Загрузка изделий для заказа"); + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxComputer.DisplayMember = "ComputerName"; + comboBoxComputer.ValueMember = "Id"; + comboBoxComputer.DataSource = list; + comboBoxComputer.SelectedItem = null; + } + } + 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 + { + int id = Convert.ToInt32(comboBoxComputer.SelectedValue); + int counr = Convert.ToInt32(textBoxCount.Text); + double sum = Convert.ToDouble(textBoxSum.Text); + 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/ComputersShop/FormCreateOrder.resx b/ComputersShop/ComputersShop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShop/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/ComputersShop/FormMain.Designer.cs b/ComputersShop/ComputersShop/FormMain.Designer.cs new file mode 100644 index 0000000..47f36ae --- /dev/null +++ b/ComputersShop/ComputersShop/FormMain.Designer.cs @@ -0,0 +1,188 @@ +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.buttonRef = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.computersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(927, 195); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonRef.Size = new System.Drawing.Size(323, 31); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(928, 156); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonIssuedOrder.Size = new System.Drawing.Size(323, 31); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(927, 117); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonOrderReady.Size = new System.Drawing.Size(323, 31); + this.buttonOrderReady.TabIndex = 6; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(927, 79); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(323, 31); + this.buttonTakeOrderInWork.TabIndex = 7; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(927, 40); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonCreateOrder.Size = new System.Drawing.Size(323, 31); + this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 40); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(909, 608); + this.dataGridView.TabIndex = 3; + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.refbooksToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1256, 28); + this.menuStrip.TabIndex = 9; + this.menuStrip.Text = "menuStrip1"; + // + // refbooksToolStripMenuItem + // + this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.computersToolStripMenuItem}); + this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem"; + this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.refbooksToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.componentsToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // computersToolStripMenuItem + // + this.computersToolStripMenuItem.Name = "computersToolStripMenuItem"; + this.computersToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.computersToolStripMenuItem.Text = "Изделия"; + this.computersToolStripMenuItem.Click += new System.EventHandler(this.ComputersToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1256, 677); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Продажа компьютеров"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonRef; + private Button buttonIssuedOrder; + private Button buttonOrderReady; + private Button buttonTakeOrderInWork; + private Button buttonCreateOrder; + private DataGridView dataGridView; + private MenuStrip menuStrip; + private ToolStripMenuItem refbooksToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem computersToolStripMenuItem; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormMain.cs b/ComputersShop/ComputersShop/FormMain.cs new file mode 100644 index 0000000..2243e47 --- /dev/null +++ b/ComputersShop/ComputersShop/FormMain.cs @@ -0,0 +1,141 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +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() + { + _logger.LogInformation(" "); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ComputerId"].Visible = false; + dataGridView.Columns["ComputerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ComputersToolStripMenuItem_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(); + } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormMain.resx b/ComputersShop/ComputersShop/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/ComputersShop/ComputersShop/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/ComputersShop/Program.cs b/ComputersShop/ComputersShop/Program.cs index 11f1124..ae5cc88 100644 --- a/ComputersShop/ComputersShop/Program.cs +++ b/ComputersShop/ComputersShop/Program.cs @@ -1,22 +1,48 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; +using ComputersShopBusinessLogic; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.StoragesContracts; +using ComputersShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; -namespace ComputersShop +namespace ComputersShopView { internal static class Program { - /// - /// Главная точка входа для приложения. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + // 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/ComputersShop/Properties/AssemblyInfo.cs b/ComputersShop/ComputersShop/Properties/AssemblyInfo.cs deleted file mode 100644 index 8fa6521..0000000 --- a/ComputersShop/ComputersShop/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Общие сведения об этой сборке предоставляются следующим набором -// набора атрибутов. Измените значения этих атрибутов для изменения сведений, -// связанных со сборкой. -[assembly: AssemblyTitle("ComputersShop")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ComputersShop")] -[assembly: AssemblyCopyright("Copyright © 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми -// для компонентов COM. Если необходимо обратиться к типу в этой сборке через -// COM, следует установить атрибут ComVisible в TRUE для этого типа. -[assembly: ComVisible(false)] - -// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM -[assembly: Guid("2bad8746-a1a3-44dd-b546-7f06a7b1dfea")] - -// Сведения о версии сборки состоят из указанных ниже четырех значений: -// -// Основной номер версии -// Дополнительный номер версии -// Номер сборки -// Редакция -// -// Можно задать все значения или принять номера сборки и редакции по умолчанию -// используя "*", как показано ниже: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ComputersShop/ComputersShop/Properties/Resources.Designer.cs b/ComputersShop/ComputersShop/Properties/Resources.Designer.cs deleted file mode 100644 index 2e2c376..0000000 --- a/ComputersShop/ComputersShop/Properties/Resources.Designer.cs +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Этот код создан программным средством. -// Версия среды выполнения: 4.0.30319.42000 -// -// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если -// код создан повторно. -// -//------------------------------------------------------------------------------ - -namespace ComputersShop.Properties -{ - - - /// - /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. - /// - // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder - // класс с помощью таких средств, как ResGen или Visual Studio. - // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen - // с параметром /str или заново постройте свой VS-проект. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ComputersShop.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Переопределяет свойство CurrentUICulture текущего потока для всех - /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/ComputersShop/ComputersShop/Properties/Resources.resx b/ComputersShop/ComputersShop/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/ComputersShop/ComputersShop/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Properties/Settings.Designer.cs b/ComputersShop/ComputersShop/Properties/Settings.Designer.cs deleted file mode 100644 index d7236e7..0000000 --- a/ComputersShop/ComputersShop/Properties/Settings.Designer.cs +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace ComputersShop.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/ComputersShop/ComputersShop/Properties/Settings.settings b/ComputersShop/ComputersShop/Properties/Settings.settings deleted file mode 100644 index 3964565..0000000 --- a/ComputersShop/ComputersShop/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/ComputersShop/ComputersShop/nlog.config b/ComputersShop/ComputersShop/nlog.config new file mode 100644 index 0000000..77b13bf --- /dev/null +++ b/ComputersShop/ComputersShop/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopBusinessLogic/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..826022d --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComponentLogic.cs @@ -0,0 +1,109 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + + +namespace ComputersShopBusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id} ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/ComputerLogic.cs new file mode 100644 index 0000000..8852003 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComputerLogic.cs @@ -0,0 +1,108 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic +{ + 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.GetFilteredList(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}.Price:{ Price}. 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/ComputersShopBusinessLogic.csproj b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj new file mode 100644 index 0000000..96b7a1b --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopBusinessLogic/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..f8a67b7 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/OrderLogic.cs @@ -0,0 +1,114 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Update operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ComputerId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.ComputerId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество компьютеров в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + //_logger.LogInformation("Computer. OrderID:{Id}. Sum:{Sum}. ComputerID:{ComputerID}.}", model.Id, model.Sum, model.ComputerId); + } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..9bf2a8b --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,12 @@ +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..8a59ab0 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs @@ -0,0 +1,12 @@ +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(); + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..a31006b --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +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; } + } +} diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..bd57d7d --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs new file mode 100644 index 0000000..5ed19ac --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs @@ -0,0 +1,15 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IComputerLogic + { + List? ReadList(ComputerSearchModel? model); + ComputerViewModel? ReadElement(ComputerSearchModel model); + bool Create(ComputerBindingModel model); + bool Update(ComputerBindingModel model); + bool Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..69b5886 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + + } +} diff --git a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj new file mode 100644 index 0000000..9c95599 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..cdea093 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +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..c9a082a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs @@ -0,0 +1,8 @@ +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..3b3d9f6 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +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..2014891 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs new file mode 100644 index 0000000..dda93bd --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComputerStorage + { + List GetFullList(); + List GetFilteredList(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..512bb9d --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..c135f61 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,15 @@ +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..3432e0c --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs @@ -0,0 +1,15 @@ +using ComputersShopDataModels.Models; +using System.ComponentModel; + +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(); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..a8c5cbd --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; +using System.ComponentModel; + +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; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/ComputersShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs b/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..348af9b --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace ComputersShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopDataModels/IId.cs b/ComputersShop/ComputersShopDataModels/IId.cs new file mode 100644 index 0000000..00436fb --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IId.cs @@ -0,0 +1,8 @@ +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..4703953 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +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..31d4507 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs @@ -0,0 +1,9 @@ +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..518eb9a --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +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; } + } +} diff --git a/ComputersShop/ComputersShopImplement/ComputersShopListImplement.csproj b/ComputersShop/ComputersShopImplement/ComputersShopListImplement.csproj new file mode 100644 index 0000000..8eb14fb --- /dev/null +++ b/ComputersShop/ComputersShopImplement/ComputersShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/ComputersShop/ComputersShopImplement/DataListSingleton.cs b/ComputersShop/ComputersShopImplement/DataListSingleton.cs new file mode 100644 index 0000000..1b0012b --- /dev/null +++ b/ComputersShop/ComputersShopImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement +{ + 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/ComputersShopImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..9e0b458 --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Implements/ComponentStorage.cs @@ -0,0 +1,104 @@ +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 GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopImplement/Implements/ComputerStorage.cs new file mode 100644 index 0000000..0a4a9e3 --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Implements/ComputerStorage.cs @@ -0,0 +1,100 @@ +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 GetFilteredList(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/ComputersShopImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..e9c9596 --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Implements/OrderStorage.cs @@ -0,0 +1,112 @@ +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) + { + OrderViewModel thisorder = order.GetViewModel; + Computer? computer = _source.Computers.Find(x => x.Id == order.ComputerId); + string computerName = computer?.ComputerName ?? string.Empty; + thisorder.ComputerName = computerName; + result.Add(thisorder); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + OrderViewModel thisorder = order.GetViewModel; + Computer? computer = _source.Computers.Find(x => x.Id == order.ComputerId); + string computerName = computer?.ComputerName ?? string.Empty; + thisorder.ComputerName = computerName; + result.Add(thisorder); + } + } + 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)) + { + OrderViewModel thisorder = order.GetViewModel; + Computer? computer = _source.Computers.Find(x => x.Id == order.ComputerId); + string computerName = computer?.ComputerName ?? string.Empty; + thisorder.ComputerName = computerName; + return thisorder; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Computers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopImplement/Models/Component.cs b/ComputersShop/ComputersShopImplement/Models/Component.cs new file mode 100644 index 0000000..4d8a13a --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Models/Component.cs @@ -0,0 +1,41 @@ +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 + }; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopImplement/Models/Computer.cs b/ComputersShop/ComputersShopImplement/Models/Computer.cs new file mode 100644 index 0000000..b5076fd --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Models/Computer.cs @@ -0,0 +1,49 @@ +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/ComputersShopImplement/Models/Order.cs b/ComputersShop/ComputersShopImplement/Models/Order.cs new file mode 100644 index 0000000..1a3f382 --- /dev/null +++ b/ComputersShop/ComputersShopImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; + +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; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; 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; + } + Status = model.Status; + if (model.DateImplement != null) + { + DateImplement = model.DateImplement; + } + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ComputerId = ComputerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +}