diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.Designer.cs
new file mode 100644
index 0000000..cd05db8
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.Designer.cs
@@ -0,0 +1,145 @@
+namespace BlacksmithWorkshopView
+{
+ partial class FormFillStore
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.labelManufacture = new System.Windows.Forms.Label();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
+ this.comboBoxStore = new System.Windows.Forms.ComboBox();
+ this.labelStore = new System.Windows.Forms.Label();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(258, 100);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 9;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(177, 100);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 10;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(14, 44);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(72, 15);
+ this.labelCount.TabIndex = 7;
+ this.labelCount.Text = "Количество";
+ //
+ // labelManufacture
+ //
+ this.labelManufacture.AutoSize = true;
+ this.labelManufacture.Location = new System.Drawing.Point(14, 15);
+ this.labelManufacture.Name = "labelManufacture";
+ this.labelManufacture.Size = new System.Drawing.Size(53, 15);
+ this.labelManufacture.TabIndex = 8;
+ this.labelManufacture.Text = "Изделие";
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(109, 41);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(224, 23);
+ this.textBoxCount.TabIndex = 6;
+ //
+ // comboBoxManufacture
+ //
+ this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxManufacture.FormattingEnabled = true;
+ this.comboBoxManufacture.Location = new System.Drawing.Point(109, 12);
+ this.comboBoxManufacture.Name = "comboBoxManufacture";
+ this.comboBoxManufacture.Size = new System.Drawing.Size(224, 23);
+ this.comboBoxManufacture.TabIndex = 5;
+ //
+ // comboBoxStore
+ //
+ this.comboBoxStore.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxStore.FormattingEnabled = true;
+ this.comboBoxStore.Location = new System.Drawing.Point(109, 71);
+ this.comboBoxStore.Name = "comboBoxStore";
+ this.comboBoxStore.Size = new System.Drawing.Size(224, 23);
+ this.comboBoxStore.TabIndex = 5;
+ //
+ // labelStore
+ //
+ this.labelStore.AutoSize = true;
+ this.labelStore.Location = new System.Drawing.Point(14, 74);
+ this.labelStore.Name = "labelStore";
+ this.labelStore.Size = new System.Drawing.Size(54, 15);
+ this.labelStore.TabIndex = 8;
+ this.labelStore.Text = "Магазин";
+ //
+ // FormFillStore
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(348, 130);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelStore);
+ this.Controls.Add(this.labelManufacture);
+ this.Controls.Add(this.comboBoxStore);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxManufacture);
+ this.Name = "FormFillStore";
+ this.Text = "Пополнение магазина";
+ this.Load += new System.EventHandler(this.FormFillStore_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private Label labelCount;
+ private Label labelManufacture;
+ private TextBox textBoxCount;
+ private ComboBox comboBoxManufacture;
+ private ComboBox comboBoxStore;
+ private Label labelStore;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.cs
new file mode 100644
index 0000000..1ec6a37
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.cs
@@ -0,0 +1,88 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormFillStore : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreLogic _logicS;
+ private readonly IManufactureLogic _logicM;
+ public FormFillStore(ILogger logger, IStoreLogic logicS, IManufactureLogic logicM)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicS = logicS;
+ _logicM = logicM;
+ }
+ private void FormFillStore_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка магазинов и изделий");
+ var listS = _logicS.ReadList(null);
+ if (listS != null)
+ {
+ comboBoxStore.DisplayMember = "StoreName";
+ comboBoxStore.ValueMember = "Id";
+ comboBoxStore.DataSource = listS;
+ comboBoxStore.SelectedItem = null;
+ }
+ var listM = _logicM.ReadList(null);
+ if (listM != null)
+ {
+ comboBoxManufacture.DisplayMember = "ManufactureName";
+ comboBoxManufacture.ValueMember = "Id";
+ comboBoxManufacture.DataSource = listM;
+ comboBoxManufacture.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (comboBoxStore.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxManufacture.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Пополнение магазина");
+ try
+ {
+ var addedManufacture = _logicM.ReadElement(new ManufactureSearchModel
+ {
+ Id = Convert.ToInt32(comboBoxManufacture.SelectedValue)
+ });
+ if (addedManufacture == null)
+ {
+ return;
+ }
+ var operationResult = _logicS.AddManufacture(addedManufacture, new StoreSearchModel
+ {
+ Id = Convert.ToInt32(comboBoxStore.SelectedValue)
+ }, Convert.ToInt32(textBoxCount.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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormFillStore.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
index 747545a..c593b65 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -28,139 +28,161 @@
///
private void InitializeComponent()
{
- this.menuStrip = new System.Windows.Forms.MenuStrip();
- this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.dataGridView = new System.Windows.Forms.DataGridView();
- this.buttonCreateOrder = new System.Windows.Forms.Button();
- this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
- this.buttonOrderReady = new System.Windows.Forms.Button();
- this.buttonIssuedOrder = new System.Windows.Forms.Button();
- this.buttonRef = new System.Windows.Forms.Button();
- this.menuStrip.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
- this.SuspendLayout();
- this.Load += new System.EventHandler(this.FormMain_Load);
- //
- // menuStrip
- //
- this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.storesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonCreateOrder = new System.Windows.Forms.Button();
+ this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
+ this.buttonOrderReady = new System.Windows.Forms.Button();
+ this.buttonIssuedOrder = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonFillStore = new System.Windows.Forms.Button();
+ this.menuStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // menuStrip
+ //
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refbooksToolStripMenuItem});
- this.menuStrip.Location = new System.Drawing.Point(0, 0);
- this.menuStrip.Name = "menuStrip";
- this.menuStrip.Size = new System.Drawing.Size(1108, 24);
- this.menuStrip.TabIndex = 0;
- this.menuStrip.Text = "menuStrip1";
- //
- // refbooksToolStripMenuItem
- //
- this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(1108, 24);
+ this.menuStrip.TabIndex = 0;
+ this.menuStrip.Text = "menuStrip1";
+ //
+ // refbooksToolStripMenuItem
+ //
+ this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
- this.manufacturesToolStripMenuItem});
- this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem";
- this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
- this.refbooksToolStripMenuItem.Text = "Справочники";
- //
- // componentsToolStripMenuItem
- //
- this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
- this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
- this.componentsToolStripMenuItem.Text = "Компоненты";
- this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
- //
- // manufacturesToolStripMenuItem
- //
- this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
- this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
- this.manufacturesToolStripMenuItem.Text = "Изделия";
- this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
- //
- // dataGridView
- //
- this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
- this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView.Location = new System.Drawing.Point(12, 27);
- this.dataGridView.Name = "dataGridView";
- this.dataGridView.RowTemplate.Height = 25;
- this.dataGridView.Size = new System.Drawing.Size(795, 456);
- this.dataGridView.TabIndex = 1;
- //
- // buttonCreateOrder
- //
- this.buttonCreateOrder.Location = new System.Drawing.Point(813, 27);
- this.buttonCreateOrder.Name = "buttonCreateOrder";
- this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23);
- this.buttonCreateOrder.TabIndex = 2;
- this.buttonCreateOrder.Text = "Создать заказ";
- this.buttonCreateOrder.UseVisualStyleBackColor = true;
- this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
- //
- // buttonTakeOrderInWork
- //
- this.buttonTakeOrderInWork.Location = new System.Drawing.Point(813, 56);
- this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
- this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23);
- this.buttonTakeOrderInWork.TabIndex = 2;
- this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
- this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
- this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
- //
- // buttonOrderReady
- //
- this.buttonOrderReady.Location = new System.Drawing.Point(813, 85);
- this.buttonOrderReady.Name = "buttonOrderReady";
- this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonOrderReady.Size = new System.Drawing.Size(283, 23);
- this.buttonOrderReady.TabIndex = 2;
- this.buttonOrderReady.Text = "Заказ готов";
- this.buttonOrderReady.UseVisualStyleBackColor = true;
- this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
- //
- // buttonIssuedOrder
- //
- this.buttonIssuedOrder.Location = new System.Drawing.Point(814, 114);
- this.buttonIssuedOrder.Name = "buttonIssuedOrder";
- this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23);
- this.buttonIssuedOrder.TabIndex = 2;
- this.buttonIssuedOrder.Text = "Заказ выдан";
- this.buttonIssuedOrder.UseVisualStyleBackColor = true;
- this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
- //
- // buttonRef
- //
- this.buttonRef.Location = new System.Drawing.Point(813, 143);
- this.buttonRef.Name = "buttonRef";
- this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonRef.Size = new System.Drawing.Size(283, 23);
- this.buttonRef.TabIndex = 2;
- this.buttonRef.Text = "Обновить список";
- this.buttonRef.UseVisualStyleBackColor = true;
- this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
- //
- // FormMain
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1108, 504);
- this.Controls.Add(this.buttonRef);
- this.Controls.Add(this.buttonIssuedOrder);
- this.Controls.Add(this.buttonOrderReady);
- this.Controls.Add(this.buttonTakeOrderInWork);
- this.Controls.Add(this.buttonCreateOrder);
- this.Controls.Add(this.dataGridView);
- this.Controls.Add(this.menuStrip);
- this.MainMenuStrip = this.menuStrip;
- this.Name = "FormMain";
- this.Text = "Кузнечная мастерская";
- this.menuStrip.ResumeLayout(false);
- this.menuStrip.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
+ this.manufacturesToolStripMenuItem,
+ this.storesToolStripMenuItem});
+ this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem";
+ this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
+ this.refbooksToolStripMenuItem.Text = "Справочники";
+ //
+ // componentsToolStripMenuItem
+ //
+ this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
+ this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.componentsToolStripMenuItem.Text = "Компоненты";
+ this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
+ //
+ // manufacturesToolStripMenuItem
+ //
+ this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
+ this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.manufacturesToolStripMenuItem.Text = "Изделия";
+ this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
+ //
+ // storesToolStripMenuItem
+ //
+ this.storesToolStripMenuItem.Name = "storesToolStripMenuItem";
+ this.storesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.storesToolStripMenuItem.Text = "Магазины";
+ this.storesToolStripMenuItem.Click += new System.EventHandler(this.StoresToolStripMenuItem_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 27);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(795, 456);
+ this.dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ this.buttonCreateOrder.Location = new System.Drawing.Point(813, 27);
+ this.buttonCreateOrder.Name = "buttonCreateOrder";
+ this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23);
+ this.buttonCreateOrder.TabIndex = 2;
+ this.buttonCreateOrder.Text = "Создать заказ";
+ this.buttonCreateOrder.UseVisualStyleBackColor = true;
+ this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
+ //
+ // buttonTakeOrderInWork
+ //
+ this.buttonTakeOrderInWork.Location = new System.Drawing.Point(813, 56);
+ this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
+ this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23);
+ this.buttonTakeOrderInWork.TabIndex = 2;
+ this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
+ this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
+ this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // buttonOrderReady
+ //
+ this.buttonOrderReady.Location = new System.Drawing.Point(813, 85);
+ this.buttonOrderReady.Name = "buttonOrderReady";
+ this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonOrderReady.Size = new System.Drawing.Size(283, 23);
+ this.buttonOrderReady.TabIndex = 2;
+ this.buttonOrderReady.Text = "Заказ готов";
+ this.buttonOrderReady.UseVisualStyleBackColor = true;
+ this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // buttonIssuedOrder
+ //
+ this.buttonIssuedOrder.Location = new System.Drawing.Point(814, 114);
+ this.buttonIssuedOrder.Name = "buttonIssuedOrder";
+ this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23);
+ this.buttonIssuedOrder.TabIndex = 2;
+ this.buttonIssuedOrder.Text = "Заказ выдан";
+ this.buttonIssuedOrder.UseVisualStyleBackColor = true;
+ this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(813, 143);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonRef.Size = new System.Drawing.Size(283, 23);
+ this.buttonRef.TabIndex = 2;
+ this.buttonRef.Text = "Обновить список";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonFillStore
+ //
+ this.buttonFillStore.Location = new System.Drawing.Point(813, 172);
+ this.buttonFillStore.Name = "buttonFillStore";
+ this.buttonFillStore.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.buttonFillStore.Size = new System.Drawing.Size(283, 23);
+ this.buttonFillStore.TabIndex = 2;
+ this.buttonFillStore.Text = "Пополнить магазин";
+ this.buttonFillStore.UseVisualStyleBackColor = true;
+ this.buttonFillStore.Click += new System.EventHandler(this.ButtonFillStore_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1108, 504);
+ this.Controls.Add(this.buttonFillStore);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonIssuedOrder);
+ this.Controls.Add(this.buttonOrderReady);
+ this.Controls.Add(this.buttonTakeOrderInWork);
+ this.Controls.Add(this.buttonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
+ this.Name = "FormMain";
+ this.Text = "Кузнечная мастерская";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -176,5 +198,7 @@
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
- }
+ private ToolStripMenuItem storesToolStripMenuItem;
+ private Button buttonFillStore;
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
index ad836a4..2b86baf 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -146,5 +146,21 @@ namespace BlacksmithWorkshopView
{
LoadData();
}
- }
+ private void StoresToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStores));
+ if (service is FormStores form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void ButtonFillStore_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormFillStore));
+ if (service is FormFillStore form)
+ {
+ form.ShowDialog();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.Designer.cs
new file mode 100644
index 0000000..79e5adf
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.Designer.cs
@@ -0,0 +1,184 @@
+namespace BlacksmithWorkshopView
+{
+ partial class FormStore
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.labelAddress = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.textBoxAddress = new System.Windows.Forms.TextBox();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.labelOpeningDate = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.buttonCancel.Location = new System.Drawing.Point(316, 41);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = System.Windows.Forms.AnchorStyles.Top;
+ this.buttonSave.Location = new System.Drawing.Point(316, 12);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 8;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // labelAddress
+ //
+ this.labelAddress.AutoSize = true;
+ this.labelAddress.Location = new System.Drawing.Point(17, 44);
+ this.labelAddress.Name = "labelAddress";
+ this.labelAddress.Size = new System.Drawing.Size(40, 15);
+ this.labelAddress.TabIndex = 5;
+ this.labelAddress.Text = "Адрес";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(17, 15);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(59, 15);
+ this.labelName.TabIndex = 6;
+ this.labelName.Text = "Название";
+ //
+ // textBoxAddress
+ //
+ this.textBoxAddress.Location = new System.Drawing.Point(82, 41);
+ this.textBoxAddress.Name = "textBoxAddress";
+ this.textBoxAddress.Size = new System.Drawing.Size(228, 23);
+ this.textBoxAddress.TabIndex = 3;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(82, 12);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(228, 23);
+ this.textBoxName.TabIndex = 4;
+ //
+ // dateTimePicker
+ //
+ this.dateTimePicker.Location = new System.Drawing.Point(110, 76);
+ this.dateTimePicker.Name = "dateTimePicker";
+ this.dateTimePicker.Size = new System.Drawing.Size(200, 23);
+ this.dateTimePicker.TabIndex = 9;
+ //
+ // labelOpeningDate
+ //
+ this.labelOpeningDate.AutoSize = true;
+ this.labelOpeningDate.Location = new System.Drawing.Point(17, 76);
+ this.labelOpeningDate.Name = "labelOpeningDate";
+ this.labelOpeningDate.Size = new System.Drawing.Size(87, 15);
+ this.labelOpeningDate.TabIndex = 5;
+ this.labelOpeningDate.Text = "Дата открытия";
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnManufactureName,
+ this.ColumnPrice,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(17, 118);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(608, 450);
+ this.dataGridView.TabIndex = 10;
+ //
+ // ColumnManufactureName
+ //
+ this.ColumnManufactureName.HeaderText = "Название";
+ this.ColumnManufactureName.Name = "ColumnManufactureName";
+ //
+ // ColumnPrice
+ //
+ this.ColumnPrice.HeaderText = "Цена";
+ this.ColumnPrice.Name = "ColumnPrice";
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.Name = "ColumnCount";
+ //
+ // FormStore
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(641, 594);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.dateTimePicker);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.labelOpeningDate);
+ this.Controls.Add(this.labelAddress);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.textBoxAddress);
+ this.Controls.Add(this.textBoxName);
+ this.Name = "FormStore";
+ this.Text = "Магазин";
+ this.Load += new System.EventHandler(this.FormStore_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private Label labelAddress;
+ private Label labelName;
+ private TextBox textBoxAddress;
+ private TextBox textBoxName;
+ private DateTimePicker dateTimePicker;
+ private Label labelOpeningDate;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ColumnManufactureName;
+ private DataGridViewTextBoxColumn ColumnPrice;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.cs
new file mode 100644
index 0000000..1242c50
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.cs
@@ -0,0 +1,123 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System.Reflection;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormStore : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreLogic _logicS;
+ private readonly IComponentLogic _logicC;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormStore(ILogger logger, IStoreLogic logicS, IComponentLogic logicC)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicS = logicS;
+ _logicC = logicC;
+ }
+ private void FormStore_Load(object sender, EventArgs e)
+ {
+ dataGridView.Columns["ColumnManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение магазина");
+ var view = _logicS.ReadElement(new StoreSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.StoreName;
+ textBoxAddress.Text = view.Address;
+ dateTimePicker.Value = view.OpeningDate;
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ if (_id == null)
+ {
+ return;
+ }
+ try
+ {
+ var list = _logicS.ReadElement(new StoreSearchModel
+ {
+ Id = _id.Value
+ })?.Manufactures;
+ if (list != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var el in list)
+ {
+ dataGridView.Rows.Add(new object[] { el.Value.Item1.ManufactureName, el.Value.Item1.Price, el.Value.Item2 });
+ }
+ }
+ _logger.LogInformation("Загрузка компонентов");
+ }
+ 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;
+ }
+ if (string.IsNullOrEmpty(textBoxAddress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение магазина");
+ try
+ {
+ var model = new StoreBindingModel
+ {
+ Id = _id ?? 0,
+ StoreName = textBoxName.Text,
+ Address = textBoxAddress.Text,
+ OpeningDate = dateTimePicker.Value
+ };
+ var operationResult = _id.HasValue ? _logicS.Update(model) : _logicS.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.resx
new file mode 100644
index 0000000..4c685dc
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStore.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/FormStores.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.Designer.cs
new file mode 100644
index 0000000..f367a32
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.Designer.cs
@@ -0,0 +1,115 @@
+namespace BlacksmithWorkshopView
+{
+ partial class FormStores
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.Windows.Forms.Button buttonRef;
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ buttonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ this.Load += new System.EventHandler(this.FormStores_Load);
+ //
+ // buttonRef
+ //
+ buttonRef.Location = new System.Drawing.Point(620, 99);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new System.Drawing.Size(174, 23);
+ buttonRef.TabIndex = 3;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(620, 70);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(174, 23);
+ this.buttonDel.TabIndex = 4;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(620, 41);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(174, 23);
+ this.buttonUpd.TabIndex = 5;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(620, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(174, 23);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(6, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(608, 450);
+ this.dataGridView.TabIndex = 2;
+ //
+ // FormStores
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormStores";
+ this.Text = "Магазины";
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.cs
new file mode 100644
index 0000000..217a1ee
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.cs
@@ -0,0 +1,100 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormStores : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreLogic _logic;
+ public FormStores(ILogger logger, IStoreLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormStores_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["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["Manufactures"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStore));
+ if (service is FormStore 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(FormStore));
+ if (service is FormStore form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление магазина");
+ try
+ {
+ if (!_logic.Delete(new StoreBindingModel
+ {
+ 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/FormStores.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.resx
new file mode 100644
index 0000000..fa1d9b6
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormStores.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ False
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index 49a2371..f025d7e 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -1,5 +1,7 @@
+using BlacksmithWorkshopBusinessLogic.BusinessLogics;
using BlacksmithWorkShopBusinessLogic.BusinessLogics;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopFileImplement.Implements;
using BlacksmithWorkshopView;
@@ -34,16 +36,21 @@ namespace BlacksmithWorkshopView
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
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/BusinessLogics/StoreLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs
new file mode 100644
index 0000000..1024bc3
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/StoreLogic.cs
@@ -0,0 +1,155 @@
+using BlacksmithWorkShopBusinessLogic.BusinessLogics;
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
+{
+ public class StoreLogic : IStoreLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreStorage _storeStorage;
+ public StoreLogic(ILogger logger, IStoreStorage storeStorage)
+ {
+ _logger = logger;
+ _storeStorage = storeStorage;
+ }
+ public List? ReadList(StoreSearchModel? model)
+ {
+ _logger.LogInformation("Readlist. StoreName: {Storename}. Id: {Id}", model?.StoreName, model?.Id);
+ var list = model == null ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("Readlist. Count: {Count}", list.Count);
+ return list;
+ }
+ public StoreViewModel? ReadElement(StoreSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. StoreName: {StoreName}. Id: {Id}", model.StoreName, model.Id);
+ var element = _storeStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
+ return element;
+ }
+ public bool Create(StoreBindingModel model)
+ {
+ CheckModel(model);
+ if (_storeStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(StoreBindingModel model)
+ {
+ CheckModel(model);
+ if (_storeStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(StoreBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_storeStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void SaveChanges(StoreViewModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ _storeStorage.Update(new StoreBindingModel()
+ {
+ StoreName = model.StoreName,
+ Address = model.Address,
+ OpeningDate = model.OpeningDate,
+ Manufactures = model.Manufactures,
+ });
+ }
+ public bool AddManufacture(IManufactureModel manufacture, StoreSearchModel model, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException("Невозможно найти магазин", nameof(model));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentException("Количество добавляемых изделий должно быть больше нуля");
+ }
+ _logger.LogInformation("Adding manufacture {manufacture} in store {store}. Id = {id}", manufacture.ManufactureName, model.StoreName, model.Id);
+ //ищем магазин
+ StoreViewModel? selectedStore = _storeStorage.GetElement(model);
+ if (selectedStore == null)
+ {
+ _logger.LogWarning("Store with id {Id} not found", model.Id);
+ return false;
+ }
+ //ищем изделие в магазине
+ if (selectedStore.Manufactures.TryGetValue(manufacture.Id, out var manufactureInStore))
+ {
+ selectedStore.Manufactures[manufacture.Id] = (manufacture, manufactureInStore.Item2 + count);//если изделие уже есть в магазине, увеличиваем его количество
+ _logger.LogInformation("Filled store Id = {storeId} with manufacture Id = {manufactureId}. Count = {count}", model.Id, manufacture.Id, count);
+ SaveChanges(selectedStore);
+ return true;
+ }
+ //иначе добавляем изделие в магазин в указанном количестве
+ selectedStore.Manufactures.Add(manufacture.Id, (manufacture, count));
+ SaveChanges(selectedStore);
+ _logger.LogInformation("Added new manufacture Id = {manufactureId} in store Id = {storeId}. Count = {count}", manufacture.Id, model.Id, count);
+ return true;
+ }
+ private void CheckModel(StoreBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName));
+ }
+ if (string.IsNullOrEmpty(model.Address))
+ {
+ throw new ArgumentNullException("Нет адреса магазина", nameof(model.StoreName));
+ }
+ _logger.LogInformation("Store. StoreName: {StoreName}. Address: {Address}. Id: {Id}", model.StoreName, model.Address, model.Id);
+ var element = _storeStorage.GetElement(new StoreSearchModel//проверка на уникальность
+ {
+ StoreName = model.StoreName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/StoreBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/StoreBindingModel.cs
new file mode 100644
index 0000000..054387c
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/StoreBindingModel.cs
@@ -0,0 +1,16 @@
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopContracts.BindingModels
+{
+ public class StoreBindingModel : IStoreModel
+ {
+ public int Id { get; set; }
+ public string StoreName { get; set; } = string.Empty;
+ public string Address { get; set; } = string.Empty;
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+ ///
+ /// Изделия в магазине
+ ///
+ public Dictionary Manufactures { get; set; } = new();
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs
new file mode 100644
index 0000000..d0941d2
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IStoreLogic.cs
@@ -0,0 +1,24 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
+{
+ public interface IStoreLogic
+ {
+ List? ReadList(StoreSearchModel? model);
+ StoreViewModel? ReadElement(StoreSearchModel model);
+ bool Create(StoreBindingModel model);
+ bool Update(StoreBindingModel model);
+ bool Delete(StoreBindingModel model);
+ ///
+ /// Добавление изделия в магазин
+ ///
+ /// Изделие
+ /// Модель для поиска нужного магазина
+ /// Количество изделий
+ ///
+ bool AddManufacture(IManufactureModel manufacture, StoreSearchModel model, int count);
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/StoreSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/StoreSearchModel.cs
new file mode 100644
index 0000000..3e4ddc9
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/StoreSearchModel.cs
@@ -0,0 +1,8 @@
+namespace BlacksmithWorkshopContracts.SearchModels
+{
+ public class StoreSearchModel
+ {
+ public int? Id { get; set; }
+ public string? StoreName { get; set; }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs
new file mode 100644
index 0000000..2eab6c8
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IStoreStorage.cs
@@ -0,0 +1,17 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopContracts.StoragesContracts
+{
+ public interface IStoreStorage
+ {
+ List GetFullList();
+ List GetFilteredList(StoreSearchModel model);
+ StoreViewModel? GetElement(StoreSearchModel model);
+ StoreViewModel? Insert(StoreBindingModel model);
+ StoreViewModel? Update(StoreBindingModel model);
+ StoreViewModel? Delete(StoreBindingModel model);
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/StoreViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/StoreViewModel.cs
new file mode 100644
index 0000000..b7675d2
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/StoreViewModel.cs
@@ -0,0 +1,21 @@
+using BlacksmithWorkshopDataModels.Models;
+using System.ComponentModel;
+
+namespace BlacksmithWorkshopContracts.ViewModels
+{
+ public class StoreViewModel : IStoreModel
+ {
+ [DisplayName("Номер магазина")]
+ public int Id { get; set; }
+ [DisplayName("Название магазина")]
+ public string StoreName { get; set; } = string.Empty;
+ [DisplayName("Адрес магазина")]
+ public string Address { get; set; } = string.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+ ///
+ /// Изделия в магазине
+ ///
+ public Dictionary Manufactures { get; set; } = new();
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IStoreModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IStoreModel.cs
new file mode 100644
index 0000000..cf653ec
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IStoreModel.cs
@@ -0,0 +1,10 @@
+namespace BlacksmithWorkshopDataModels.Models
+{
+ public interface IStoreModel : IId
+ {
+ string StoreName { get; }
+ string Address { get; }
+ DateTime OpeningDate { get; }
+ Dictionary Manufactures { get; }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
index fef796c..a33d3c2 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
@@ -8,11 +8,13 @@ namespace BlacksmithWorkshopListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Manufactures { get; set; }
+ public List Stores { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Manufactures = new List();
+ Stores = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs
new file mode 100644
index 0000000..3fb8c5d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/StoreStorage.cs
@@ -0,0 +1,104 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using BlacksmithWorkshopListImplement;
+using BlacksmithWorkshopListImplement.Models;
+
+namespace BlacksmithWorkshopListImplement.Implements
+{
+ public class StoreStorage : IStoreStorage
+ {
+ private readonly DataListSingleton _source;
+ public StoreStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var store in _source.Stores)
+ {
+ result.Add(store.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(StoreSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ return result;
+ }
+ foreach (var store in _source.Stores)
+ {
+ if (store.StoreName.Contains(model.StoreName ?? string.Empty))
+ {
+ result.Add(store.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public StoreViewModel? GetElement(StoreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var store in _source.Stores)
+ {
+ if ((!string.IsNullOrEmpty(model.StoreName) &&
+ store.StoreName == model.StoreName) ||
+ (model.Id.HasValue && store.Id == model.Id))
+ {
+ return store.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public StoreViewModel? Insert(StoreBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var store in _source.Stores)
+ {
+ if (model.Id <= store.Id)
+ {
+ model.Id = store.Id + 1;
+ }
+ }
+ var newStore = Store.Create(model);
+ if (newStore == null)
+ {
+ return null;
+ }
+ _source.Stores.Add(newStore);
+ return newStore.GetViewModel;
+ }
+ public StoreViewModel? Update(StoreBindingModel model)
+ {
+ foreach (var store in _source.Stores)
+ {
+ if (store.Id == model.Id)
+ {
+ store.Update(model);
+ return store.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public StoreViewModel? Delete(StoreBindingModel model)
+ {
+ for (int i = 0; i < _source.Stores.Count; ++i)
+ {
+ if (_source.Stores[i].Id == model.Id)
+ {
+ var element = _source.Stores[i];
+ _source.Stores.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Store.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Store.cs
new file mode 100644
index 0000000..28ce5d2
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Store.cs
@@ -0,0 +1,49 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopListImplement.Models
+{
+ public class Store : IStoreModel
+ {
+ public int Id { get; private set; }
+ public string StoreName { get; private set; } = string.Empty;
+ public string Address { get; private set; } = string.Empty;
+ public DateTime OpeningDate { get; private set; }
+ public Dictionary Manufactures { get; private set; } = new();
+ public static Store? Create(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Store()
+ {
+ Id = model.Id,
+ StoreName = model.StoreName,
+ Address = model.Address,
+ OpeningDate = model.OpeningDate,
+ Manufactures = new()
+ };
+ }
+ public void Update(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ StoreName = model.StoreName;
+ Address = model.Address;
+ OpeningDate = model.OpeningDate;
+ Manufactures = model.Manufactures;
+ }
+ public StoreViewModel GetViewModel => new()
+ {
+ Id = Id,
+ StoreName = StoreName,
+ Address = Address,
+ OpeningDate = OpeningDate,
+ Manufactures = Manufactures
+ };
+ }
+}