From 75702dfc08298d6d441943adeebea8712fde3d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 11 Feb 2024 17:29:50 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5?= =?UTF-8?q?=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarpentryWorkshop/CarpentryWorkshop.sln | 26 +- .../CarpentryWorkshopView.csproj | 33 +++ .../CarpentryWorkshop/Form1.Designer.cs | 39 --- CarpentryWorkshop/CarpentryWorkshop/Form1.cs | 10 - .../FormComponent.Designer.cs | 127 ++++++++++ .../CarpentryWorkshop/FormComponent.cs | 85 +++++++ .../{Form1.resx => FormComponent.resx} | 0 .../FormComponents.Designer.cs | 120 ++++++++++ .../CarpentryWorkshop/FormComponents.cs | 105 ++++++++ .../CarpentryWorkshop/FormComponents.resx | 120 ++++++++++ .../CarpentryWorkshop/FormWood.Designer.cs | 224 ++++++++++++++++++ .../CarpentryWorkshop/FormWood.cs | 202 ++++++++++++++++ .../CarpentryWorkshop/FormWood.resx | 120 ++++++++++ .../FormWoodComponent.Designer.cs | 119 ++++++++++ .../CarpentryWorkshop/FormWoodComponent.cs | 63 +++++ .../CarpentryWorkshop/FormWoodComponent.resx | 120 ++++++++++ .../CarpentryWorkshop/Program.cs | 36 ++- .../CarpentryWorkshop/nlog.config | 15 ++ .../BusinessLogics/ComponentLogic.cs | 107 +++++++++ .../BusinessLogics/OrderLogic.cs | 130 ++++++++++ .../BusinessLogics/WoodLogic.cs | 107 +++++++++ .../CarpentryWorkshopBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 11 + .../BindingModels/OrderBindingModel.cs | 17 ++ .../BindingModels/WoodBindingModel.cs | 16 ++ .../IComponentLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../BusinessLogicsContracts/IWoodLogic.cs | 15 ++ .../CarpentryWorkshopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/WoodSearchModel.cs | 8 + .../StoragesContracts/IComponentStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../StoragesContracts/IWoodStorage.cs | 16 ++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../ViewModels/WoodViewModel.cs | 19 ++ .../CarpentryWorkshopDataModels.csproj | 9 + .../Enums/OrderStatus.cs | 15 ++ .../CarpentryWorkshopDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 9 + .../Models/IOrderModel.cs | 19 ++ .../Models/IWoodModel.cs | 9 + .../CarpentryWorkshopListImplement.csproj | 14 ++ .../DataListSingleton.cs | 26 ++ .../Implements/ComponentStorage.cs | 101 ++++++++ .../Implements/OrderStorage.cs | 101 ++++++++ .../Implements/WoodStorage.cs | 101 ++++++++ .../Models/Component.cs | 41 ++++ .../Models/Order.cs | 58 +++++ .../Models/Wood.cs | 45 ++++ 52 files changed, 2660 insertions(+), 51 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj delete mode 100644 CarpentryWorkshop/CarpentryWorkshop/Form1.Designer.cs delete mode 100644 CarpentryWorkshop/CarpentryWorkshop/Form1.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs rename CarpentryWorkshop/CarpentryWorkshop/{Form1.resx => FormComponent.resx} (100%) create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormComponents.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWood.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWood.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshop/nlog.config create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs diff --git a/CarpentryWorkshop/CarpentryWorkshop.sln b/CarpentryWorkshop/CarpentryWorkshop.sln index 907fc20..8003ba3 100644 --- a/CarpentryWorkshop/CarpentryWorkshop.sln +++ b/CarpentryWorkshop/CarpentryWorkshop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshop", "CarpentryWorkshop\CarpentryWorkshop.csproj", "{98E796E8-D77E-4A5D-BB64-1C4029C51360}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopView", "CarpentryWorkshop\CarpentryWorkshopView.csproj", "{98E796E8-D77E-4A5D-BB64-1C4029C51360}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopDataModels", "CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj", "{E4AD7D91-C944-486B-891A-32D402EE6AD8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopContracts", "CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj", "{E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopListImplement", "CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj", "{8778E6ED-03D0-4073-B61E-8ED7FF2DC420}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopBusinessLogic", "CarpentryWorkshopBusinessLogic\CarpentryWorkshopBusinessLogic.csproj", "{4D7EFA75-B5DC-4287-A50D-73405118D4A0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {98E796E8-D77E-4A5D-BB64-1C4029C51360}.Debug|Any CPU.Build.0 = Debug|Any CPU {98E796E8-D77E-4A5D-BB64-1C4029C51360}.Release|Any CPU.ActiveCfg = Release|Any CPU {98E796E8-D77E-4A5D-BB64-1C4029C51360}.Release|Any CPU.Build.0 = Release|Any CPU + {E4AD7D91-C944-486B-891A-32D402EE6AD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4AD7D91-C944-486B-891A-32D402EE6AD8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4AD7D91-C944-486B-891A-32D402EE6AD8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4AD7D91-C944-486B-891A-32D402EE6AD8}.Release|Any CPU.Build.0 = Release|Any CPU + {E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1F5F636-7BA7-49CA-AF95-D36D1C55FD0E}.Release|Any CPU.Build.0 = Release|Any CPU + {8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8778E6ED-03D0-4073-B61E-8ED7FF2DC420}.Release|Any CPU.Build.0 = Release|Any CPU + {4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D7EFA75-B5DC-4287-A50D-73405118D4A0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj b/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj new file mode 100644 index 0000000..1bf66cf --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/CarpentryWorkshopView.csproj @@ -0,0 +1,33 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Form1.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/Form1.Designer.cs deleted file mode 100644 index 22e0d5a..0000000 --- a/CarpentryWorkshop/CarpentryWorkshop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CarpentryWorkshop -{ - 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/CarpentryWorkshop/CarpentryWorkshop/Form1.cs b/CarpentryWorkshop/CarpentryWorkshop/Form1.cs deleted file mode 100644 index c75964d..0000000 --- a/CarpentryWorkshop/CarpentryWorkshop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CarpentryWorkshop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs new file mode 100644 index 0000000..41265c4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponent.Designer.cs @@ -0,0 +1,127 @@ +namespace CarpentryWorkshopView +{ + 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + 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.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(257, 71); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(88, 27); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(162, 71); + this.buttonSave.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(88, 27); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(91, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(252, 23); + this.textBoxName.TabIndex = 1; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 10); + this.labelName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(91, 36); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(129, 23); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(14, 39); + this.labelCost.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена:"; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(360, 110); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "FormComponent"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonSave; + private System.Windows.Forms.TextBox textBoxName; + private System.Windows.Forms.Label labelName; + private TextBox textBoxCost; + private Label labelCost; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs b/CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs new file mode 100644 index 0000000..4fe6856 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponent.cs @@ -0,0 +1,85 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + 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/CarpentryWorkshop/CarpentryWorkshop/Form1.resx b/CarpentryWorkshop/CarpentryWorkshop/FormComponent.resx similarity index 100% rename from CarpentryWorkshop/CarpentryWorkshop/Form1.resx rename to CarpentryWorkshop/CarpentryWorkshop/FormComponent.resx diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs new file mode 100644 index 0000000..659028e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs @@ -0,0 +1,120 @@ +namespace CarpentryWorkshopView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(350, 360); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(410, 32); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(410, 70); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(75, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(410, 111); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(75, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(410, 152); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(75, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs new file mode 100644 index 0000000..98cca33 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.cs @@ -0,0 +1,105 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + 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/CarpentryWorkshop/CarpentryWorkshop/FormComponents.resx b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs new file mode 100644 index 0000000..c039c4b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs @@ -0,0 +1,224 @@ +namespace CarpentryWorkshopView +{ + partial class FormWood + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + dataGridView = new DataGridView(); + ButtonRef = new Button(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + ID = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 41); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(94, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(247, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(94, 38); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(100, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridView); + groupBox1.Controls.Add(ButtonRef); + groupBox1.Controls.Add(ButtonDel); + groupBox1.Controls.Add(ButtonUpd); + groupBox1.Controls.Add(ButtonAdd); + groupBox1.Location = new Point(12, 67); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(510, 338); + groupBox1.TabIndex = 4; + groupBox1.TabStop = false; + groupBox1.Text = "Компонент"; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentName, Count }); + dataGridView.Location = new Point(0, 21); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(394, 311); + dataGridView.TabIndex = 5; + // + // ButtonRef + // + ButtonRef.Location = new Point(400, 169); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(106, 28); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(400, 135); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(106, 28); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(400, 101); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(106, 28); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(400, 67); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(106, 28); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(354, 415); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(75, 23); + ButtonSave.TabIndex = 5; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(435, 415); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 6; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // ID + // + ID.HeaderText = "Id"; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 250; + // + // ComponentName + // + ComponentName.HeaderText = "Компонент"; + ComponentName.Name = "ComponentName"; + ComponentName.Width = 250; + // + // Count + // + Count.HeaderText = "Количество"; + Count.Name = "Count"; + // + // FormWood + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(536, 450); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormWood"; + Text = "Создание набора"; + Load += FormWood_Load; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private Button ButtonSave; + private Button ButtonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs new file mode 100644 index 0000000..4facb1c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs @@ -0,0 +1,202 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarpentryWorkshopView +{ + public partial class FormWood : Form + { + private readonly ILogger _logger; + private readonly IWoodLogic _logic; + private int? _id; + private Dictionary _woodComponents; + public int Id { set { _id = value; } } + public FormWood(ILogger logger, IWoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _woodComponents = new Dictionary(); + } + private void FormWood_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new WoodSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.WoodName; + textBoxPrice.Text = view.Price.ToString(); + _woodComponents = view.WoodComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_woodComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _woodComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWoodComponent)); + if (service is FormWoodComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_woodComponents.ContainsKey(form.Id)) + { + _woodComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _woodComponents.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(FormWoodComponent)); + if (service is FormWoodComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _woodComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _woodComponents[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); _woodComponents?.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 (_woodComponents == null || _woodComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new WoodBindingModel + { + Id = _id ?? 0, + WoodName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + WoodComponents = _woodComponents + }; + 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 _woodComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWood.resx b/CarpentryWorkshop/CarpentryWorkshop/FormWood.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs new file mode 100644 index 0000000..e06c6ad --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoodComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + textBoxCount = new TextBox(); + comboBoxComponent = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 37); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 34); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(235, 23); + textBoxCount.TabIndex = 3; + // + // comboBoxComponent + // + comboBoxComponent.BackColor = SystemColors.Window; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(235, 23); + comboBoxComponent.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(248, 63); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(167, 63); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormWoodComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(337, 97); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(comboBoxComponent); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormWoodComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private TextBox textBoxCount; + private ComboBox comboBoxComponent; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs new file mode 100644 index 0000000..a9af5f1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.cs @@ -0,0 +1,63 @@ +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopView +{ + public partial class FormWoodComponent : 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 FormWoodComponent(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/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.resx b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Program.cs b/CarpentryWorkshop/CarpentryWorkshop/Program.cs index 57440dd..837f262 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Program.cs @@ -1,17 +1,51 @@ +using CarpentryWorkshopBusinessLogic.BusinessLogics; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace CarpentryWorkshop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// [STAThread] static void Main() { + // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + // Application.Run(new Form1()); + } + + 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/CarpentryWorkshop/CarpentryWorkshop/nlog.config b/CarpentryWorkshop/CarpentryWorkshop/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..497ae97 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,107 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopBusinessLogic.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("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..1166d01 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,130 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopBusinessLogic.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) + { + _orderStorage.Insert(new OrderBindingModel + { + WoodId = model.WoodId, + WoodName = model.WoodName, + Count = model.Count, + Sum = model.Sum, + Status = OrderStatus.Принят, + DateCreate = DateTime.Now + }); ; + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (order == null) + { + throw new Exception("Элемент не найден"); + } + if (order.Status.ToString() != "Принят") + { + throw new Exception("Заказ не в статусе \"Принят\""); + } + _orderStorage.Update(new OrderBindingModel + { + Id = order.Id, + WoodId = order.WoodId, + WoodName = order.WoodName, + Count = order.Count, + Sum = order.Sum, + DateCreate = order.DateCreate, + + Status = OrderStatus.Выполняется + }); + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (order == null) + { + throw new Exception("Не найден заказ"); + } + if (order.Status.ToString() != "Выполняется") + { + throw new Exception("Заказ не в статусе \"Выполняется\""); + } + _orderStorage.Update(new OrderBindingModel + { + Id = order.Id, + WoodId = order.WoodId, + WoodName = order.WoodName, + Count = order.Count, + Sum = order.Sum, + DateCreate = order.DateCreate, + DateImplement = DateTime.Now, + Status = OrderStatus.Готов + }); + return true; + } + public bool DeliveryOrder(OrderBindingModel model) + { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (order == null) + { + throw new Exception("Не найден заказ"); + } + + if (order.Status.ToString() != "Готов") + { + throw new Exception("Заказ не в статусе \"Готов\""); + } + + _orderStorage.Update(new OrderBindingModel + { + Id = order.Id, + WoodId = order.WoodId, + WoodName = order.WoodName, + Count = order.Count, + Sum = order.Sum, + DateCreate = order.DateCreate, + DateImplement = order.DateImplement, + Status = OrderStatus.Выдан + }); + return true; + + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs new file mode 100644 index 0000000..54b08dc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs @@ -0,0 +1,107 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class WoodLogic : IWoodLogic + { + private readonly ILogger _logger; + private readonly IWoodStorage _woodStorage; + public WoodLogic(ILogger logger, IWoodStorage woodStorage) + { + _logger = logger; + _woodStorage = woodStorage; + } + public List? ReadList(WoodSearchModel? model) + { + _logger.LogInformation("ReadList. WoodName:{WoodName}. Id:{ Id}", model?.WoodName, model?.Id); + var list = model == null ? _woodStorage.GetFullList() : _woodStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public WoodViewModel? ReadElement(WoodSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. WoodName:{WoodName}. Id:{ Id}", model.WoodName, model.Id); + var element = _woodStorage.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(WoodBindingModel model) + { + CheckModel(model); + if (_woodStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WoodBindingModel model) + { + CheckModel(model); + if (_woodStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(WoodBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_woodStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(WoodBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.WoodName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.WoodName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Wood. WoodName:{WoodName}. Cost:{ Cost}. Id: { Id}", model.WoodName, model.Price, model.Id); + var element = _woodStorage.GetElement(new WoodSearchModel + { + WoodName = model.WoodName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj new file mode 100644 index 0000000..055d91f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..faf4e34 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..b814e83 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int WoodId { get; set; } + public string WoodName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs new file mode 100644 index 0000000..4f4b1af --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs @@ -0,0 +1,16 @@ +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class WoodBindingModel : IWoodModel + { + public int Id { get; set; } + public string WoodName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary WoodComponents + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..d36006f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..07a7c17 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs new file mode 100644 index 0000000..2b2bb25 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs @@ -0,0 +1,15 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IWoodLogic + { + List? ReadList(WoodSearchModel? model); + WoodViewModel? ReadElement(WoodSearchModel model); + bool Create(WoodBindingModel model); + bool Update(WoodBindingModel model); + bool Delete(WoodBindingModel model); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj new file mode 100644 index 0000000..6ef3d42 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..14c1448 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace CarpentryWorkshopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..4ea399e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace CarpentryWorkshopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs new file mode 100644 index 0000000..ada738d --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs @@ -0,0 +1,8 @@ +namespace CarpentryWorkshopContracts.SearchModels +{ + public class WoodSearchModel + { + public int? Id { get; set; } + public string? WoodName { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..c24a37b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.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); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..50c291e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.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); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs new file mode 100644 index 0000000..d2e3f41 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs @@ -0,0 +1,16 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; + +namespace CarpentryWorkshopContracts.StoragesContracts +{ + public interface IWoodStorage + { + List GetFullList(); + List GetFilteredList(WoodSearchModel model); + WoodViewModel? GetElement(WoodSearchModel model); + WoodViewModel? Insert(WoodBindingModel model); + WoodViewModel? Update(WoodBindingModel model); + WoodViewModel? Delete(WoodBindingModel model); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..6e7b31c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using CarpentryWorkshopDataModels.Models; +using System.ComponentModel; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..64235bc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; +using System.ComponentModel; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int WoodId { get; set; } + [DisplayName("Изделие")] + public string WoodName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs new file mode 100644 index 0000000..aef07a4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs @@ -0,0 +1,19 @@ +using CarpentryWorkshopDataModels.Models; +using System.ComponentModel; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class WoodViewModel : IWoodModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string WoodName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary WoodComponents + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj b/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..b87de40 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,15 @@ +namespace CarpentryWorkshopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs new file mode 100644 index 0000000..86b5c6d --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace CarpentryWorkshopDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..ede69d8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs @@ -0,0 +1,9 @@ +namespace CarpentryWorkshopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..4312a8f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using CarpentryWorkshopDataModels.Enums; + +namespace CarpentryWorkshopDataModels.Models +{ + public interface IOrderModel : IId + { + int WoodId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs new file mode 100644 index 0000000..3fc19d8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs @@ -0,0 +1,9 @@ +namespace CarpentryWorkshopDataModels.Models +{ + public interface IWoodModel : IId + { + string WoodName { get; } + double Price { get; } + Dictionary WoodComponents { get; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj new file mode 100644 index 0000000..319d159 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..9813b2a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using CarpentryWorkshopListImplement.Models; + +namespace CarpentryWorkshopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Woods { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Woods = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..6cccd91 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,101 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; + +namespace CarpentryWorkshopListImplement.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/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..b7c740f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,101 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; + +namespace CarpentryWorkshopListImplement.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 (order.Id.Equals(model.Id)) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (model.Id == null && !model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ((model.Id != null && order.Id == model.Id) || + (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/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs new file mode 100644 index 0000000..3c0c06c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs @@ -0,0 +1,101 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; + +namespace CarpentryWorkshopListImplement.Implements +{ + public class WoodStorage : IWoodStorage + { + private readonly DataListSingleton _source; + public WoodStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var wood in _source.Woods) + { + result.Add(wood.GetViewModel); + } + return result; + } + public List GetFilteredList(WoodSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.WoodName)) + { + return result; + } + foreach (var wood in _source.Woods) + { + if (wood.WoodName.Contains(model.WoodName)) + { + result.Add(wood.GetViewModel); + } + } + return result; + } + public WoodViewModel? GetElement(WoodSearchModel model) + { + if (string.IsNullOrEmpty(model.WoodName) && !model.Id.HasValue) + { + return null; + } + foreach (var wood in _source.Woods) + { + if ((!string.IsNullOrEmpty(model.WoodName) && wood.WoodName == model.WoodName) || + (model.Id.HasValue && wood.Id == model.Id)) + { + return wood.GetViewModel; + } + } + return null; + } + public WoodViewModel? Insert(WoodBindingModel model) + { + model.Id = 1; + foreach (var wood in _source.Woods) + { + if (model.Id <= wood.Id) + { + model.Id = wood.Id + 1; + } + } + var newWood = Wood.Create(model); + if (newWood == null) + { + return null; + } + _source.Woods.Add(newWood); + return newWood.GetViewModel; + } + public WoodViewModel? Update(WoodBindingModel model) + { + foreach (var wood in _source.Woods) + { + if (wood.Id == model.Id) + { + wood.Update(model); + return wood.GetViewModel; + } + } + return null; + } + public WoodViewModel? Delete(WoodBindingModel model) + { + for (int i = 0; i < _source.Woods.Count; ++i) + { + if (_source.Woods[i].Id == model.Id) + { + var element = _source.Woods[i]; + _source.Woods.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs new file mode 100644 index 0000000..8dce082 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs new file mode 100644 index 0000000..acd2e75 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs @@ -0,0 +1,58 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; set; } + public int WoodId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } + public DateTime DateCreate { get; set; } + public DateTime? DateImplement { get; set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WoodId = model.WoodId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + WoodId = model.WoodId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + WoodId = WoodId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs new file mode 100644 index 0000000..ade5ca4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs @@ -0,0 +1,45 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Wood : IWoodModel + { + public int Id { get; private set; } + public string WoodName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary WoodComponents { get; private set; } = new Dictionary(); + public static Wood? Create(WoodBindingModel? model) + { + if (model == null) + { + return null; + } + return new Wood() + { + Id = model.Id, + WoodName = model.WoodName, + Price = model.Price, + WoodComponents = model.WoodComponents + }; + } + public void Update(WoodBindingModel? model) + { + if (model == null) + { + return; + } + WoodName = model.WoodName; + Price = model.Price; + WoodComponents = model.WoodComponents; + } + public WoodViewModel GetViewModel => new() + { + Id = Id, + WoodName = WoodName, + Price = Price, + WoodComponents = WoodComponents + }; + } +} \ No newline at end of file -- 2.25.1 From 55541300922e6465abfc66ac920dabe35e6a867d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 12 Feb 2024 17:46:14 +0400 Subject: [PATCH 2/4] =?UTF-8?q?1=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82!=20=D0=BD=D0=BE=20=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BF=D0=B0=D1=80=D1=83=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormComponents.Designer.cs | 158 ++++++++-------- .../FormCreateOrder.Designer.cs | 146 ++++++++++++++ .../CarpentryWorkshop/FormCreateOrder.cs | 120 ++++++++++++ .../CarpentryWorkshop/FormCreateOrder.resx | 120 ++++++++++++ .../CarpentryWorkshop/FormMain.Designer.cs | 178 ++++++++++++++++++ .../CarpentryWorkshop/FormMain.cs | 149 +++++++++++++++ .../CarpentryWorkshop/FormMain.resx | 123 ++++++++++++ .../CarpentryWorkshop/FormWood.cs | 9 - .../CarpentryWorkshop/FormWoods.Designer.cs | 115 +++++++++++ .../CarpentryWorkshop/FormWoods.cs | 98 ++++++++++ .../CarpentryWorkshop/FormWoods.resx | 120 ++++++++++++ .../CarpentryWorkshop/Program.cs | 7 +- 12 files changed, 1254 insertions(+), 89 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormMain.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormMain.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshop/FormWoods.resx diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs index 659028e..4d121ff 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs @@ -28,93 +28,95 @@ /// private void InitializeComponent() { - dataGridView = new DataGridView(); - buttonAdd = new Button(); - buttonUpd = new Button(); - buttonDel = new Button(); - buttonRef = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.BackgroundColor = SystemColors.ControlLightLight; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Left; - dataGridView.Location = new Point(0, 0); - dataGridView.MultiSelect = false; - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(350, 360); - dataGridView.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.Location = new Point(410, 32); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(75, 23); - buttonAdd.TabIndex = 1; - buttonAdd.Text = "Добавить"; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonUpd - // - buttonUpd.Location = new Point(410, 70); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(75, 23); - buttonUpd.TabIndex = 2; - buttonUpd.Text = "Изменить"; - buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += buttonUpd_Click; - // - // buttonDel - // - buttonDel.Location = new Point(410, 111); - buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(75, 23); - buttonDel.TabIndex = 3; - buttonDel.Text = "Удалить"; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += buttonDel_Click; + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); // // buttonRef // - buttonRef.Location = new Point(410, 152); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(75, 23); - buttonRef.TabIndex = 4; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += buttonRef_Click; + this.buttonRef.Location = new System.Drawing.Point(370, 132); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(370, 91); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(370, 50); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(370, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 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.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 312); + this.dataGridView.TabIndex = 0; // // FormComponents // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(541, 360); - Controls.Add(buttonRef); - Controls.Add(buttonDel); - Controls.Add(buttonUpd); - Controls.Add(buttonAdd); - Controls.Add(dataGridView); - Margin = new Padding(4, 3, 4, 3); - Name = "FormComponents"; - Text = "Компоненты"; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 312); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + } #endregion - private DataGridView dataGridView; - private Button buttonAdd; - private Button buttonUpd; - private Button buttonDel; - private Button buttonRef; + private System.Windows.Forms.Button buttonRef; + private System.Windows.Forms.Button buttonDel; + private System.Windows.Forms.Button buttonUpd; + private System.Windows.Forms.Button buttonAdd; + private System.Windows.Forms.DataGridView dataGridView; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..3b9f590 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace CarpentryWorkshopView +{ + 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.labelCount = new System.Windows.Forms.Label(); + this.comboBoxWood = new System.Windows.Forms.ComboBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelProduct = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 36); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(69, 13); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // comboBoxWood + // + this.comboBoxWood.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxWood.FormattingEnabled = true; + this.comboBoxWood.Location = new System.Drawing.Point(87, 6); + this.comboBoxWood.Name = "comboBoxWood"; + this.comboBoxWood.Size = new System.Drawing.Size(217, 21); + this.comboBoxWood.TabIndex = 1; + this.comboBoxWood.SelectedIndexChanged += new System.EventHandler(this.comboBoxWood_SelectedIndexChanged); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(219, 85); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(138, 85); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(87, 33); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(217, 20); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // labelProduct + // + this.labelProduct.AutoSize = true; + this.labelProduct.Location = new System.Drawing.Point(12, 9); + this.labelProduct.Name = "labelProduct"; + this.labelProduct.Size = new System.Drawing.Size(54, 13); + this.labelProduct.TabIndex = 0; + this.labelProduct.Text = "Изделие:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 62); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(44, 13); + this.labelSum.TabIndex = 4; + this.labelSum.Text = "Сумма:"; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(87, 59); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(217, 20); + this.textBoxSum.TabIndex = 5; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(318, 118); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxWood); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelProduct); + this.Name = "FormCreateOrder"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Label labelCount; + private System.Windows.Forms.ComboBox comboBoxWood; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonSave; + private System.Windows.Forms.TextBox textBoxCount; + private System.Windows.Forms.Label labelProduct; + private System.Windows.Forms.Label labelSum; + private System.Windows.Forms.TextBox textBoxSum; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs new file mode 100644 index 0000000..7bd71e3 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs @@ -0,0 +1,120 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IWoodLogic _logicW; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IWoodLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + //List list = _logicW.ReadList(null); + //if (list != null) + //{ + // comboBoxWood.DisplayMember = "WoodName"; + // comboBoxWood.ValueMember = "Id"; + // comboBoxWood.DataSource = list; + // comboBoxWood.SelectedItem = null; + //} + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "ManufactureName"; + comboBoxWood.ValueMember = "Id"; + comboBoxWood.DataSource = list; + comboBoxWood.SelectedItem = null; + } + _logger.LogInformation("Изделия загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxWood.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxWood.SelectedValue); + var wood = _logicW.ReadElement(new WoodSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (wood?.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 comboBoxWood_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 (comboBoxWood.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + WoodId = Convert.ToInt32(comboBoxWood.SelectedValue), + WoodName = comboBoxWood.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.resx b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs new file mode 100644 index 0000000..08dbbfe --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs @@ -0,0 +1,178 @@ +namespace CarpentryWorkshopView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + ИзделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ButtonCreateOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + ButtonOrderReady = new Button(); + ButtonIssuedOrder = new Button(); + ButtonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(896, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ИзделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // ИзделияToolStripMenuItem + // + ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + ИзделияToolStripMenuItem.Size = new Size(180, 22); + ИзделияToolStripMenuItem.Text = "Изделия"; + ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.EnableHeadersVisualStyles = false; + dataGridView.Location = new Point(1, 32); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(755, 243); + dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonCreateOrder.Location = new Point(762, 44); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(122, 23); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; + // + // ButtonTakeOrderInWork + // + ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonTakeOrderInWork.Location = new Point(762, 73); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(122, 42); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // ButtonOrderReady + // + ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonOrderReady.Location = new Point(762, 121); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(122, 23); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonIssuedOrder.Location = new Point(762, 150); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(122, 23); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // ButtonRef + // + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(762, 179); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(122, 23); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(896, 280); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Сборка Набора"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private DataGridView dataGridView; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem ИзделияToolStripMenuItem; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs new file mode 100644 index 0000000..ea377d9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -0,0 +1,149 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarpentryWorkshopView +{ + 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[1].Visible = false; + + } + _logger.LogInformation("Загрузка продуктов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки продуктов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + // прописать логику + var service = Program.ServiceProvider?.GetService(typeof(FormWoods)); + if (service is FormWoods 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/CarpentryWorkshop/CarpentryWorkshop/FormMain.resx b/CarpentryWorkshop/CarpentryWorkshop/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs index 4facb1c..c16da1e 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs @@ -4,15 +4,6 @@ using CarpentryWorkshopContracts.BusinessLogicsContracts; using CarpentryWorkshopContracts.SearchModels; using CarpentryWorkshopDataModels.Models; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace CarpentryWorkshopView { diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs new file mode 100644 index 0000000..06e908f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.Designer.cs @@ -0,0 +1,115 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoods + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + 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(509, 448); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(526, 12); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(127, 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(526, 41); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(127, 23); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(526, 70); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(127, 23); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(526, 99); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(127, 23); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormWoods + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(668, 450); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormWoods"; + this.Text = "Набор"; + this.Load += new System.EventHandler(this.FormWoods_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button ButtonAdd; + private System.Windows.Forms.Button ButtonUpd; + private System.Windows.Forms.Button ButtonDel; + private System.Windows.Forms.Button ButtonRef; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs new file mode 100644 index 0000000..94ffbb0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.cs @@ -0,0 +1,98 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopView +{ + public partial class FormWoods : Form + { + private readonly ILogger _logger; + private readonly IWoodLogic _logic; + public FormWoods(ILogger logger, IWoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormWoods_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["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns[3].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(FormWood)); + if (service is FormWood 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(FormWood)); + if (service is FormWood 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 WoodBindingModel { 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/CarpentryWorkshop/CarpentryWorkshop/FormWoods.resx b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoods.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Program.cs b/CarpentryWorkshop/CarpentryWorkshop/Program.cs index 837f262..a1741f7 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Program.cs @@ -2,6 +2,7 @@ using CarpentryWorkshopBusinessLogic.BusinessLogics; using CarpentryWorkshopContracts.BusinessLogicsContracts; using CarpentryWorkshopContracts.StoragesContracts; using CarpentryWorkshopListImplement.Implements; +using CarpentryWorkshopView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -19,11 +20,13 @@ namespace CarpentryWorkshop [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) -- 2.25.1 From e9a686fc1a8843ac1a1d9d0f228cc8c3ecb6596b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Thu, 22 Feb 2024 14:59:15 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E=D1=81=D1=8C?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=201=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCreateOrder.Designer.cs | 176 +++++++++--------- .../CarpentryWorkshop/FormCreateOrder.cs | 3 +- .../CarpentryWorkshop/FormMain.cs | 33 ++-- .../CarpentryWorkshop/FormWood.Designer.cs | 43 ++--- .../FormWoodComponent.Designer.cs | 1 + .../BusinessLogics/OrderLogic.cs | 136 ++++++-------- .../BindingModels/OrderBindingModel.cs | 1 - .../Implements/OrderStorage.cs | 17 +- 8 files changed, 207 insertions(+), 203 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs index 3b9f590..2e159bf 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs @@ -28,119 +28,127 @@ /// private void InitializeComponent() { - this.labelCount = new System.Windows.Forms.Label(); - this.comboBoxWood = new System.Windows.Forms.ComboBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.labelProduct = new System.Windows.Forms.Label(); - this.labelSum = new System.Windows.Forms.Label(); - this.textBoxSum = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); + labelCount = new Label(); + comboBoxWood = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + labelProduct = new Label(); + labelSum = new Label(); + textBoxSum = new TextBox(); + SuspendLayout(); // // labelCount // - this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(12, 36); - this.labelCount.Name = "labelCount"; - this.labelCount.Size = new System.Drawing.Size(69, 13); - this.labelCount.TabIndex = 2; - this.labelCount.Text = "Количество:"; + labelCount.AutoSize = true; + labelCount.Location = new Point(14, 42); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; // // comboBoxWood // - this.comboBoxWood.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxWood.FormattingEnabled = true; - this.comboBoxWood.Location = new System.Drawing.Point(87, 6); - this.comboBoxWood.Name = "comboBoxWood"; - this.comboBoxWood.Size = new System.Drawing.Size(217, 21); - this.comboBoxWood.TabIndex = 1; - this.comboBoxWood.SelectedIndexChanged += new System.EventHandler(this.comboBoxWood_SelectedIndexChanged); + comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWood.FormattingEnabled = true; + comboBoxWood.Location = new Point(102, 7); + comboBoxWood.Margin = new Padding(4, 3, 4, 3); + comboBoxWood.Name = "comboBoxWood"; + comboBoxWood.Size = new Size(252, 23); + comboBoxWood.TabIndex = 1; + comboBoxWood.SelectedIndexChanged += comboBoxWood_SelectedIndexChanged; // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(219, 85); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(75, 23); - this.buttonCancel.TabIndex = 7; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + buttonCancel.Location = new Point(255, 98); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(138, 85); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(75, 23); - this.buttonSave.TabIndex = 6; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + buttonSave.Location = new Point(161, 98); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(87, 33); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(217, 20); - this.textBoxCount.TabIndex = 3; - this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + textBoxCount.Location = new Point(102, 38); + textBoxCount.Margin = new Padding(4, 3, 4, 3); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(252, 23); + textBoxCount.TabIndex = 3; + textBoxCount.TextChanged += textBoxCount_TextChanged; // // labelProduct // - this.labelProduct.AutoSize = true; - this.labelProduct.Location = new System.Drawing.Point(12, 9); - this.labelProduct.Name = "labelProduct"; - this.labelProduct.Size = new System.Drawing.Size(54, 13); - this.labelProduct.TabIndex = 0; - this.labelProduct.Text = "Изделие:"; + labelProduct.AutoSize = true; + labelProduct.Location = new Point(14, 10); + labelProduct.Margin = new Padding(4, 0, 4, 0); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(56, 15); + labelProduct.TabIndex = 0; + labelProduct.Text = "Изделие:"; // // labelSum // - this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(12, 62); - this.labelSum.Name = "labelSum"; - this.labelSum.Size = new System.Drawing.Size(44, 13); - this.labelSum.TabIndex = 4; - this.labelSum.Text = "Сумма:"; + labelSum.AutoSize = true; + labelSum.Location = new Point(14, 72); + labelSum.Margin = new Padding(4, 0, 4, 0); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 4; + labelSum.Text = "Сумма:"; // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(87, 59); - this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.ReadOnly = true; - this.textBoxSum.Size = new System.Drawing.Size(217, 20); - this.textBoxSum.TabIndex = 5; + textBoxSum.Location = new Point(102, 68); + textBoxSum.Margin = new Padding(4, 3, 4, 3); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(252, 23); + textBoxSum.TabIndex = 5; // // FormCreateOrder // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(318, 118); - this.Controls.Add(this.labelSum); - this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.labelCount); - this.Controls.Add(this.comboBoxWood); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.labelProduct); - this.Name = "FormCreateOrder"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Заказ"; - this.Load += new System.EventHandler(this.FormCreateOrder_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(371, 136); + Controls.Add(labelSum); + Controls.Add(textBoxSum); + Controls.Add(labelCount); + Controls.Add(comboBoxWood); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelProduct); + Margin = new Padding(4, 3, 4, 3); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); } #endregion - private System.Windows.Forms.Label labelCount; - private System.Windows.Forms.ComboBox comboBoxWood; - private System.Windows.Forms.Button buttonCancel; - private System.Windows.Forms.Button buttonSave; - private System.Windows.Forms.TextBox textBoxCount; - private System.Windows.Forms.Label labelProduct; - private System.Windows.Forms.Label labelSum; - private System.Windows.Forms.TextBox textBoxSum; + private Label labelCount; + private ComboBox comboBoxWood; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelProduct; + private Label labelSum; + private TextBox textBoxSum; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs index 7bd71e3..9e8e96c 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs @@ -34,7 +34,7 @@ namespace CarpentryWorkshopView var list = _logicW.ReadList(null); if (list != null) { - comboBoxWood.DisplayMember = "ManufactureName"; + comboBoxWood.DisplayMember = "WoodName"; comboBoxWood.ValueMember = "Id"; comboBoxWood.DataSource = list; comboBoxWood.SelectedItem = null; @@ -93,7 +93,6 @@ namespace CarpentryWorkshopView var operationResult = _logicO.CreateOrder(new OrderBindingModel { WoodId = Convert.ToInt32(comboBoxWood.SelectedValue), - WoodName = comboBoxWood.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs index ea377d9..9c3fba9 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -1,16 +1,8 @@ using CarpentryWorkshop; using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopDataModels.Enums; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace CarpentryWorkshopView { @@ -38,7 +30,8 @@ namespace CarpentryWorkshopView if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns[1].Visible = false; + dataGridView.Columns["WoodId"].Visible = false; + dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка продуктов"); @@ -75,6 +68,20 @@ namespace CarpentryWorkshopView LoadData(); } } + + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + WoodId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["WoodId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -83,7 +90,7 @@ namespace CarpentryWorkshopView _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -105,7 +112,7 @@ namespace CarpentryWorkshopView _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -126,7 +133,7 @@ namespace CarpentryWorkshopView _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs index c039c4b..1771f2f 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs @@ -34,15 +34,15 @@ textBoxPrice = new TextBox(); groupBox1 = new GroupBox(); dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); ButtonRef = new Button(); ButtonDel = new Button(); ButtonUpd = new Button(); ButtonAdd = new Button(); ButtonSave = new Button(); ButtonCancel = new Button(); - ID = new DataGridViewTextBoxColumn(); - ComponentName = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -76,6 +76,7 @@ // textBoxPrice.Location = new Point(94, 38); textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.ReadOnly = true; textBoxPrice.Size = new Size(100, 23); textBoxPrice.TabIndex = 3; // @@ -104,6 +105,24 @@ dataGridView.Size = new Size(394, 311); dataGridView.TabIndex = 5; // + // ID + // + ID.HeaderText = "Id"; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 250; + // + // ComponentName + // + ComponentName.HeaderText = "Компонент"; + ComponentName.Name = "ComponentName"; + ComponentName.Width = 250; + // + // Count + // + Count.HeaderText = "Количество"; + Count.Name = "Count"; + // // ButtonRef // ButtonRef.Location = new Point(400, 169); @@ -164,24 +183,6 @@ ButtonCancel.UseVisualStyleBackColor = true; ButtonCancel.Click += ButtonCancel_Click; // - // ID - // - ID.HeaderText = "Id"; - ID.Name = "ID"; - ID.Visible = false; - ID.Width = 250; - // - // ComponentName - // - ComponentName.HeaderText = "Компонент"; - ComponentName.Name = "ComponentName"; - ComponentName.Width = 250; - // - // Count - // - Count.HeaderText = "Количество"; - Count.Name = "Count"; - // // FormWood // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs index e06c6ad..644bad9 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs @@ -63,6 +63,7 @@ // // comboBoxComponent // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxComponent.BackColor = SystemColors.Window; comboBoxComponent.FormattingEnabled = true; comboBoxComponent.Location = new Point(90, 6); diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 1166d01..66a3eee 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,15 +12,18 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics { 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); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -29,102 +32,75 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public bool CreateOrder(OrderBindingModel model) { - _orderStorage.Insert(new OrderBindingModel + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) { - WoodId = model.WoodId, - WoodName = model.WoodName, - Count = model.Count, - Sum = model.Sum, - Status = OrderStatus.Принят, - DateCreate = DateTime.Now - }); ; + _logger.LogWarning("Insert operation failed"); + return false; + } return true; } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Элемент не найден"); - } - if (order.Status.ToString() != "Принят") - { - throw new Exception("Заказ не в статусе \"Принят\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - - Status = OrderStatus.Выполняется - }); - return true; + return ChangeStatus(model, OrderStatus.Выполняется); } + public bool FinishOrder(OrderBindingModel model) { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); - } - if (order.Status.ToString() != "Выполняется") - { - throw new Exception("Заказ не в статусе \"Выполняется\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = DateTime.Now, - Status = OrderStatus.Готов - }); - return true; + return ChangeStatus(model, OrderStatus.Готов); } + public bool DeliveryOrder(OrderBindingModel model) { - var order = _orderStorage.GetElement(new OrderSearchModel + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = +true) + { + if (model == null) { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); + throw new ArgumentNullException(nameof(model)); } - - if (order.Status.ToString() != "Готов") + if (!withParams) { - throw new Exception("Заказ не в статусе \"Готов\""); + return; } - - _orderStorage.Update(new OrderBindingModel + if (model.Sum <= 0) { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = order.DateImplement, - Status = OrderStatus.Выдан - }); - return true; - + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); } } -} \ No newline at end of file +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs index b814e83..5421843 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -7,7 +7,6 @@ namespace CarpentryWorkshopContracts.BindingModels { public int Id { get; set; } public int WoodId { get; set; } - public string WoodName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs index b7c740f..9cf7e8a 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs @@ -18,7 +18,7 @@ namespace CarpentryWorkshopListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(AccessWoodStorage(order.GetViewModel)); } return result; } @@ -33,7 +33,7 @@ namespace CarpentryWorkshopListImplement.Implements { if (order.Id.Equals(model.Id)) { - result.Add(order.GetViewModel); + result.Add(AccessWoodStorage(order.GetViewModel)); } } return result; @@ -97,5 +97,18 @@ namespace CarpentryWorkshopListImplement.Implements } return null; } + + public OrderViewModel AccessWoodStorage(OrderViewModel model) + { + foreach (var wood in _source.Woods) + { + if (wood.Id == model.WoodId) + { + model.WoodName = wood.WoodName; + break; + } + } + return model; + } } } \ No newline at end of file -- 2.25.1 From 7b3c8b5b256eee878576cad517f365ba034b63b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Thu, 22 Feb 2024 15:14:50 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B2=D0=BE=D1=82=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs | 8 -------- CarpentryWorkshop/CarpentryWorkshop/FormMain.cs | 5 ++--- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs index 9e8e96c..80d42b5 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs @@ -21,14 +21,6 @@ namespace CarpentryWorkshopView private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - //List list = _logicW.ReadList(null); - //if (list != null) - //{ - // comboBoxWood.DisplayMember = "WoodName"; - // comboBoxWood.ValueMember = "Id"; - // comboBoxWood.DataSource = list; - // comboBoxWood.SelectedItem = null; - //} try { var list = _logicW.ReadList(null); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs index 9c3fba9..73d980e 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -23,7 +23,6 @@ namespace CarpentryWorkshopView private void LoadData() { _logger.LogInformation("Загрузка заказов"); - // прописать логику try { var list = _orderLogic.ReadList(null); @@ -34,11 +33,11 @@ namespace CarpentryWorkshopView dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка продуктов"); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки продуктов"); + _logger.LogError(ex, "Ошибка загрузки изделий"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } -- 2.25.1