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..4d121ff --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormComponents.Designer.cs @@ -0,0 +1,122 @@ +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() + { + 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 + // + 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 + // + 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 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/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/FormCreateOrder.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..2e159bf --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.Designer.cs @@ -0,0 +1,154 @@ +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() + { + 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 + // + 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 + // + 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 + // + 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 + // + 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 + // + 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 + // + 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 + // + 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 + // + 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 + // + 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 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 new file mode 100644 index 0000000..80d42b5 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormCreateOrder.cs @@ -0,0 +1,111 @@ +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("Загрузка изделий для заказа"); + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "WoodName"; + 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), + 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..73d980e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -0,0 +1,155 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +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["WoodId"].Visible = false; + dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + // прописать логику + var service = Program.ServiceProvider?.GetService(typeof(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 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) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(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(CreateBindingModel(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(CreateBindingModel(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.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs new file mode 100644 index 0000000..1771f2f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.Designer.cs @@ -0,0 +1,225 @@ +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(); + 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(); + 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.ReadOnly = true; + 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; + // + // 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); + 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; + // + // 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..c16da1e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWood.cs @@ -0,0 +1,193 @@ +using CarpentryWorkshop; +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; + +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..644bad9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshop/FormWoodComponent.Designer.cs @@ -0,0 +1,120 @@ +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.DropDownStyle = ComboBoxStyle.DropDownList; + 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/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 57440dd..a1741f7 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Program.cs @@ -1,7 +1,19 @@ +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; + namespace CarpentryWorkshop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +23,32 @@ namespace CarpentryWorkshop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/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..66a3eee --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,106 @@ +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) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus 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) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = +true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} 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..5421843 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class OrderBindingModel : 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; } = 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..9cf7e8a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,114 @@ +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(AccessWoodStorage(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(AccessWoodStorage(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; + } + + 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 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