diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
index b57c89e..b363b98 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj
@@ -8,4 +8,10 @@
enable
+
+
+
+
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs
deleted file mode 100644
index 6d3391d..0000000
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace BlacksmithWorkshop
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs
deleted file mode 100644
index 6c3de35..0000000
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace BlacksmithWorkshop
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx b/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Form1.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..da2944a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs
@@ -0,0 +1,144 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelManufacture = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.labelSum = new System.Windows.Forms.Label();
+ this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelManufacture
+ //
+ this.labelManufacture.AutoSize = true;
+ this.labelManufacture.Location = new System.Drawing.Point(24, 24);
+ this.labelManufacture.Name = "labelManufacture";
+ this.labelManufacture.Size = new System.Drawing.Size(71, 20);
+ this.labelManufacture.TabIndex = 0;
+ this.labelManufacture.Text = "Изделие:";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(24, 70);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(93, 20);
+ this.labelCount.TabIndex = 1;
+ this.labelCount.Text = "Количество:";
+ //
+ // labelSum
+ //
+ this.labelSum.AutoSize = true;
+ this.labelSum.Location = new System.Drawing.Point(24, 113);
+ this.labelSum.Name = "labelSum";
+ this.labelSum.Size = new System.Drawing.Size(58, 20);
+ this.labelSum.TabIndex = 2;
+ this.labelSum.Text = "Сумма:";
+ //
+ // comboBoxManufacture
+ //
+ this.comboBoxManufacture.FormattingEnabled = true;
+ this.comboBoxManufacture.Location = new System.Drawing.Point(166, 21);
+ this.comboBoxManufacture.Name = "comboBoxManufacture";
+ this.comboBoxManufacture.Size = new System.Drawing.Size(278, 28);
+ this.comboBoxManufacture.TabIndex = 3;
+ this.comboBoxManufacture.SelectedIndexChanged += new System.EventHandler(this.ComboBoxManufacture_SelectedIndexChanged);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(166, 67);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(278, 27);
+ this.textBoxCount.TabIndex = 4;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(166, 110);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.Size = new System.Drawing.Size(278, 27);
+ this.textBoxSum.TabIndex = 5;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(230, 155);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(340, 155);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(479, 203);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxManufacture);
+ this.Controls.Add(this.labelSum);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelManufacture);
+ this.Name = "FormCreateOrder";
+ this.Text = "Заказ";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelManufacture;
+ private Label labelCount;
+ private Label labelSum;
+ private ComboBox comboBoxManufacture;
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs
new file mode 100644
index 0000000..4295273
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.cs
@@ -0,0 +1,130 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IManufactureLogic _logicA;
+
+ private readonly IOrderLogic _logicO;
+
+ public FormCreateOrder(ILogger logger, IManufactureLogic logicA, IOrderLogic logicO)
+ {
+ InitializeComponent();
+
+ _logger = logger;
+ _logicA = logicA;
+ _logicO = logicO;
+ }
+
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка изделий для заказа");
+
+ //дописать логику
+ }
+
+ private void CalcSum()
+ {
+ if (comboBoxManufacture.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxManufacture.SelectedValue);
+
+ var manufacture = _logicA.ReadManufacture(new ManufactureSearchModel
+ {
+ Id = id
+ });
+
+ int count = Convert.ToInt32(textBoxCount.Text);
+ textBoxSum.Text = Math.Round(count * (manufacture?.Price ?? 0), 2).ToString();
+
+ _logger.LogInformation("Расчет суммы заказа");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка расчета суммы заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void TextBoxCount_TextChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+
+ if (comboBoxManufacture.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+
+ _logger.LogInformation("Создание заказа");
+
+ try
+ {
+ var operationResult = _logicO.CreateOrder(new OrderBindingModel
+ {
+ ManufactureId = Convert.ToInt32(comboBoxManufacture.SelectedValue),
+ Count = Convert.ToInt32(textBoxCount.Text),
+ Sum = Convert.ToDouble(textBoxSum.Text)
+ });
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка создания заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
new file mode 100644
index 0000000..1fe2054
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -0,0 +1,247 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormMain
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnSum = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnStatus = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnDateCreate = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnDateImplement = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonCreateOrder = new System.Windows.Forms.Button();
+ this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
+ this.buttonOrderReady = new System.Windows.Forms.Button();
+ this.buttonIssuedOrder = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.заготовкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.menuStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnId,
+ this.ColumnManufacture,
+ this.ColumnCount,
+ this.ColumnSum,
+ this.ColumnStatus,
+ this.ColumnDateCreate,
+ this.ColumnDateImplement});
+ this.dataGridView.Location = new System.Drawing.Point(12, 36);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(937, 402);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ColumnId
+ //
+ this.ColumnId.HeaderText = "Номер";
+ this.ColumnId.MinimumWidth = 6;
+ this.ColumnId.Name = "ColumnId";
+ this.ColumnId.Width = 125;
+ //
+ // ColumnManufacture
+ //
+ this.ColumnManufacture.HeaderText = "Изделие";
+ this.ColumnManufacture.MinimumWidth = 6;
+ this.ColumnManufacture.Name = "ColumnManufacture";
+ this.ColumnManufacture.Width = 125;
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 6;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 125;
+ //
+ // ColumnSum
+ //
+ this.ColumnSum.HeaderText = "Сумма";
+ this.ColumnSum.MinimumWidth = 6;
+ this.ColumnSum.Name = "ColumnSum";
+ this.ColumnSum.Width = 125;
+ //
+ // ColumnStatus
+ //
+ this.ColumnStatus.HeaderText = "Статус";
+ this.ColumnStatus.MinimumWidth = 6;
+ this.ColumnStatus.Name = "ColumnStatus";
+ this.ColumnStatus.Width = 125;
+ //
+ // ColumnDateCreate
+ //
+ this.ColumnDateCreate.HeaderText = "Дата создания";
+ this.ColumnDateCreate.MinimumWidth = 6;
+ this.ColumnDateCreate.Name = "ColumnDateCreate";
+ this.ColumnDateCreate.Width = 125;
+ //
+ // ColumnDateImplement
+ //
+ this.ColumnDateImplement.HeaderText = "Дата выполнения";
+ this.ColumnDateImplement.MinimumWidth = 6;
+ this.ColumnDateImplement.Name = "ColumnDateImplement";
+ this.ColumnDateImplement.Width = 125;
+ //
+ // buttonCreateOrder
+ //
+ this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 66);
+ this.buttonCreateOrder.Name = "buttonCreateOrder";
+ this.buttonCreateOrder.Size = new System.Drawing.Size(235, 29);
+ this.buttonCreateOrder.TabIndex = 1;
+ this.buttonCreateOrder.Text = "Создать заказ";
+ this.buttonCreateOrder.UseVisualStyleBackColor = true;
+ this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // buttonTakeOrderInWork
+ //
+ this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1014, 143);
+ this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
+ this.buttonTakeOrderInWork.Size = new System.Drawing.Size(235, 29);
+ this.buttonTakeOrderInWork.TabIndex = 2;
+ this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
+ this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
+ this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // buttonOrderReady
+ //
+ this.buttonOrderReady.Location = new System.Drawing.Point(1014, 220);
+ this.buttonOrderReady.Name = "buttonOrderReady";
+ this.buttonOrderReady.Size = new System.Drawing.Size(235, 29);
+ this.buttonOrderReady.TabIndex = 3;
+ this.buttonOrderReady.Text = "Заказ готов";
+ this.buttonOrderReady.UseVisualStyleBackColor = true;
+ this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // buttonIssuedOrder
+ //
+ this.buttonIssuedOrder.Location = new System.Drawing.Point(1014, 296);
+ this.buttonIssuedOrder.Name = "buttonIssuedOrder";
+ this.buttonIssuedOrder.Size = new System.Drawing.Size(235, 29);
+ this.buttonIssuedOrder.TabIndex = 4;
+ this.buttonIssuedOrder.Text = "Заказ выдан";
+ this.buttonIssuedOrder.UseVisualStyleBackColor = true;
+ this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(1014, 369);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(235, 29);
+ this.buttonRef.TabIndex = 5;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(1297, 28);
+ this.menuStrip1.TabIndex = 6;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // toolStripMenuItem
+ //
+ this.toolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.заготовкиToolStripMenuItem,
+ this.изделияToolStripMenuItem});
+ this.toolStripMenuItem.Name = "toolStripMenuItem";
+ this.toolStripMenuItem.Size = new System.Drawing.Size(117, 24);
+ this.toolStripMenuItem.Text = "Справочники";
+ //
+ // заготовкиToolStripMenuItem
+ //
+ this.заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem";
+ this.заготовкиToolStripMenuItem.Size = new System.Drawing.Size(162, 26);
+ this.заготовкиToolStripMenuItem.Text = "Заготовки";
+ this.заготовкиToolStripMenuItem.Click += new System.EventHandler(this.ЗаготовкиToolStripMenuItem_Click);
+ //
+ // изделияToolStripMenuItem
+ //
+ this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
+ this.изделияToolStripMenuItem.Size = new System.Drawing.Size(162, 26);
+ this.изделияToolStripMenuItem.Text = "Изделия";
+ this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1297, 450);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonIssuedOrder);
+ this.Controls.Add(this.buttonOrderReady);
+ this.Controls.Add(this.buttonTakeOrderInWork);
+ this.Controls.Add(this.buttonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Name = "FormMain";
+ this.Text = "Абстрактный магазин";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private Button buttonTakeOrderInWork;
+ private Button buttonOrderReady;
+ private Button buttonIssuedOrder;
+ private Button buttonRef;
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem toolStripMenuItem;
+ private ToolStripMenuItem заготовкиToolStripMenuItem;
+ private ToolStripMenuItem изделияToolStripMenuItem;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnManufacture;
+ private DataGridViewTextBoxColumn ColumnCount;
+ private DataGridViewTextBoxColumn ColumnSum;
+ private DataGridViewTextBoxColumn ColumnStatus;
+ private DataGridViewTextBoxColumn ColumnDateCreate;
+ private DataGridViewTextBoxColumn ColumnDateImplement;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
new file mode 100644
index 0000000..ac32701
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -0,0 +1,163 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ 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("Загрузка заказов");
+
+ //прописать логику
+ }
+
+ private void ЗаготовкиToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormWorkPieces));
+
+ if(service is FormWorkPieces form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ //прописать логику
+ }
+
+ private void ButtonCreateOrder_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+
+ if (service is FormCreateOrder form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+
+ }
+
+ private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
+
+ try
+ {
+ var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = id
+ });
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка передачи заказа в работу");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonOrderReady_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
+
+ try
+ {
+ var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = id
+ });
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonIssuedOrder_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
+
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
+ {
+ Id = id
+ });
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+
+ _logger.LogInformation("Заказ №{id} выдан", id);
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx
new file mode 100644
index 0000000..eb63604
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs
new file mode 100644
index 0000000..0a4a273
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.Designer.cs
@@ -0,0 +1,221 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormManufacture
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelCost = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxCost = new System.Windows.Forms.TextBox();
+ this.groupBoxWorkPiece = new System.Windows.Forms.GroupBox();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnWorkPiece = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.groupBoxWorkPiece.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(23, 30);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelCost
+ //
+ this.labelCost.AutoSize = true;
+ this.labelCost.Location = new System.Drawing.Point(23, 84);
+ this.labelCost.Name = "labelCost";
+ this.labelCost.Size = new System.Drawing.Size(86, 20);
+ this.labelCost.TabIndex = 1;
+ this.labelCost.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(133, 27);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(332, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ this.textBoxCost.Location = new System.Drawing.Point(133, 81);
+ this.textBoxCost.Name = "textBoxCost";
+ this.textBoxCost.Size = new System.Drawing.Size(196, 27);
+ this.textBoxCost.TabIndex = 3;
+ //
+ // groupBoxWorkPiece
+ //
+ this.groupBoxWorkPiece.Controls.Add(this.buttonRef);
+ this.groupBoxWorkPiece.Controls.Add(this.buttonDel);
+ this.groupBoxWorkPiece.Controls.Add(this.buttonUpd);
+ this.groupBoxWorkPiece.Controls.Add(this.buttonAdd);
+ this.groupBoxWorkPiece.Controls.Add(this.dataGridView);
+ this.groupBoxWorkPiece.Location = new System.Drawing.Point(23, 126);
+ this.groupBoxWorkPiece.Name = "groupBoxWorkPiece";
+ this.groupBoxWorkPiece.Size = new System.Drawing.Size(567, 300);
+ this.groupBoxWorkPiece.TabIndex = 4;
+ this.groupBoxWorkPiece.TabStop = false;
+ this.groupBoxWorkPiece.Text = "Заготовки";
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(454, 196);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(94, 29);
+ 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(454, 145);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(94, 29);
+ 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(454, 95);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(94, 29);
+ 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(454, 43);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(94, 29);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnWorkPiece,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(6, 26);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(416, 268);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ColumnWorkPiece
+ //
+ this.ColumnWorkPiece.HeaderText = "Заготовка";
+ this.ColumnWorkPiece.MinimumWidth = 6;
+ this.ColumnWorkPiece.Name = "ColumnWorkPiece";
+ this.ColumnWorkPiece.Width = 125;
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 6;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 125;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(340, 448);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(95, 29);
+ this.buttonSave.TabIndex = 5;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(458, 448);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormManufacture
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(619, 500);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.groupBoxWorkPiece);
+ this.Controls.Add(this.textBoxCost);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelCost);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormManufacture";
+ this.Text = "Изделие";
+ this.Load += new System.EventHandler(this.FormManufacture_Load);
+ this.groupBoxWorkPiece.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCost;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private GroupBox groupBoxWorkPiece;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private DataGridViewTextBoxColumn ColumnWorkPiece;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs
new file mode 100644
index 0000000..af32e51
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.cs
@@ -0,0 +1,244 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ public partial class FormManufacture : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IManufactureLogic _logic;
+
+ private int? _id;
+
+ private Dictionary _manufactureWorkPieces;
+
+ public int Id { set { _id = value; } }
+
+ public FormManufacture(ILogger logger, IManufactureLogic logic)
+ {
+ InitializeComponent();
+
+ _logger = logger;
+ _logic = logic;
+ _manufactureWorkPieces = new Dictionary();
+ }
+
+ private void FormManufacture_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка изделия");
+
+ try
+ {
+ var view = _logic.ReadManufacture(new ManufactureSearchModel { Id = _id.Value });
+
+ if(view != null)
+ {
+ textBoxName.Text = view.ManufactureName;
+ textBoxCost.Text = view.Price.ToString();
+ _manufactureWorkPieces = view.ManufactureWorkPieces ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch(Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заготовок для изделия");
+
+ try
+ {
+ if(_manufactureWorkPieces != null)
+ {
+ dataGridView.Rows.Clear();
+
+ foreach(var awp in _manufactureWorkPieces)
+ {
+ dataGridView.Rows.Add(new object[] { awp.Key, awp.Value.Item1.WorkPieceName, awp.Value.Item2 });
+ }
+
+ textBoxCost.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(FormManufactureWorkPiece));
+ if (service is FormManufactureWorkPiece form)
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.WorkPieceModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление новой заготовки:{WorkPieceName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
+
+ if (_manufactureWorkPieces.ContainsKey(form.Id))
+ {
+ _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, form.Count);
+ }
+ else
+ {
+ _manufactureWorkPieces.Add(form.Id, (form.WorkPieceModel, form.Count));
+ }
+
+ LoadData();
+ }
+ }
+
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormManufactureWorkPiece));
+
+ if (service is FormManufactureWorkPiece form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _manufactureWorkPieces[id].Item2;
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.WorkPieceModel == null)
+ {
+ return;
+ }
+
+ _logger.LogInformation("Изменение компонента:{ComponentName} - {Count}", form.WorkPieceModel.WorkPieceName, form.Count);
+ _manufactureWorkPieces[form.Id] = (form.WorkPieceModel, 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("Удаление заготовки:{WorkPieceName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
+ _manufactureWorkPieces?.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(textBoxCost.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+
+ if (_manufactureWorkPieces == null || _manufactureWorkPieces.Count == 0)
+ {
+ MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+
+ _logger.LogInformation("Сохранение изделия");
+
+ try
+ {
+ var model = new ManufactureBindingModel
+ {
+ Id = _id ?? 0,
+ ManufactureName = textBoxName.Text,
+ Price = Convert.ToDouble(textBoxCost.Text),
+ ManufactureWorkPieces = _manufactureWorkPieces
+ };
+
+ 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 _manufactureWorkPieces)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx
new file mode 100644
index 0000000..be598c0
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufacture.resx
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs
new file mode 100644
index 0000000..82b10ad
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.Designer.cs
@@ -0,0 +1,119 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormManufactureWorkPiece
+ {
+ ///
+ /// 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.labelWorkPiece = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.comboBoxWorkPiece = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelWorkPiece
+ //
+ this.labelWorkPiece.AutoSize = true;
+ this.labelWorkPiece.Location = new System.Drawing.Point(31, 33);
+ this.labelWorkPiece.Name = "labelWorkPiece";
+ this.labelWorkPiece.Size = new System.Drawing.Size(81, 20);
+ this.labelWorkPiece.TabIndex = 0;
+ this.labelWorkPiece.Text = "Заготовка:";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(31, 79);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(93, 20);
+ this.labelCount.TabIndex = 1;
+ this.labelCount.Text = "Количество:";
+ //
+ // comboBoxWorkPiece
+ //
+ this.comboBoxWorkPiece.FormattingEnabled = true;
+ this.comboBoxWorkPiece.Location = new System.Drawing.Point(156, 30);
+ this.comboBoxWorkPiece.Name = "comboBoxWorkPiece";
+ this.comboBoxWorkPiece.Size = new System.Drawing.Size(320, 28);
+ this.comboBoxWorkPiece.TabIndex = 2;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(156, 76);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(320, 27);
+ this.textBoxCount.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(235, 118);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(353, 118);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormManufactureWorkPiece
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(526, 168);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxWorkPiece);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelWorkPiece);
+ this.Name = "FormManufactureWorkPiece";
+ this.Text = "Заготовки для изделия";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelWorkPiece;
+ private Label labelCount;
+ private ComboBox comboBoxWorkPiece;
+ private TextBox textBoxCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs
new file mode 100644
index 0000000..f367911
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.cs
@@ -0,0 +1,88 @@
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Reflection.Metadata.Ecma335;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ public partial class FormManufactureWorkPiece : Form
+ {
+ private readonly List? _list;
+
+ public int Id { get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); }
+ set { comboBoxWorkPiece.SelectedValue = value; } }
+
+ public IWorkPieceModel? WorkPieceModel
+ {
+ 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 FormManufactureWorkPiece(IWorkPieceLogic logic)
+ {
+ InitializeComponent();
+
+ _list = logic.ReadList(null);
+
+ if(_list != null)
+ {
+ comboBoxWorkPiece.DisplayMember = "WorkPieceName";
+ comboBoxWorkPiece.ValueMember = "Id";
+ comboBoxWorkPiece.DataSource = _list;
+ comboBoxWorkPiece.SelectedItem = null;
+ }
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+ if (comboBoxWorkPiece.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите заготовку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+
+ return;
+ }
+
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactureWorkPiece.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs
new file mode 100644
index 0000000..9bbdb92
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs
@@ -0,0 +1,149 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormManufactures
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(653, 36);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(94, 29);
+ this.buttonAdd.TabIndex = 0;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(653, 92);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(94, 29);
+ this.buttonUpd.TabIndex = 1;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(653, 151);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(94, 29);
+ this.buttonDelete.TabIndex = 2;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(653, 203);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(94, 29);
+ this.buttonRef.TabIndex = 3;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnId,
+ this.ColumnName,
+ this.ColumnCost});
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(604, 426);
+ this.dataGridView.TabIndex = 4;
+ //
+ // ColumnId
+ //
+ this.ColumnId.HeaderText = "Id";
+ this.ColumnId.MinimumWidth = 6;
+ this.ColumnId.Name = "ColumnId";
+ this.ColumnId.ReadOnly = true;
+ this.ColumnId.Width = 125;
+ //
+ // ColumnName
+ //
+ this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+ this.ColumnName.HeaderText = "Название";
+ this.ColumnName.MinimumWidth = 6;
+ this.ColumnName.Name = "ColumnName";
+ this.ColumnName.ReadOnly = true;
+ this.ColumnName.Width = 301;
+ //
+ // ColumnCost
+ //
+ this.ColumnCost.HeaderText = "Стоимость";
+ this.ColumnCost.MinimumWidth = 6;
+ this.ColumnCost.Name = "ColumnCost";
+ this.ColumnCost.Width = 125;
+ //
+ // formManufactures
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(781, 450);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Name = "formManufactures";
+ this.Text = "Изделия";
+ this.Load += new System.EventHandler(this.FormManufactures_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDelete;
+ private Button buttonRef;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnName;
+ private DataGridViewTextBoxColumn ColumnCost;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs
new file mode 100644
index 0000000..e0dad9e
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs
@@ -0,0 +1,124 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ public partial class FormManufactures : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IManufactureLogic _logic;
+
+ public FormManufactures(ILogger logger, IManufactureLogic logic)
+ {
+
+ InitializeComponent();
+
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormManufactures_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ColumnName"].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(FormManufacture));
+ if (service is FormManufacture form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormManufacture));
+
+ if (service is FormManufacture form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ _logger.LogInformation("Удаление компонента");
+
+ try
+ {
+ if (!_logic.Delete(new ManufactureBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs
new file mode 100644
index 0000000..020f587
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.Designer.cs
@@ -0,0 +1,119 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormWorkPiece
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(30, 24);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(30, 65);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(48, 20);
+ this.labelPrice.TabIndex = 1;
+ this.labelPrice.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(127, 21);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(293, 27);
+ this.textBoxName.TabIndex = 2;
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(127, 62);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.Size = new System.Drawing.Size(179, 27);
+ this.textBoxPrice.TabIndex = 3;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(326, 104);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(212, 104);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 5;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // FormWorkPiece
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(464, 153);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormWorkPiece";
+ this.Text = "Заготовка";
+ this.Load += new System.EventHandler(this.FormWorkPiece_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs
new file mode 100644
index 0000000..c5a3e7d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.cs
@@ -0,0 +1,103 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshop
+{
+ // ""
+ public partial class FormWorkPiece : System.Windows.Forms.Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IWorkPieceLogic _logic;
+
+ private int? _id;
+
+ public int Id { set { _id = value; } }
+
+ //
+ public FormWorkPiece(ILogger logger, IWorkPieceLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ //
+ private void FormWorkPiece_Load(object sender, EventArgs e)
+ {
+ // id. ,
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation(" ");
+
+ var view = _logic.ReadElement(new WorkPieceSearchModel { Id = _id.Value });
+
+ if(view != null)
+ {
+ textBoxName.Text = view.WorkPieceName;
+ textBoxPrice.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 WorkPieceBindingModel
+ {
+ Id = _id ?? 0,
+ WorkPieceName = textBoxName.Text,
+ Cost = Convert.ToDouble(textBoxPrice.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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPiece.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs
new file mode 100644
index 0000000..250fce1
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.Designer.cs
@@ -0,0 +1,149 @@
+namespace BlacksmithWorkshop
+{
+ partial class FormWorkPieces
+ {
+ ///
+ /// 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.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCost = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(653, 36);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(94, 29);
+ this.buttonAdd.TabIndex = 0;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(653, 92);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(94, 29);
+ this.buttonUpd.TabIndex = 1;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(653, 151);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(94, 29);
+ this.buttonDelete.TabIndex = 2;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(653, 203);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(94, 29);
+ this.buttonRef.TabIndex = 3;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnId,
+ this.ColumnName,
+ this.ColumnCost});
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(604, 426);
+ this.dataGridView.TabIndex = 4;
+ //
+ // ColumnId
+ //
+ this.ColumnId.HeaderText = "Id";
+ this.ColumnId.MinimumWidth = 6;
+ this.ColumnId.Name = "ColumnId";
+ this.ColumnId.ReadOnly = true;
+ this.ColumnId.Width = 125;
+ //
+ // ColumnName
+ //
+ this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
+ this.ColumnName.HeaderText = "Название";
+ this.ColumnName.MinimumWidth = 6;
+ this.ColumnName.Name = "ColumnName";
+ this.ColumnName.ReadOnly = true;
+ this.ColumnName.Width = 301;
+ //
+ // ColumnCost
+ //
+ this.ColumnCost.HeaderText = "Стоимость";
+ this.ColumnCost.MinimumWidth = 6;
+ this.ColumnCost.Name = "ColumnCost";
+ this.ColumnCost.Width = 125;
+ //
+ // FormWorkPieces
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(781, 450);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Name = "FormWorkPieces";
+ this.Text = "Компоненты";
+ this.Load += new System.EventHandler(this.FormWorkPiece_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDelete;
+ private Button buttonRef;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnName;
+ private DataGridViewTextBoxColumn ColumnCost;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs
new file mode 100644
index 0000000..8943400
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.cs
@@ -0,0 +1,127 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace BlacksmithWorkshop
+{
+ public partial class FormWorkPieces : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IManufactureLogic _logic;
+
+ public FormWorkPieces(ILogger logger, IManufactureLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormWorkPiece_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+
+ //растягиваем колонку Название на всю ширину, колонку Id скрываем
+ if(list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ManufactureName"].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(FormWorkPieces));
+
+ if (service is FormWorkPieces 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(FormWorkPiece));
+
+ if (service is FormWorkPiece form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ //проверяем наличие выделенной строки
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ _logger.LogInformation("Удаление компонента");
+
+ try
+ {
+ if (!_logic.Delete(new ManufactureBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx
new file mode 100644
index 0000000..7bec10e
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormWorkPieces.resx
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index 1d7fc1e..8f7a4c9 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -1,17 +1,56 @@
+using BlacksmithWorkshopBusinessLogic.BusinessLogic;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopListImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
+using System.Drawing;
+
namespace BlacksmithWorkshop
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
///
- /// The main entry point for the application.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI settings or default font,
+ // 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();
+ }
+
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs
similarity index 63%
rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs
index c95ec8f..84a3287 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ArticleLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ManufactureLogic.cs
@@ -12,26 +12,26 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
- internal class ArticleLogic : IArticleLogic
+ public class ManufactureLogic : IManufactureLogic
{
private readonly ILogger _logger;
- private readonly IArticleStorage _articleStorage;
+ private readonly IManufactureStorage _manufactureStorage;
//конструктор
- public ArticleLogic(ILogger logger, IArticleStorage productStorage)
+ public ManufactureLogic(ILogger logger, IManufactureStorage productStorage)
{
_logger = logger;
- _articleStorage = productStorage;
+ _manufactureStorage = productStorage;
}
//вывод отфильтрованного списка
- public List? ReadList(ArticleSearchModel? model)
+ public List? ReadList(ManufactureSearchModel? model)
{
- _logger.LogInformation("ReadList. ArticleName:{ArticleName}. Id:{Id}", model?.ArticleName, model?.Id);
+ _logger.LogInformation("ReadList. ManufactureName:{ManufactureName}. Id:{Id}", model?.ManufactureName, model?.Id);
//list хранит весь список в случае, если model пришло со значением null на вход метода
- var list = model == null ? _articleStorage.GetFullList() : _articleStorage.GetFilteredList(model);
+ var list = model == null ? _manufactureStorage.GetFullList() : _manufactureStorage.GetFilteredList(model);
if(list == null)
{
@@ -45,34 +45,34 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//вывод конкретного изделия
- public ArticleViewModel? ReadProduct(ArticleSearchModel model)
+ public ManufactureViewModel? ReadManufacture(ManufactureSearchModel model)
{
if(model == null)
{
throw new ArgumentNullException(nameof(model));
}
- _logger.LogInformation("ReadProduct. ArticleName:{ArticleName}. Id:{Id}", model.ArticleName, model.Id);
+ _logger.LogInformation("ReadManufacture. ManufactureName:{ManufactureName}. Id:{Id}", model.ManufactureName, model.Id);
- var element = _articleStorage.GetElement(model);
+ var element = _manufactureStorage.GetElement(model);
if(element == null)
{
- _logger.LogWarning("ReadProduct element not found");
+ _logger.LogWarning("ReadManufacture element not found");
return null;
}
- _logger.LogInformation("ReadProduct find. Id:{Id}", model.Id);
+ _logger.LogInformation("ReadManufacture find. Id:{Id}", model.Id);
return element;
}
//Создание изделия
- public bool Create(ArticleBindingModel model)
+ public bool Create(ManufactureBindingModel model)
{
CheckModel(model);
- if(_articleStorage.Insert(model) == null)
+ if(_manufactureStorage.Insert(model) == null)
{
_logger.LogWarning("Create operation failed");
return false;
@@ -82,11 +82,11 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//обновление изделия
- public bool Update(ArticleBindingModel model)
+ public bool Update(ManufactureBindingModel model)
{
CheckModel(model);
- if(_articleStorage.Update(model) == null)
+ if(_manufactureStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
@@ -96,11 +96,11 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//удаление изделия
- public bool Delete(ArticleBindingModel model)
+ public bool Delete(ManufactureBindingModel model)
{
CheckModel(model);
- if(_articleStorage.Delete(model) == null)
+ if(_manufactureStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
@@ -110,7 +110,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//проверка входного аргумента для методов Insert, Update и Delete
- private void CheckModel(ArticleBindingModel model, bool withParams = true)
+ private void CheckModel(ManufactureBindingModel model, bool withParams = true)
{
if(model == null)
{
@@ -124,9 +124,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//проверка на наличие названия изделия
- if (string.IsNullOrEmpty(model.ArticleName))
+ if (string.IsNullOrEmpty(model.ManufactureName))
{
- throw new ArgumentNullException("Нет названия изделия", nameof(model.ArticleName));
+ throw new ArgumentNullException("Нет названия изделия", nameof(model.ManufactureName));
}
//проверка на наличие нормальной цены у изделия
@@ -135,13 +135,13 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
}
- _logger.LogInformation("Article. ArticleName:{ArticleName}. Price:{Price}. Id:{Id}",
- model.ArticleName, model.Price, model.Id);
+ _logger.LogInformation("Manufacture. ManufactureName:{ManufactureName}. Price:{Price}. Id:{Id}",
+ model.ManufactureName, model.Price, model.Id);
//проверка на наличие такого же изделия в списке
- var element = _articleStorage.GetElement(new ArticleSearchModel
+ var element = _manufactureStorage.GetElement(new ManufactureSearchModel
{
- ArticleName = model.ArticleName,
+ ManufactureName = model.ManufactureName,
});
if(element != null && element.Id != model.Id)
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs
index aa8fa2e..3bf131f 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -110,9 +110,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//проверка корректности id у изделий
- if (model.ArticleId < 0)
+ if (model.ManufactureId < 0)
{
- throw new ArgumentNullException("Некорректный id у изделия", nameof(model.ArticleId));
+ throw new ArgumentNullException("Некорректный id у изделия", nameof(model.ManufactureId));
}
//проверка корректности дат
@@ -121,7 +121,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения");
}
- _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ArticleId:{Id}", model.Id, model.Sum, model.ArticleId);
+ _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}", model.Id, model.Sum, model.ManufactureId);
}
//обновление статуса заказа
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs
index ff09e0a..30bcbaf 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/WorkPieceLogic.cs
@@ -13,17 +13,17 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
//класс, реализующий логику для компонентов
- public class ComponentLogic : IWorkPieceLogic
+ public class WorkPieceLogic : IWorkPieceLogic
{
private readonly ILogger _logger;
private readonly IWorkPieceStorage _workPieceStorage;
//конструктор
- public ComponentLogic(ILogger logger, IWorkPieceStorage componentStorage)
+ public WorkPieceLogic(ILogger logger, IWorkPieceStorage workPieceStorage)
{
_logger = logger;
- _workPieceStorage = componentStorage;
+ _workPieceStorage = workPieceStorage;
}
//вывод отфильтрованного списка компонентов
@@ -135,7 +135,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Cost));
}
- _logger.LogInformation("Component. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}",
+ _logger.LogInformation("WorkPiece. WorkPieceName:{WorkPieceName}. Cost:{Cost}. Id:{Id}",
model.WorkPieceName, model.Cost, model.Id);
//проверка на наличие такой же заготовки в списке
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs
similarity index 61%
rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs
index 60334e6..84ed77d 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ArticleBindingModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ManufactureBindingModel.cs
@@ -8,14 +8,14 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopContracts.BindingModels
{
//реализация сущности "Продукт"
- public class ArticleBindingModel : IArticleModel
+ public class ManufactureBindingModel : IManufactureModel
{
public int Id { get; set; }
- public string ArticleName { get; set; } = string.Empty;
+ public string ManufactureName { get; set; } = string.Empty;
public double Price { get; set; }
- public Dictionary ArticleWorkPiece { get; set; } = new();
+ public Dictionary ManufactureWorkPieces { get; set; } = new();
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
index ec8912a..5ab83dc 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
@@ -13,7 +13,7 @@ namespace BlacksmithWorkshopContracts.BindingModels
{
public int Id { get; set; }
- public int ArticleId { get; set; }
+ public int ManufactureId { get; set; }
public int Count { get; set; }
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs
similarity index 53%
rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs
index 055d888..43b6b6e 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IArticleLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IManufactureLogic.cs
@@ -10,16 +10,16 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
{
//бизнес-логика для продуктов
- public interface IArticleLogic
+ public interface IManufactureLogic
{
- List? ReadList(ArticleSearchModel? model);
+ List? ReadList(ManufactureSearchModel? model);
- ArticleViewModel? ReadProduct(ArticleSearchModel model);
+ ManufactureViewModel? ReadManufacture(ManufactureSearchModel model);
- bool Create(ArticleBindingModel model);
+ bool Create(ManufactureBindingModel model);
- bool Update(ArticleBindingModel model);
+ bool Update(ManufactureBindingModel model);
- bool Delete(ArticleBindingModel model);
+ bool Delete(ManufactureBindingModel model);
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs
similarity index 82%
rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs
index 0a98f7c..d077a1b 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ArticleSearchModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ManufactureSearchModel.cs
@@ -7,12 +7,12 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopContracts.SearchModels
{
//модель для поиска заготовки "Продукт" (она же изделие)
- public class ArticleSearchModel
+ public class ManufactureSearchModel
{
//для поиска по идентификатору
public int? Id { get; set; }
//для поиска по названию
- public string? ArticleName { get; set; }
+ public string? ManufactureName { get; set; }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs
deleted file mode 100644
index e5e47d5..0000000
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IArticleStorage.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using BlacksmithWorkshopContracts.BindingModels;
-using BlacksmithWorkshopContracts.SearchModels;
-using BlacksmithWorkshopContracts.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BlacksmithWorkshopContracts.StoragesContracts
-{
- //класс для хранилища продуктов (изделий)
- public interface IArticleStorage
- {
- List GetFullList();
-
- List GetFilteredList(ArticleSearchModel model);
-
- ArticleViewModel? GetElement(ArticleSearchModel model);
-
- ArticleViewModel? Insert(ArticleBindingModel model);
-
- ArticleViewModel? Update(ArticleBindingModel model);
-
- ArticleViewModel? Delete(ArticleBindingModel model);
- }
-}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs
new file mode 100644
index 0000000..fedf71d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IManufactureStorage.cs
@@ -0,0 +1,27 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopContracts.StoragesContracts
+{
+ //класс для хранилища продуктов (изделий)
+ public interface IManufactureStorage
+ {
+ List GetFullList();
+
+ List GetFilteredList(ManufactureSearchModel model);
+
+ ManufactureViewModel? GetElement(ManufactureSearchModel model);
+
+ ManufactureViewModel? Insert(ManufactureBindingModel model);
+
+ ManufactureViewModel? Update(ManufactureBindingModel model);
+
+ ManufactureViewModel? Delete(ManufactureBindingModel model);
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
similarity index 71%
rename from BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
index 492114b..6dca595 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ArticleViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ManufactureViewModel.cs
@@ -9,16 +9,16 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopContracts.ViewModels
{
//класс для отображения пользователю информаци о продуктах (изделиях)
- public class ArticleViewModel : IArticleModel
+ public class ManufactureViewModel : IManufactureModel
{
public int Id { get; set; }
[DisplayName("Навание изделия")]
- public string ArticleName { get; set; } = string.Empty;
+ public string ManufactureName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
- public Dictionary ArticleWorkPiece { get; set; } = new();
+ public Dictionary ManufactureWorkPieces { get; set; } = new();
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
index 8fe2993..2101bed 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
@@ -15,10 +15,10 @@ namespace BlacksmithWorkshopContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
- public int ArticleId { get; set; }
+ public int ManufactureId { get; set; }
[DisplayName("Изделие")]
- public string ArticleName { get; set; } = string.Empty;
+ public string ManufactureName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs
similarity index 74%
rename from BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs
index b4437a5..0fcb4f0 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IArticleModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IManufactureModel.cs
@@ -7,15 +7,15 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopDataModels.Models
{
//интерфейс, отвечающий за продукт
- public interface IArticleModel : IId
+ public interface IManufactureModel : IId
{
//наименование изделия
- string ArticleName { get; }
+ string ManufactureName { get; }
//цена изделия
double Price { get; }
//словарь, хранящий пары кол-во + компонент и его цена
- Dictionary ArticleWorkPiece { get; }
+ Dictionary ManufactureWorkPieces { get; }
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
index 601726f..c36654a 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
@@ -11,7 +11,7 @@ namespace BlacksmithWorkshopDataModels.Models
public interface IOrderModel : IId
{
//id продукта
- int ArticleId { get; }
+ int ManufactureId { get; }
//кол-во продуктов
int Count { get; }
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
index b6da397..e2b2a4c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
@@ -16,7 +16,7 @@ namespace BlacksmithWorkshopListImplement
public List WorkPieces { get; set; }
//список для хранения изделий
- public List Articles { get; set; }
+ public List Manufactures { get; set; }
//список для хранения заказов
public List Orders { get; set; }
@@ -24,7 +24,7 @@ namespace BlacksmithWorkshopListImplement
public DataListSingleton()
{
WorkPieces = new List();
- Articles = new List();
+ Manufactures = new List();
Orders = new List();
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs
deleted file mode 100644
index 3e5eeb8..0000000
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ArticleStorage.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-using BlacksmithWorkshopContracts.BindingModels;
-using BlacksmithWorkshopContracts.SearchModels;
-using BlacksmithWorkshopContracts.StoragesContracts;
-using BlacksmithWorkshopContracts.ViewModels;
-using BlacksmithWorkshopListImplement.Models;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BlacksmithWorkshopListImplement.Implements
-{
- //класс, реализующий интерфейс хранилища изделий
- public class ArticleStorage : IArticleStorage
- {
- //поле для работы со списком изделий
- private readonly DataListSingleton _source;
-
- //получение в конструкторе объекта DataListSingleton
- public ArticleStorage()
- {
- _source = DataListSingleton.GetInstance();
- }
-
- //получение полного списка изделий
- public List GetFullList()
- {
- var result = new List();
-
- foreach(var article in _source.Articles)
- {
- result.Add(article.GetViewModel);
- }
-
- return result;
- }
-
- //получение отфильтрованного списка изделий
- public List GetFilteredList(ArticleSearchModel model)
- {
- var result = new List();
-
- if (string.IsNullOrEmpty(model.ArticleName))
- {
- return result;
- }
-
- foreach(var article in _source.Articles)
- {
- if(article.ArticleName.Contains(model.ArticleName))
- {
- result.Add(article.GetViewModel);
- }
- }
-
- return result;
- }
-
- //получение элемента из списка изделий
- public ArticleViewModel? GetElement(ArticleSearchModel model)
- {
- if(string.IsNullOrEmpty(model.ArticleName) && !model.Id.HasValue)
- {
- return null;
- }
-
- foreach(var article in _source.Articles)
- {
- if((!string.IsNullOrEmpty(model.ArticleName) && article.ArticleName == model.ArticleName) ||
- (model.Id.HasValue && article.Id == model.Id))
- {
- return article.GetViewModel;
- }
- }
-
- return null;
- }
-
- //при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1
- public ArticleViewModel? Insert(ArticleBindingModel model)
- {
- model.Id = 1;
-
- foreach(var article in _source.Articles)
- {
- if(model.Id <= article.Id)
- {
- model.Id = article.Id + 1;
- }
- }
-
- var newArticle = Article.Create(model);
-
- if(newArticle == null)
- {
- return null;
- }
-
- _source.Articles.Add(newArticle);
-
- return newArticle.GetViewModel;
- }
-
- //обновление изделия
- public ArticleViewModel? Update(ArticleBindingModel model)
- {
- foreach (var article in _source.Articles)
- {
- if (article.Id == model.Id)
- {
- article.Update(model);
-
- return article.GetViewModel;
- }
- }
-
- return null;
- }
-
- //удаление изделия
- public ArticleViewModel? Delete(ArticleBindingModel model)
- {
- for(int i = 0; i < _source.Articles.Count; ++i)
- {
- if (_source.Articles[i].Id == model.Id)
- {
- var element = _source.Articles[i];
- _source.Articles.RemoveAt(i);
-
- return element.GetViewModel;
- }
- }
-
- return null;
- }
- }
-}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs
new file mode 100644
index 0000000..0c27f61
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ManufactureStorage.cs
@@ -0,0 +1,138 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BlacksmithWorkshopListImplement.Implements
+{
+ //класс, реализующий интерфейс хранилища изделий
+ public class ManufactureStorage : IManufactureStorage
+ {
+ //поле для работы со списком изделий
+ private readonly DataListSingleton _source;
+
+ //получение в конструкторе объекта DataListSingleton
+ public ManufactureStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ //получение полного списка изделий
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach(var manufacture in _source.Manufactures)
+ {
+ result.Add(manufacture.GetViewModel);
+ }
+
+ return result;
+ }
+
+ //получение отфильтрованного списка изделий
+ public List GetFilteredList(ManufactureSearchModel model)
+ {
+ var result = new List();
+
+ if (string.IsNullOrEmpty(model.ManufactureName))
+ {
+ return result;
+ }
+
+ foreach(var manufacture in _source.Manufactures)
+ {
+ if(manufacture.ManufactureName.Contains(model.ManufactureName))
+ {
+ result.Add(manufacture.GetViewModel);
+ }
+ }
+
+ return result;
+ }
+
+ //получение элемента из списка изделий
+ public ManufactureViewModel? GetElement(ManufactureSearchModel model)
+ {
+ if(string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach(var manufacture in _source.Manufactures)
+ {
+ if((!string.IsNullOrEmpty(model.ManufactureName) && manufacture.ManufactureName == model.ManufactureName) ||
+ (model.Id.HasValue && manufacture.Id == model.Id))
+ {
+ return manufacture.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ //при создании изделия определяем для него новый id: ищем max id и прибавлляем к нему 1
+ public ManufactureViewModel? Insert(ManufactureBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach(var manufacture in _source.Manufactures)
+ {
+ if(model.Id <= manufacture.Id)
+ {
+ model.Id = manufacture.Id + 1;
+ }
+ }
+
+ var newManufacture = Manufacture.Create(model);
+
+ if(newManufacture == null)
+ {
+ return null;
+ }
+
+ _source.Manufactures.Add(newManufacture);
+
+ return newManufacture.GetViewModel;
+ }
+
+ //обновление изделия
+ public ManufactureViewModel? Update(ManufactureBindingModel model)
+ {
+ foreach (var manufacture in _source.Manufactures)
+ {
+ if (manufacture.Id == model.Id)
+ {
+ manufacture.Update(model);
+
+ return manufacture.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ //удаление изделия
+ public ManufactureViewModel? Delete(ManufactureBindingModel model)
+ {
+ for(int i = 0; i < _source.Manufactures.Count; ++i)
+ {
+ if (_source.Manufactures[i].Id == model.Id)
+ {
+ var element = _source.Manufactures[i];
+ _source.Manufactures.RemoveAt(i);
+
+ return element.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs
similarity index 63%
rename from BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs
rename to BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs
index d8dd647..ed71631 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Article.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs
@@ -10,54 +10,54 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Models
{
//класс реализующий интерфейс модели изделия
- public class Article : IArticleModel
+ public class Manufacture : IManufactureModel
{
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
public int Id { get; private set; }
- public string ArticleName { get; private set; } = string.Empty;
+ public string ManufactureName { get; private set; } = string.Empty;
public double Price { get; private set; }
- public Dictionary ArticleWorkPiece { get; private set; } = new Dictionary();
+ public Dictionary ManufactureWorkPieces { get; private set; } = new Dictionary();
//метод для создания объекта от класса-компонента на основе класса-BindingModel
- public static Article? Create(ArticleBindingModel? model)
+ public static Manufacture? Create(ManufactureBindingModel? model)
{
if (model == null)
{
return null;
}
- return new Article()
+ return new Manufacture()
{
Id = model.Id,
- ArticleName = model.ArticleName,
+ ManufactureName = model.ManufactureName,
Price = model.Price,
- ArticleWorkPiece = model.ArticleWorkPiece
+ ManufactureWorkPieces = model.ManufactureWorkPieces
};
}
//метод изменения существующего объекта
- public void Update(ArticleBindingModel? model)
+ public void Update(ManufactureBindingModel? model)
{
if (model == null)
{
return;
}
- ArticleName = model.ArticleName;
+ ManufactureName = model.ManufactureName;
Price = model.Price;
- ArticleWorkPiece = model.ArticleWorkPiece;
+ ManufactureWorkPieces = model.ManufactureWorkPieces;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
- public ArticleViewModel GetViewModel => new()
+ public ManufactureViewModel GetViewModel => new()
{
Id = Id,
- ArticleName = ArticleName,
+ ManufactureName = ManufactureName,
Price = Price,
- ArticleWorkPiece = ArticleWorkPiece
+ ManufactureWorkPieces = ManufactureWorkPieces
};
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
index 84272c5..2f5c338 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
@@ -17,7 +17,7 @@ namespace BlacksmithWorkshopListImplement.Models
//методы set сделали приватными, чтобы исключить неразрешённые манипуляции
public int Id { get; private set; }
- public int ArticleId { get; private set; }
+ public int ManufactureId { get; private set; }
public int Count { get; private set; }
@@ -25,7 +25,7 @@ namespace BlacksmithWorkshopListImplement.Models
public OrderStatus Status { get; private set; }
- public DateTime DateCreate { get; private set; }
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
@@ -38,12 +38,12 @@ namespace BlacksmithWorkshopListImplement.Models
return new Order()
{
- ArticleId = model.ArticleId,
+ ManufactureId = model.ManufactureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
- DateCreate = model.DateCreate, //а надо ли?
- DateImplement = model.DateImplement //а надо ли?
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
};
}
@@ -55,23 +55,23 @@ namespace BlacksmithWorkshopListImplement.Models
return;
}
- ArticleId = model.ArticleId;
+ ManufactureId = model.ManufactureId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
- DateCreate = model.DateCreate; //а надо ли?
- DateImplement = model.DateImplement; //а надо ли?
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
}
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
public OrderViewModel GetViewModel => new()
{
- ArticleId = ArticleId,
+ ManufactureId = ManufactureId,
Count = Count,
Sum = Sum,
Status = Status,
- DateCreate = DateCreate, //а надо ли?
- DateImplement = DateImplement //а надо ли?
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
};
}
}