From 84ae8be0ee4238131feeb6d5bcda1e87bb8d406d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 14 Feb 2023 23:28:49 +0400 Subject: [PATCH 01/13] =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 26 +- .../BlacksmithWorkshop.csproj | 11 - .../BlacksmithWorkshopView.csproj | 22 ++ .../BlacksmithWorkshop/Form1.Designer.cs | 39 --- .../BlacksmithWorkshop/Form1.cs | 10 - .../BlacksmithWorkshop/Form1.resx | 120 --------- .../FormComponent.Designer.cs | 121 +++++++++ .../BlacksmithWorkshop/FormComponent.cs | 82 +++++++ .../BlacksmithWorkshop/FormComponent.resx | 60 +++++ .../FormComponents.Designer.cs | 115 +++++++++ .../BlacksmithWorkshop/FormComponents.cs | 100 ++++++++ .../BlacksmithWorkshop/FormComponents.resx | 63 +++++ .../FormCreateOrder.Designer.cs | 148 +++++++++++ .../BlacksmithWorkshop/FormCreateOrder.cs | 105 ++++++++ .../BlacksmithWorkshop/FormCreateOrder.resx | 60 +++++ .../BlacksmithWorkshop/FormMain.Designer.cs | 180 ++++++++++++++ .../BlacksmithWorkshop/FormMain.cs | 149 ++++++++++++ .../BlacksmithWorkshop/FormMain.resx | 63 +++++ .../FormManufacture.Designer.cs | 229 ++++++++++++++++++ .../BlacksmithWorkshop/FormManufacture.cs | 208 ++++++++++++++++ .../BlacksmithWorkshop/FormManufacture.resx | 69 ++++++ .../FormManufactureComponent.Designer.cs | 122 ++++++++++ .../FormManufactureComponent.cs | 78 ++++++ .../FormManufactureComponent.resx | 60 +++++ .../FormManufactures.Designer.cs | 115 +++++++++ .../BlacksmithWorkshop/FormManufactures.cs | 101 ++++++++ .../BlacksmithWorkshop/FormManufactures.resx | 63 +++++ .../BlacksmithWorkshop/Program.cs | 42 +++- .../BlacksmithWorkshopBusinessLogic.csproj | 17 ++ .../BusinessLogics/ComponentLogic.cs | 107 ++++++++ .../BusinessLogics/ManufactureLogic.cs | 107 ++++++++ .../BusinessLogics/OrderLogic.cs | 142 +++++++++++ .../BindingModels/ComponentBindingModel.cs | 11 + .../BindingModels/ManufactureBindingModel.cs | 12 + .../BindingModels/OrderBindingModel.cs | 16 ++ .../BlacksmithWorkshopContracts.csproj | 13 + .../IComponentLogic.cs | 15 ++ .../IManufactureLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/ManufactureSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 16 ++ .../StoragesContracts/IManufactureStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/ManufactureViewModel.cs | 15 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../BlacksmithWorkshopDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 11 + .../BlacksmithWorkshopDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 8 + .../Models/IManufactureModel.cs | 9 + .../Models/IOrderModel.cs | 14 ++ .../BlacksmithWorkshopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 26 ++ .../Implements/ComponentStorage.cs | 100 ++++++++ .../Implements/ManufactureStorage.cs | 100 ++++++++ .../Implements/OrderStorage.cs | 100 ++++++++ .../Models/Component.cs | 41 ++++ .../Models/Manufacture.cs | 45 ++++ .../Models/Order.cs | 67 +++++ 62 files changed, 3521 insertions(+), 186 deletions(-) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ComponentStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index ce3b039..57e91a7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{3C0DDC74-314C-4940-94A4-09A677B02BEF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopView", "BlacksmithWorkshop\BlacksmithWorkshopView.csproj", "{3C0DDC74-314C-4940-94A4-09A677B02BEF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{D2562E41-4F78-446C-9794-98FB6DDCE6BB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{CDACDBC7-673D-4A8F-8B1D-AAA2A8468628}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{1FAF13A8-1967-44CE-BA00-CC202A84C914}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{D57FFF62-0A87-4995-9693-317A94689469}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {3C0DDC74-314C-4940-94A4-09A677B02BEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C0DDC74-314C-4940-94A4-09A677B02BEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {3C0DDC74-314C-4940-94A4-09A677B02BEF}.Release|Any CPU.Build.0 = Release|Any CPU + {D2562E41-4F78-446C-9794-98FB6DDCE6BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D2562E41-4F78-446C-9794-98FB6DDCE6BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D2562E41-4F78-446C-9794-98FB6DDCE6BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D2562E41-4F78-446C-9794-98FB6DDCE6BB}.Release|Any CPU.Build.0 = Release|Any CPU + {CDACDBC7-673D-4A8F-8B1D-AAA2A8468628}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CDACDBC7-673D-4A8F-8B1D-AAA2A8468628}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CDACDBC7-673D-4A8F-8B1D-AAA2A8468628}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CDACDBC7-673D-4A8F-8B1D-AAA2A8468628}.Release|Any CPU.Build.0 = Release|Any CPU + {1FAF13A8-1967-44CE-BA00-CC202A84C914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FAF13A8-1967-44CE-BA00-CC202A84C914}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FAF13A8-1967-44CE-BA00-CC202A84C914}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FAF13A8-1967-44CE-BA00-CC202A84C914}.Release|Any CPU.Build.0 = Release|Any CPU + {D57FFF62-0A87-4995-9693-317A94689469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D57FFF62-0A87-4995-9693-317A94689469}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D57FFF62-0A87-4995-9693-317A94689469}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D57FFF62-0A87-4995-9693-317A94689469}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj deleted file mode 100644 index b57c89e..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj new file mode 100644 index 0000000..8bd3034 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs deleted file mode 100644 index 6d3391d..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace BlacksmithWorkshop -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs deleted file mode 100644 index 6c3de35..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace BlacksmithWorkshop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.Designer.cs new file mode 100644 index 0000000..09997f0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.Designer.cs @@ -0,0 +1,121 @@ +namespace BlacksmithWorkshopView +{ + 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.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormComponent_Load); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(89, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(218, 23); + this.textBoxName.TabIndex = 0; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(24, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Название"; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(89, 41); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(90, 23); + this.textBoxCost.TabIndex = 0; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(24, 44); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена"; + // + // 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(151, 73); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 2; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(232, 73); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 2; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(381, 119); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private Label labelName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs new file mode 100644 index 0000000..bdb6fad --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs @@ -0,0 +1,82 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.Designer.cs new file mode 100644 index 0000000..39f0aea --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace BlacksmithWorkshopView +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormComponents_Load); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(608, 450); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(614, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(174, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(614, 41); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(174, 23); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(614, 70); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(174, 23); + this.buttonDel.TabIndex = 1; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + buttonRef.Location = new System.Drawing.Point(614, 99); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new System.Drawing.Size(174, 23); + buttonRef.TabIndex = 1; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + 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 = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs new file mode 100644 index 0000000..bc95a2c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs @@ -0,0 +1,100 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.resx new file mode 100644 index 0000000..fa1d9b6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..7fc5dfd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -0,0 +1,148 @@ +namespace BlacksmithWorkshopView +{ + 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.comboBoxManufacture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.labelManufacture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + // + // comboBoxManufacture + // + this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxManufacture.FormattingEnabled = true; + this.comboBoxManufacture.Location = new System.Drawing.Point(113, 12); + this.comboBoxManufacture.Name = "comboBoxManufacture"; + this.comboBoxManufacture.Size = new System.Drawing.Size(224, 23); + this.comboBoxManufacture.TabIndex = 0; + this.comboBoxManufacture.SelectedIndexChanged += new System.EventHandler(this.ComboBoxManufacture_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(113, 41); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(224, 23); + this.textBoxCount.TabIndex = 1; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Enabled = false; + this.textBoxSum.Location = new System.Drawing.Point(113, 70); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(224, 23); + this.textBoxSum.TabIndex = 2; + // + // labelManufacture + // + this.labelManufacture.AutoSize = true; + this.labelManufacture.Location = new System.Drawing.Point(18, 15); + this.labelManufacture.Name = "labelManufacture"; + this.labelManufacture.Size = new System.Drawing.Size(53, 15); + this.labelManufacture.TabIndex = 3; + this.labelManufacture.Text = "Изделие"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(18, 44); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(18, 73); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(45, 15); + this.labelSum.TabIndex = 3; + this.labelSum.Text = "Сумма"; + // + // 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(181, 99); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(262, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(387, 153); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelManufacture); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxManufacture); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxManufacture; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Label labelManufacture; + private Label labelCount; + private Label labelSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs new file mode 100644 index 0000000..6ab8b42 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -0,0 +1,105 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logicM; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IManufactureLogic logicM, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicM = logicM; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + var list = _logicM.ReadList(null); + if (list != null) + { + comboBoxManufacture.DisplayMember = "ManufactureName"; + comboBoxManufacture.ValueMember = "Id"; + comboBoxManufacture.DataSource = list; + comboBoxManufacture.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxManufacture.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); + var manufacture = _logicM.ReadElement(new ManufactureSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (manufacture?.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 ComboBoxManufacture_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 (comboBoxManufacture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ManufactureId = Convert.ToInt32(comboBoxManufacture.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/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs new file mode 100644 index 0000000..747545a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -0,0 +1,180 @@ +namespace BlacksmithWorkshopView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + this.Load += new System.EventHandler(this.FormMain_Load); + // + // menuStrip + // + 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(1108, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // refbooksToolStripMenuItem + // + this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.manufacturesToolStripMenuItem}); + this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem"; + this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.refbooksToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.componentsToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // manufacturesToolStripMenuItem + // + this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem"; + this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.manufacturesToolStripMenuItem.Text = "Изделия"; + this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_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, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(795, 456); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(813, 27); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(813, 56); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23); + this.buttonTakeOrderInWork.TabIndex = 2; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(813, 85); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonOrderReady.Size = new System.Drawing.Size(283, 23); + this.buttonOrderReady.TabIndex = 2; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(814, 114); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23); + this.buttonIssuedOrder.TabIndex = 2; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(813, 143); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.buttonRef.Size = new System.Drawing.Size(283, 23); + this.buttonRef.TabIndex = 2; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1108, 504); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Кузнечная мастерская"; + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem refbooksToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem manufacturesToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs new file mode 100644 index 0000000..84ccd87 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -0,0 +1,149 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + 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["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].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 ManufacturesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + if (service is FormManufactures form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs new file mode 100644 index 0000000..3d8e71c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs @@ -0,0 +1,229 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufacture + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(94, 20); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(210, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(94, 49); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(100, 23); + this.textBoxPrice.TabIndex = 0; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 28); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Название"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 57); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(67, 15); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость"; + // + // 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(12, 78); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Size = new System.Drawing.Size(776, 410); + this.groupBoxComponents.TabIndex = 2; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(621, 109); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(149, 23); + 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(621, 80); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(149, 23); + 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(621, 51); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(149, 23); + 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(621, 22); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(149, 23); + 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(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(609, 382); + this.dataGridView.TabIndex = 0; + // + // ManufactureId + // + this.ManufactureId.HeaderText = "Id"; + this.ManufactureId.Name = "ManufactureId"; + this.ManufactureId.Visible = false; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Компонент"; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // 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(632, 509); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 3; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(713, 509); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormManufacture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 544); + 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 = "FormManufacture"; + this.Text = "Изделие"; + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxPrice; + private Label labelName; + private Label labelPrice; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ManufactureId; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs new file mode 100644 index 0000000..49e4db0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -0,0 +1,208 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufacture : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logic; + private int? _id; + private Dictionary _manufactureComponents; + public int Id { set { _id = value; } } + public FormManufacture(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _manufactureComponents = new Dictionary(); + } + private void FormManufacture_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ManufactureSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ManufactureName; + textBoxPrice.Text = view.Price.ToString(); + _manufactureComponents = view.ManufactureComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_manufactureComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var mc in _manufactureComponents) + { + dataGridView.Rows.Add(new object[] { mc.Key, mc.Value.Item1.ComponentName, mc.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(FormManufactureComponent)); + if (service is FormManufactureComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_manufactureComponents.ContainsKey(form.Id)) + { + _manufactureComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _manufactureComponents.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(FormManufactureComponent)); + if (service is FormManufactureComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _manufactureComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + _manufactureComponents[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); + _manufactureComponents?.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 (_manufactureComponents == null || _manufactureComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ManufactureBindingModel + { + Id = _id ?? 0, + ManufactureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ManufactureComponents = _manufactureComponents + }; + 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 _manufactureComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx new file mode 100644 index 0000000..1059cc4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.Designer.cs new file mode 100644 index 0000000..928ef81 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.Designer.cs @@ -0,0 +1,122 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufactureComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(100, 25); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(225, 23); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(100, 54); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(225, 23); + this.textBoxCount.TabIndex = 1; + // + // 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(170, 86); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 2; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // 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(251, 86); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 2; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(22, 28); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(69, 15); + this.labelComponent.TabIndex = 3; + this.labelComponent.Text = "Компонент"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(22, 57); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество"; + // + // FormManufactureComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(338, 121); + 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 = "FormManufactureComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label labelComponent; + private Label labelCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs new file mode 100644 index 0000000..b4c44df --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs @@ -0,0 +1,78 @@ +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufactureComponent : 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 FormManufactureComponent(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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs new file mode 100644 index 0000000..d2f357f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs @@ -0,0 +1,115 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufactures + { + /// + /// 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(620, 99); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new System.Drawing.Size(174, 23); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(620, 70); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(174, 23); + this.buttonDel.TabIndex = 4; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(620, 41); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(174, 23); + this.buttonUpd.TabIndex = 5; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(620, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(174, 23); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(6, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(608, 450); + this.dataGridView.TabIndex = 2; + // + // FormManufactures + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + 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 = "FormManufactures"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormManufactures_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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs new file mode 100644 index 0000000..8b83db6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufactures : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logic; + public FormManufactures(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormManufactures_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["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ManufactureComponents"].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(FormManufacture)); + if (service is FormManufacture 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(FormManufacture)); + if (service is FormManufacture 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 ManufactureBindingModel + { + 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/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx new file mode 100644 index 0000000..fa1d9b6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 1d7fc1e..8716cd5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,17 +1,49 @@ -namespace BlacksmithWorkshop +using BlacksmithWorkShopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopListImplement.Implements; +using BlacksmithWorkshopView; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace BlacksmithWorkshopView { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; [STAThread] static void Main() { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj new file mode 100644 index 0000000..82a5881 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..4ac858e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,107 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("Readlist. ComponentName: {ComponentName}. Id: {Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("Readlist. Count: {Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel? model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName= model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs new file mode 100644 index 0000000..4a1360b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs @@ -0,0 +1,107 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkShopBusinessLogic.BusinessLogics +{ + public class ManufactureLogic : IManufactureLogic + { + private readonly ILogger _logger; + private readonly IManufactureStorage _manufactureStorage; + public ManufactureLogic(ILogger logger, IManufactureStorage manufactureStorage) + { + _logger = logger; + _manufactureStorage = manufactureStorage; + } + public List? ReadList(ManufactureSearchModel? model) + { + _logger.LogInformation("Readlist. ManufactureName: {ManufactureName}. Id: {Id}", model?.ManufactureName, model?.Id); + var list = model == null ? _manufactureStorage.GetFullList() : _manufactureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("Readlist. Count: {Count}", list.Count); + return list; + } + public ManufactureViewModel? ReadElement(ManufactureSearchModel? model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ManufactureName: {ManufactureName}. Id: {Id}", model.ManufactureName, model.Id); + var element = _manufactureStorage.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(ManufactureBindingModel model) + { + CheckModel(model); + if (_manufactureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ManufactureBindingModel model) + { + CheckModel(model); + if (_manufactureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ManufactureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_manufactureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ManufactureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ManufactureName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.ManufactureName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Manufacture. ManufactureName: {ManufactureName}. Price: {Price}. Id: {Id}", model.ManufactureName, model.Price, model.Id); + var element = _manufactureStorage.GetElement(new ManufactureSearchModel + { + ManufactureName = model.ManufactureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..10ce8dc --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,142 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkShopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Readlist. Id: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("Readlist. Count: {Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if ((int)model.Status > -2) + { + model.Status = OrderStatus.Принят; + } + else + { + _logger.LogWarning("Create order operation failed"); + return false; + } + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Create order operation failed"); + return false; + } + model.Status = OrderStatus.Принят; + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + if ((int)model.Status > -1 || _orderStorage.UpdateOrderStatus(model) == null) + { + return true; + } + else + { + _logger.LogWarning("Take order in work operation failed"); + return false; + } + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Take order in work operation failed"); + return false; + } + model.Status = OrderStatus.Выполняется; + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + if ((int)model.Status > 0) + { + model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; + } + else + { + _logger.LogWarning("Finish order operation failed"); + return false; + } + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Finish order operation failed"); + return false; + } + model.Status = OrderStatus.Готов; + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model); + if ((int)model.Status > 1) + { + model.Status = OrderStatus.Выдан; + } + else + { + _logger.LogWarning("Delivery order operation failed"); + return false; + } + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Delivery order operation failed"); + return false; + } + model.Status = OrderStatus.Выдан; + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким ID уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..c914ef1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs new file mode 100644 index 0000000..b724106 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs @@ -0,0 +1,12 @@ +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ManufactureBindingModel : IManufactureModel + { + public int Id { get; set; } + public string ManufactureName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ManufactureComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..ae0aeb4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ManufactureId { 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj new file mode 100644 index 0000000..f685e06 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BlacksmithWorkshopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..156c055 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.BusinessLogicContracts +{ + 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs new file mode 100644 index 0000000..13b7395 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -0,0 +1,15 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.BusinessLogicContracts +{ + public interface IManufactureLogic + { + List? ReadList(ManufactureSearchModel? model); + ManufactureViewModel? ReadElement(ManufactureSearchModel model); + bool Create(ManufactureBindingModel model); + bool Update(ManufactureBindingModel model); + bool Delete(ManufactureBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..47b6ca0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.BusinessLogicContracts +{ + 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..26a764c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs new file mode 100644 index 0000000..75c45c0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs @@ -0,0 +1,8 @@ +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ManufactureSearchModel + { + public int? Id { get; set; } + public string? ManufactureName { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..399b8c6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..f0236ca --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs new file mode 100644 index 0000000..eaeedb7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + public interface IManufactureStorage + { + List GetFullList(); + List GetFilteredList(ManufactureSearchModel model); + ManufactureViewModel? GetElement(ManufactureSearchModel model); + ManufactureViewModel? Insert(ManufactureBindingModel model); + ManufactureViewModel? Update(ManufactureBindingModel model); + ManufactureViewModel? Delete(ManufactureBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..fd915a1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..2f2049f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs new file mode 100644 index 0000000..25732a6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs @@ -0,0 +1,15 @@ +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ManufactureViewModel : IManufactureModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ManufactureName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ManufactureComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..05da722 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System.ComponentModel; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ManufactureId { get; set; } + [DisplayName("Изделие")] + public string ManufactureName { 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/BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/BlacksmithWorkshopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..652e114 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace BlacksmithWorkshopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs new file mode 100644 index 0000000..298cf59 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace BlacksmithWorkshopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..43fce65 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs new file mode 100644 index 0000000..7249c78 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs @@ -0,0 +1,9 @@ +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IManufactureModel : IId + { + string ManufactureName { get; } + double Price { get; } + Dictionary ManufactureComponents { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..4fe770d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using BlacksmithWorkshopDataModels.Enums; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IOrderModel : IId + { + int ManufactureId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj new file mode 100644 index 0000000..b65badc --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/BlacksmithWorkshopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..eb26022 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Manufactures { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Manufactures = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..b135ad2 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,100 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if (!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName || model.Id.HasValue && component.Id == model.Id) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; i++) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..7b02df4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,100 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ManufactureStorage : IManufactureStorage + { + private readonly DataListSingleton _source; + public ManufactureStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var manufacture in _source.Manufactures) + { + result.Add(manufacture.GetViewModel); + } + return result; + } + public List GetFilteredList(ManufactureSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return result; + } + foreach (var manufacture in _source.Manufactures) + { + if (manufacture.ManufactureName.Contains(model.ManufactureName)) + { + result.Add(manufacture.GetViewModel); + } + } + return result; + } + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + foreach (var manufacture in _source.Manufactures) + { + if (!string.IsNullOrEmpty(model.ManufactureName) && manufacture.ManufactureName == model.ManufactureName || model.Id.HasValue && manufacture.Id == model.Id) + { + return manufacture.GetViewModel; + } + } + return null; + } + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = 1; + foreach (var manufacture in _source.Manufactures) + { + if (model.Id <= manufacture.Id) + { + model.Id = manufacture.Id + 1; + } + } + var newManufacture = Manufacture.Create(model); + if (newManufacture == null) + { + return null; + } + _source.Manufactures.Add(newManufacture); + return newManufacture.GetViewModel; + } + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + foreach (var manufacture in _source.Manufactures) + { + if (manufacture.Id == model.Id) + { + manufacture.Update(model); + return manufacture.GetViewModel; + } + } + return null; + } + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + for (int i = 0; i < _source.Manufactures.Count; i++) + { + if (_source.Manufactures[i].Id == model.Id) + { + var element = _source.Manufactures[i]; + _source.Manufactures.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..68e7ece --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,100 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; i++) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs new file mode 100644 index 0000000..e5c5db0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs new file mode 100644 index 0000000..229abc4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs @@ -0,0 +1,45 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Manufacture : IManufactureModel + { + public int Id { get; private set; } + public string ManufactureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ManufactureComponents { get; private set; } = new Dictionary(); + public static Manufacture? Create(ManufactureBindingModel? model) + { + if (model == null) + { + return null; + } + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + ManufactureComponents = model.ManufactureComponents + }; + } + public void Update(ManufactureBindingModel? model) + { + if (model == null) + { + return; + } + ManufactureName = model.ManufactureName; + Price = model.Price; + ManufactureComponents = model.ManufactureComponents; + } + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureComponents = ManufactureComponents + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs new file mode 100644 index 0000000..91747b1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -0,0 +1,67 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System.Diagnostics; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ManufactureId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + ManufactureId = model.ManufactureId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public void UpdateStatus(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} -- 2.25.1 From 7db58413395a939084fd7912e0b666244809831e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 15 Feb 2023 00:03:28 +0400 Subject: [PATCH 02/13] =?UTF-8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 4 +- .../BusinessLogics/OrderLogic.cs | 44 ++++++++----------- .../StoragesContracts/IOrderStorage.cs | 1 + .../Implements/OrderStorage.cs | 12 +++++ .../Models/Order.cs | 1 + 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 84ccd87..6c5dea2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,7 +99,9 @@ namespace BlacksmithWorkshopView try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { Id = id }); + { + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 10ce8dc..039fefd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -51,8 +51,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model); - if ((int)model.Status > -1 || _orderStorage.UpdateOrderStatus(model) == null) + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; + if ((int)model.Status > -1) + { + model.Status = OrderStatus.Выполняется; + } + if (_orderStorage.UpdateOrderStatus(model) != null) { return true; } @@ -61,54 +66,43 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Take order in work operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } - model.Status = OrderStatus.Выполняется; - return true; } public bool FinishOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 0) { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Finish order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Finish order operation failed"); - return false; - } - model.Status = OrderStatus.Готов; - return true; } public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model); + OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; if ((int)model.Status > 1) { model.Status = OrderStatus.Выдан; } + if (_orderStorage.UpdateOrderStatus(model) != null) + { + return true; + } else { _logger.LogWarning("Delivery order operation failed"); return false; } - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } - model.Status = OrderStatus.Выдан; - return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index fd915a1..40f6ee1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); + OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 68e7ece..e8a4b84 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,5 +96,17 @@ namespace BlacksmithWorkshopListImplement.Implements } return null; } + public OrderViewModel? UpdateOrderStatus(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.UpdateStatus(model); + return order.GetViewModel; + } + } + return null; + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 91747b1..20ea5d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -52,6 +52,7 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { -- 2.25.1 From 46c1d78dd92570f6087c6d259269bdc6e18c2413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 15 Feb 2023 00:22:52 +0400 Subject: [PATCH 03/13] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 24 ++++++++++++------- .../Models/Order.cs | 5 +++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 039fefd..3b4e82d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,7 +32,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if ((int)model.Status > -2) + if (model.Status == OrderStatus.Неизвестен) { model.Status = OrderStatus.Принят; } @@ -46,14 +46,16 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Create order operation failed"); return false; } - model.Status = OrderStatus.Принят; return true; } public bool TakeOrderInWork(OrderBindingModel model) { - OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + OrderViewModel? vm = _orderStorage.GetElement(new() + { + Id = model.Id + }); model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if ((int)model.Status > -1) + if (model.Status == OrderStatus.Принят) { model.Status = OrderStatus.Выполняется; } @@ -69,9 +71,12 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } public bool FinishOrder(OrderBindingModel model) { - OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + OrderViewModel? vm = _orderStorage.GetElement(new() + { + Id = model.Id + }); model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if ((int)model.Status > 0) + if (model.Status == OrderStatus.Выполняется) { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; @@ -88,9 +93,12 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } public bool DeliveryOrder(OrderBindingModel model) { - OrderViewModel? vm = _orderStorage.GetElement(new() { Id = model.Id }); + OrderViewModel? vm = _orderStorage.GetElement(new() + { + Id = model.Id + }); model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if ((int)model.Status > 1) + if (model.Status == OrderStatus.Готов) { model.Status = OrderStatus.Выдан; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 20ea5d1..448cbd8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -52,7 +52,10 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; + if (model.DateImplement != null) + { + DateImplement = model.DateImplement; + } } public OrderViewModel GetViewModel => new() { -- 2.25.1 From 6f5175f2c8eacbc124b09f9c6b9e544fb732fcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 15 Feb 2023 00:47:44 +0400 Subject: [PATCH 04/13] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs | 1 + .../BindingModels/OrderBindingModel.cs | 1 + .../BlacksmithWorkshopListImplement/Models/Order.cs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index 6ab8b42..448d54b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -79,6 +79,7 @@ namespace BlacksmithWorkshopView var operationResult = _logicO.CreateOrder(new OrderBindingModel { ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue), + ManufactureName = comboBoxManufacture.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index ae0aeb4..08893aa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -7,6 +7,7 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } public int ManufactureId { get; set; } + public string ManufactureName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 448cbd8..0043ca1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace BlacksmithWorkshopListImplement.Models { public int Id { get; private set; } public int ManufactureId { get; private set; } + public string ManufactureName { get; private set; } = string.Empty; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -25,6 +26,7 @@ namespace BlacksmithWorkshopListImplement.Models { Id = model.Id, ManufactureId = model.ManufactureId, + ManufactureName = model.ManufactureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -61,6 +63,7 @@ namespace BlacksmithWorkshopListImplement.Models { Id = Id, ManufactureId = ManufactureId, + ManufactureName = ManufactureName, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From dc78b899fd9aa882bd5d9ec5eec7c17fe11a0a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 00:27:49 +0400 Subject: [PATCH 05/13] =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormComponents.cs | 5 ++-- .../BlacksmithWorkshop/FormCreateOrder.cs | 5 ++-- .../BlacksmithWorkshop/FormMain.cs | 5 ++-- .../BlacksmithWorkshop/FormManufacture.cs | 26 +++++++------------ .../FormManufactureComponent.cs | 2 +- .../BlacksmithWorkshop/FormManufactures.cs | 5 ++-- .../BlacksmithWorkshop/nlog.config | 15 +++++++++++ .../BusinessLogics/ComponentLogic.cs | 2 +- .../BusinessLogics/ManufactureLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 2 +- .../BindingModels/ComponentBindingModel.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 2 +- .../IComponentLogic.cs | 2 +- .../IManufactureLogic.cs | 2 +- .../BusinessLogicsContracts/IOrderLogic.cs | 2 +- .../SearchModels/ComponentSearchModel.cs | 2 +- .../SearchModels/ManufactureSearchModel.cs | 2 +- .../SearchModels/OrderSearchModel.cs | 2 +- .../StoragesContracts/IComponentStorage.cs | 2 +- .../StoragesContracts/IManufactureStorage.cs | 2 +- .../StoragesContracts/IOrderStorage.cs | 2 +- .../ViewModels/ComponentViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../Enums/OrderStatus.cs | 2 +- .../BlacksmithWorkshopDataModels/IId.cs | 2 +- .../Models/IComponentModel.cs | 2 +- .../Models/IManufactureModel.cs | 2 +- .../Models/IOrderModel.cs | 2 +- .../DataListSingleton.cs | 2 +- .../Models/Component.cs | 2 +- .../Models/Manufacture.cs | 2 +- .../Models/Order.cs | 2 +- 32 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/nlog.config diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs index bc95a2c..4a1561e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponents.cs @@ -67,8 +67,7 @@ namespace BlacksmithWorkshopView { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); @@ -97,4 +96,4 @@ namespace BlacksmithWorkshopView LoadData(); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index 448d54b..68c7562 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -41,8 +41,7 @@ namespace BlacksmithWorkshopView Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (manufacture?.Price ?? 0), - 2).ToString(); + textBoxSum.Text = Math.Round(count * (manufacture?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) @@ -103,4 +102,4 @@ namespace BlacksmithWorkshopView Close(); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 6c5dea2..ad836a4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -138,8 +138,7 @@ namespace BlacksmithWorkshopView catch (Exception ex) { _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -148,4 +147,4 @@ namespace BlacksmithWorkshopView LoadData(); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs index 49e4db0..26db474 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs @@ -35,8 +35,7 @@ namespace BlacksmithWorkshopView { textBoxName.Text = view.ManufactureName; textBoxPrice.Text = view.Price.ToString(); - _manufactureComponents = view.ManufactureComponents ?? new - Dictionary(); + _manufactureComponents = view.ManufactureComponents ?? new Dictionary(); LoadData(); } } @@ -66,8 +65,7 @@ namespace BlacksmithWorkshopView catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки компонент изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ButtonAdd_Click(object sender, EventArgs e) @@ -84,13 +82,11 @@ namespace BlacksmithWorkshopView _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); if (_manufactureComponents.ContainsKey(form.Id)) { - _manufactureComponents[form.Id] = (form.ComponentModel, - form.Count); + _manufactureComponents[form.Id] = (form.ComponentModel, form.Count); } else { - _manufactureComponents.Add(form.Id, (form.ComponentModel, - form.Count)); + _manufactureComponents.Add(form.Id, (form.ComponentModel, form.Count)); } LoadData(); } @@ -133,8 +129,7 @@ namespace BlacksmithWorkshopView } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } @@ -148,20 +143,17 @@ namespace BlacksmithWorkshopView { if (string.IsNullOrEmpty(textBoxName.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxPrice.Text)) { - MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_manufactureComponents == null || _manufactureComponents.Count == 0) { - MessageBox.Show("Заполните компоненты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение изделия"); @@ -205,4 +197,4 @@ namespace BlacksmithWorkshopView return Math.Round(price * 1.1, 2); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs index b4c44df..15c6417 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureComponent.cs @@ -75,4 +75,4 @@ namespace BlacksmithWorkshopView Close(); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs index 8b83db6..429a101 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -68,8 +68,7 @@ namespace BlacksmithWorkshopView { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); @@ -98,4 +97,4 @@ namespace BlacksmithWorkshopView LoadData(); } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config b/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config new file mode 100644 index 0000000..f14c974 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs index 4ac858e..956abb6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -104,4 +104,4 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs index 4a1360b..6617132 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ManufactureLogic.cs @@ -104,4 +104,4 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 3b4e82d..9dcfd5d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -141,4 +141,4 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics } } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs index c914ef1..f7cd977 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -8,4 +8,4 @@ namespace BlacksmithWorkshopContracts.BindingModels public string ComponentName { get; set; } = string.Empty; public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index 08893aa..292a337 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -14,4 +14,4 @@ namespace BlacksmithWorkshopContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs index 156c055..fd237e3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -12,4 +12,4 @@ namespace BlacksmithWorkshopContracts.BusinessLogicContracts bool Update(ComponentBindingModel model); bool Delete(ComponentBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs index 13b7395..ebfa220 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -12,4 +12,4 @@ namespace BlacksmithWorkshopContracts.BusinessLogicContracts bool Update(ManufactureBindingModel model); bool Delete(ManufactureBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index 47b6ca0..b228496 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,4 +12,4 @@ namespace BlacksmithWorkshopContracts.BusinessLogicContracts bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs index 26a764c..68dcb63 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -5,4 +5,4 @@ public int? Id { get; set; } public string? ComponentName { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs index 75c45c0..bc368bc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs @@ -5,4 +5,4 @@ public int? Id { get; set; } public string? ManufactureName { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index 399b8c6..47cdc98 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -4,4 +4,4 @@ { public int? Id { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs index f0236ca..8ec6097 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IComponentStorage.cs @@ -13,4 +13,4 @@ namespace BlacksmithWorkshopContracts.StoragesContracts ComponentViewModel? Update(ComponentBindingModel model); ComponentViewModel? Delete(ComponentBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs index eaeedb7..0305f29 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs @@ -13,4 +13,4 @@ namespace BlacksmithWorkshopContracts.StoragesContracts ManufactureViewModel? Update(ManufactureBindingModel model); ManufactureViewModel? Delete(ManufactureBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index 40f6ee1..3b385e4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -14,4 +14,4 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Delete(OrderBindingModel model); OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs index 2f2049f..945cc46 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -11,4 +11,4 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Цена")] public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 05da722..6108267 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -22,4 +22,4 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs index 652e114..cbdd815 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs @@ -8,4 +8,4 @@ Готов = 2, Выдан = 3 } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs index 298cf59..28fe9b1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/IId.cs @@ -4,4 +4,4 @@ { int Id { get; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs index 43fce65..b66b083 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IComponentModel.cs @@ -5,4 +5,4 @@ string ComponentName { get; } double Cost { get; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs index 7249c78..d54a1ed 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs @@ -6,4 +6,4 @@ double Price { get; } Dictionary ManufactureComponents { get; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 4fe770d..9fe5b82 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -11,4 +11,4 @@ namespace BlacksmithWorkshopDataModels.Models DateTime DateCreate { get; } DateTime? DateImplement { get; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index eb26022..fef796c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -23,4 +23,4 @@ namespace BlacksmithWorkshopListImplement return _instance; } } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs index e5c5db0..d3e9adf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Component.cs @@ -38,4 +38,4 @@ namespace BlacksmithWorkshopListImplement.Models Cost = Cost }; } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs index 229abc4..0c56875 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs @@ -42,4 +42,4 @@ namespace BlacksmithWorkshopListImplement.Models ManufactureComponents = ManufactureComponents }; } -} +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 0043ca1..935da6e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -71,4 +71,4 @@ namespace BlacksmithWorkshopListImplement.Models DateImplement = DateImplement }; } -} +} \ No newline at end of file -- 2.25.1 From 8bee3f079499375bae837113306cfe78dbfa9f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 00:32:51 +0400 Subject: [PATCH 06/13] =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/BlacksmithWorkshopView.csproj | 10 ++++++++++ .../BlacksmithWorkshop/{nlog.config => nlog.config} | 7 +++---- 2 files changed, 13 insertions(+), 4 deletions(-) rename BlacksmithWorkshop/BlacksmithWorkshop/{nlog.config => nlog.config} (62%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj index 8bd3034..197531c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshopView.csproj @@ -8,6 +8,16 @@ enable + + + + + + + Always + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config b/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config similarity index 62% rename from BlacksmithWorkshop/BlacksmithWorkshop/nlog.config rename to BlacksmithWorkshop/BlacksmithWorkshop/nlog.config index f14c974..0ddb3aa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config +++ b/BlacksmithWorkshop/BlacksmithWorkshop/nlog.config @@ -1,9 +1,8 @@ - + - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + autoReload="true" internalLogLevel="Info"> -- 2.25.1 From cdc9aca2034308026c9b8331763fc2bf517f51a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 01:03:20 +0400 Subject: [PATCH 07/13] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=81=D1=82=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=81=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 59 ++++++++----------- .../StoragesContracts/IOrderStorage.cs | 1 - .../Implements/OrderStorage.cs | 12 ---- .../Models/Order.cs | 16 ----- 4 files changed, 23 insertions(+), 65 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 9dcfd5d..b90dd14 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,15 +32,7 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status == OrderStatus.Неизвестен) - { - model.Status = OrderStatus.Принят; - } - else - { - _logger.LogWarning("Create order operation failed"); - return false; - } + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Create order operation failed"); @@ -58,16 +50,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Принят) { model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Take order in work operation failed"); - return false; - } + _logger.LogWarning("Take order in work operation failed"); + return false; } public bool FinishOrder(OrderBindingModel model) { @@ -80,16 +69,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Finish order operation failed"); - return false; - } + _logger.LogWarning("Finish order operation failed"); + return false; } public bool DeliveryOrder(OrderBindingModel model) { @@ -101,16 +87,13 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics if (model.Status == OrderStatus.Готов) { model.Status = OrderStatus.Выдан; + if (_orderStorage.Update(model) != null) + { + return true; + } } - if (_orderStorage.UpdateOrderStatus(model) != null) - { - return true; - } - else - { - _logger.LogWarning("Delivery order operation failed"); - return false; - } + _logger.LogWarning("Delivery order operation failed"); + return false; } private void CheckModel(OrderBindingModel model, bool withParams = true) { @@ -130,6 +113,10 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count)); } + if (model.Status != OrderStatus.Неизвестен) + { + throw new ArgumentException("Заказ не в статусе Неизвестен"); + } _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); var element = _orderStorage.GetElement(new OrderSearchModel { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs index 3b385e4..d6e3ec4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -12,6 +12,5 @@ namespace BlacksmithWorkshopContracts.StoragesContracts OrderViewModel? Insert(OrderBindingModel model); OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); - OrderViewModel? UpdateOrderStatus(OrderBindingModel model); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index e8a4b84..68e7ece 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -96,17 +96,5 @@ namespace BlacksmithWorkshopListImplement.Implements } return null; } - public OrderViewModel? UpdateOrderStatus(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.UpdateStatus(model); - return order.GetViewModel; - } - } - return null; - } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 935da6e..82309c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -40,25 +40,9 @@ namespace BlacksmithWorkshopListImplement.Models { return; } - ManufactureId = model.ManufactureId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } - public void UpdateStatus(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.DateImplement != null) - { - DateImplement = model.DateImplement; - } - } public OrderViewModel GetViewModel => new() { Id = Id, -- 2.25.1 From 8aa9a3b384be2236f4fff61d05f3cf6e9b700de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 01:04:54 +0400 Subject: [PATCH 08/13] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopListImplement/Models/Order.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 82309c9..d71ddd5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -41,7 +41,10 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; + if (model.DateImplement != null) + { + DateImplement = model.DateImplement; + } } public OrderViewModel GetViewModel => new() { -- 2.25.1 From 37c903b6c64ef5dab10e07c3dba6bf51309200ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 01:19:20 +0400 Subject: [PATCH 09/13] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index b90dd14..e1017b4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -32,13 +32,16 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + if (model.Status == OrderStatus.Неизвестен) { - _logger.LogWarning("Create order operation failed"); - return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) != null) + { + return true; + } } - return true; + _logger.LogWarning("Create order operation failed"); + return false; } public bool TakeOrderInWork(OrderBindingModel model) { @@ -113,10 +116,6 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Count)); } - if (model.Status != OrderStatus.Неизвестен) - { - throw new ArgumentException("Заказ не в статусе Неизвестен"); - } _logger.LogInformation("Order. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id); var element = _orderStorage.GetElement(new OrderSearchModel { -- 2.25.1 From f4e845ee60b6de438bdf17fb5e5e10c9d8f019e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 19:25:02 +0400 Subject: [PATCH 10/13] =?UTF-8?q?=D1=83=D0=BF=D1=80=D0=BE=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BC=D0=B5=D0=BD=D1=8B=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index e1017b4..b6ef1fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -29,6 +29,28 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogInformation("Readlist. Count: {Count}", list.Count); return list; } + public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus) + { + OrderViewModel? vm = _orderStorage.GetElement(new() + { + Id = model.Id + }); + model.Status = vm?.Status ?? OrderStatus.Неизвестен; + if ((int)model.Status == (int)newstatus - 1) + { + model.Status = newstatus; + if (newstatus == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + if (_orderStorage.Update(model) != null) + { + return true; + } + } + _logger.LogWarning($"Changing order status of order {model.Id} to {newstatus} failed"); + return false; + } public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -43,61 +65,9 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics _logger.LogWarning("Create order operation failed"); return false; } - public bool TakeOrderInWork(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Принят) - { - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Take order in work operation failed"); - return false; - } - public bool FinishOrder(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Выполняется) - { - model.Status = OrderStatus.Готов; - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Finish order operation failed"); - return false; - } - public bool DeliveryOrder(OrderBindingModel model) - { - OrderViewModel? vm = _orderStorage.GetElement(new() - { - Id = model.Id - }); - model.Status = vm?.Status ?? OrderStatus.Неизвестен; - if (model.Status == OrderStatus.Готов) - { - model.Status = OrderStatus.Выдан; - if (_orderStorage.Update(model) != null) - { - return true; - } - } - _logger.LogWarning("Delivery order operation failed"); - return false; - } + public bool TakeOrderInWork(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выполняется); + public bool FinishOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Готов); + public bool DeliveryOrder(OrderBindingModel model) => SetNewStatus(model, OrderStatus.Выдан); private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) -- 2.25.1 From 311a7a0491c43628ee6d4452be24e11ababf15f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 22:47:16 +0400 Subject: [PATCH 11/13] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D1=8F=20=D0=B2=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs | 1 - .../BindingModels/OrderBindingModel.cs | 1 - .../Implements/OrderStorage.cs | 5 ++++- .../BlacksmithWorkshopListImplement/Models/Order.cs | 3 --- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs index 68c7562..f7444d8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs @@ -78,7 +78,6 @@ namespace BlacksmithWorkshopView var operationResult = _logicO.CreateOrder(new OrderBindingModel { ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue), - ManufactureName = comboBoxManufacture.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs index 292a337..334617b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -7,7 +7,6 @@ namespace BlacksmithWorkshopContracts.BindingModels { public int Id { get; set; } public int ManufactureId { get; set; } - public string ManufactureName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 68e7ece..8cb2fa6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -18,7 +18,10 @@ namespace BlacksmithWorkshopListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.Id); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); } return result; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index d71ddd5..5772867 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -10,7 +10,6 @@ namespace BlacksmithWorkshopListImplement.Models { public int Id { get; private set; } public int ManufactureId { get; private set; } - public string ManufactureName { get; private set; } = string.Empty; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -26,7 +25,6 @@ namespace BlacksmithWorkshopListImplement.Models { Id = model.Id, ManufactureId = model.ManufactureId, - ManufactureName = model.ManufactureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,7 +48,6 @@ namespace BlacksmithWorkshopListImplement.Models { Id = Id, ManufactureId = ManufactureId, - ManufactureName = ManufactureName, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From c58f9e230a5a7a485b302af1bde0ebc98d0a3472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 22:49:36 +0400 Subject: [PATCH 12/13] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20id=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopListImplement/Implements/OrderStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 8cb2fa6..a35e491 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -19,7 +19,7 @@ namespace BlacksmithWorkshopListImplement.Implements foreach (var order in _source.Orders) { OrderViewModel vm = order.GetViewModel; - var manufacture = _source.Manufactures.Find(x => x.Id == order.Id); + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; result.Add(vm); } -- 2.25.1 From 58fb2e9e43db386af473c3ea74625066f51e47c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 17 Feb 2023 22:55:58 +0400 Subject: [PATCH 13/13] =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index a35e491..c57ce1d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -36,7 +36,10 @@ namespace BlacksmithWorkshopListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - result.Add(order.GetViewModel); + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); } } return result; -- 2.25.1