diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.Designer.cs
new file mode 100644
index 0000000..cf38cf6
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.Designer.cs
@@ -0,0 +1,151 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormAddReinforcedInShop
+ {
+ ///
+ /// 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.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
+ this.comboBoxReinforced = new System.Windows.Forms.ComboBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.comboBoxShop = new System.Windows.Forms.ComboBox();
+ this.label1 = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(355, 99);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 17;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSave.Location = new System.Drawing.Point(274, 99);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 16;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // numericUpDownCount
+ //
+ this.numericUpDownCount.Location = new System.Drawing.Point(208, 64);
+ this.numericUpDownCount.Maximum = new decimal(new int[] {
+ 1410065408,
+ 2,
+ 0,
+ 0});
+ this.numericUpDownCount.Name = "numericUpDownCount";
+ this.numericUpDownCount.Size = new System.Drawing.Size(221, 23);
+ this.numericUpDownCount.TabIndex = 15;
+ //
+ // comboBoxReinforced
+ //
+ this.comboBoxReinforced.FormattingEnabled = true;
+ this.comboBoxReinforced.Location = new System.Drawing.Point(207, 37);
+ this.comboBoxReinforced.Name = "comboBoxReinforced";
+ this.comboBoxReinforced.Size = new System.Drawing.Size(222, 23);
+ this.comboBoxReinforced.TabIndex = 14;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(126, 66);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(75, 15);
+ this.label3.TabIndex = 13;
+ this.label3.Text = "Количество:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(5, 40);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(196, 15);
+ this.label2.TabIndex = 12;
+ this.label2.Text = "Изделие которое нужно добавить:";
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.FormattingEnabled = true;
+ this.comboBoxShop.Location = new System.Drawing.Point(207, 10);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(222, 23);
+ this.comboBoxShop.TabIndex = 11;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(77, 13);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(124, 15);
+ this.label1.TabIndex = 10;
+ this.label1.Text = "Выбранный магазин:";
+ //
+ // FormAddReinforcedInShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(444, 134);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.numericUpDownCount);
+ this.Controls.Add(this.comboBoxReinforced);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.label1);
+ this.Name = "FormAddReinforcedInShop";
+ this.Text = "Добавить изделие в магазин";
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private NumericUpDown numericUpDownCount;
+ private ComboBox comboBoxReinforced;
+ private Label label3;
+ private Label label2;
+ private ComboBox comboBoxShop;
+ private Label label1;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.cs
new file mode 100644
index 0000000..a860bf6
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.cs
@@ -0,0 +1,90 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormAddReinforcedInShop : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _shopLogic;
+ private readonly IReinforcedLogic _reinforcedLogic;
+ private readonly List? _listShops;
+ private readonly List? _listReinforceds;
+
+ public FormAddReinforcedInShop(ILogger logger, IShopLogic shopLogic, IReinforcedLogic reinforcedLogic)
+ {
+ InitializeComponent();
+ _shopLogic = shopLogic;
+ _reinforcedLogic = reinforcedLogic;
+ _logger = logger;
+ _listShops = shopLogic.ReadList(null);
+ if (_listShops != null)
+ {
+ comboBoxShop.DisplayMember = "Name";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = _listShops;
+ comboBoxShop.SelectedItem = null;
+ }
+
+ _listReinforceds = reinforcedLogic.ReadList(null);
+ if (_listReinforceds != null)
+ {
+ comboBoxReinforced.DisplayMember = "ReinforcedName";
+ comboBoxReinforced.ValueMember = "Id";
+ comboBoxReinforced.DataSource = _listReinforceds;
+ comboBoxReinforced.SelectedItem = null;
+ }
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxReinforced.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Добавление изделия в магазин");
+ try
+ {
+ var reinforced = _reinforcedLogic.ReadElement(new()
+ {
+ Id = (int)comboBoxReinforced.SelectedValue
+ });
+ if (reinforced == null)
+ {
+ throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
+ }
+ var resultOperation = _shopLogic.AddReinforced(
+ model: new() { Id = (int)comboBoxShop.SelectedValue },
+ reinforced: reinforced,
+ count: (int)numericUpDownCount.Value
+ );
+ if (!resultOperation)
+ {
+ 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/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormAddReinforcedInShop.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/PrecastConcretePlant/PrecastConcretePlant/FormComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormComponent.Designer.cs
index 9285128..8f64057 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormComponent.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormComponent.Designer.cs
@@ -100,7 +100,7 @@
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormComponent";
- this.Text = "FormComponent";
+ this.Text = "Компонент";
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormComponents.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.Designer.cs
index cbc6613..bf4819b 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormComponents.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormComponents.Designer.cs
@@ -103,7 +103,7 @@
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormComponents";
- this.Text = "FormComponents";
+ this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs
index 1fce33c..68ebddd 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormCreateOrder.Designer.cs
@@ -126,7 +126,7 @@
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FormCreateOrder";
- this.Text = "FormCreateOrder";
+ this.Text = "Создать заказ";
((System.ComponentModel.ISupportInitialize)(this.textBoxCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
index a2e34f9..4908d6e 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
@@ -38,6 +38,8 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reinforcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.buttonAddReinforcedInShop = new System.Windows.Forms.Button();
+ this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -45,7 +47,7 @@
// buttonRef
//
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRef.Location = new System.Drawing.Point(823, 294);
+ this.buttonRef.Location = new System.Drawing.Point(840, 276);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(147, 32);
this.buttonRef.TabIndex = 12;
@@ -56,7 +58,7 @@
// buttonFinish
//
this.buttonFinish.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonFinish.Location = new System.Drawing.Point(823, 235);
+ this.buttonFinish.Location = new System.Drawing.Point(840, 217);
this.buttonFinish.Name = "buttonFinish";
this.buttonFinish.Size = new System.Drawing.Size(147, 32);
this.buttonFinish.TabIndex = 11;
@@ -67,7 +69,7 @@
// buttonReady
//
this.buttonReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonReady.Location = new System.Drawing.Point(823, 177);
+ this.buttonReady.Location = new System.Drawing.Point(840, 159);
this.buttonReady.Name = "buttonReady";
this.buttonReady.Size = new System.Drawing.Size(147, 32);
this.buttonReady.TabIndex = 10;
@@ -78,7 +80,7 @@
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonTakeOrderInWork.Location = new System.Drawing.Point(823, 118);
+ this.buttonTakeOrderInWork.Location = new System.Drawing.Point(840, 100);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 32);
this.buttonTakeOrderInWork.TabIndex = 9;
@@ -89,7 +91,7 @@
// buttonCreateOrder
//
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonCreateOrder.Location = new System.Drawing.Point(823, 59);
+ this.buttonCreateOrder.Location = new System.Drawing.Point(840, 41);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(147, 32);
this.buttonCreateOrder.TabIndex = 8;
@@ -123,7 +125,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.reinforcedToolStripMenuItem,
- this.componentToolStripMenuItem});
+ this.componentToolStripMenuItem,
+ this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -142,11 +145,30 @@
this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
+ // buttonAddReinforcedInShop
+ //
+ this.buttonAddReinforcedInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(840, 337);
+ this.buttonAddReinforcedInShop.Name = "buttonAddReinforcedInShop";
+ this.buttonAddReinforcedInShop.Size = new System.Drawing.Size(147, 31);
+ this.buttonAddReinforcedInShop.TabIndex = 14;
+ this.buttonAddReinforcedInShop.Text = "Пополнение магазина";
+ this.buttonAddReinforcedInShop.UseVisualStyleBackColor = true;
+ this.buttonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click);
+ //
+ // магазиныToolStripMenuItem
+ //
+ this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.магазиныToolStripMenuItem.Text = "Магазины";
+ this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(999, 389);
+ this.Controls.Add(this.buttonAddReinforcedInShop);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonFinish);
@@ -155,7 +177,7 @@
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Name = "FormMain";
- this.Text = "FormMain";
+ this.Text = "Заказы";
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
@@ -176,5 +198,7 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem reinforcedToolStripMenuItem;
private ToolStripMenuItem componentToolStripMenuItem;
+ private Button buttonAddReinforcedInShop;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
index 6961b10..3c41bda 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
@@ -63,8 +63,7 @@ namespace PrecastConcretePlantView
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
- var service =
- Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
@@ -106,7 +105,8 @@ namespace PrecastConcretePlantView
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
- Id = id
+ Id = id,
+ Status = orderStatus
});
if (!operationResult)
{
@@ -152,5 +152,23 @@ namespace PrecastConcretePlantView
{
LoadData();
}
+
+ private void ShopsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormViewShops));
+ if (service is FormViewShops form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void ButtonAddReinforcedInShop_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormAddReinforcedInShop));
+ if (service is FormAddReinforcedInShop form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.Designer.cs
index bda4a1c..910c8e6 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforced.Designer.cs
@@ -239,7 +239,7 @@
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Name = "FormReinforced";
- this.Text = "FormReinforced";
+ this.Text = "Изделие";
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedComponent.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedComponent.Designer.cs
index 1e52690..718ed6f 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedComponent.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedComponent.Designer.cs
@@ -101,7 +101,7 @@
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelReinforced);
this.Name = "FormReinforcedComponent";
- this.Text = "FormReinforcedComponent";
+ this.Text = "Компонент изделия";
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs
new file mode 100644
index 0000000..035854b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs
@@ -0,0 +1,186 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormShop
+ {
+ ///
+ /// 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.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.textBoxAddress = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ReinforcedName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.comboBoxShop = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.dateTimePickerOpening = new System.Windows.Forms.DateTimePicker();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSave.Location = new System.Drawing.Point(496, 285);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(120, 22);
+ this.buttonSave.TabIndex = 17;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(622, 284);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(103, 23);
+ this.buttonCancel.TabIndex = 16;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // textBoxAddress
+ //
+ this.textBoxAddress.Location = new System.Drawing.Point(159, 26);
+ this.textBoxAddress.Name = "textBoxAddress";
+ this.textBoxAddress.Size = new System.Drawing.Size(221, 23);
+ this.textBoxAddress.TabIndex = 14;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(386, 8);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(100, 15);
+ this.label3.TabIndex = 13;
+ this.label3.Text = "Время открытия:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(159, 8);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(97, 15);
+ this.label2.TabIndex = 12;
+ this.label2.Text = "Адрес магазина:";
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ReinforcedName,
+ this.Price,
+ this.Count});
+ this.dataGridView.Location = new System.Drawing.Point(12, 63);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(713, 204);
+ this.dataGridView.TabIndex = 11;
+ //
+ // ReinforcedName
+ //
+ this.ReinforcedName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ReinforcedName.HeaderText = "Имя изделия";
+ this.ReinforcedName.Name = "ReinforcedName";
+ //
+ // Price
+ //
+ this.Price.HeaderText = "Цена";
+ this.Price.Name = "Price";
+ //
+ // Count
+ //
+ this.Count.HeaderText = "Количество";
+ this.Count.Name = "Count";
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.Location = new System.Drawing.Point(12, 26);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(141, 23);
+ this.comboBoxShop.TabIndex = 1;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 8);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(116, 15);
+ this.label1.TabIndex = 9;
+ this.label1.Text = "Название магазина:";
+ //
+ // dateTimePickerOpening
+ //
+ this.dateTimePickerOpening.Location = new System.Drawing.Point(386, 26);
+ this.dateTimePickerOpening.Name = "dateTimePickerOpening";
+ this.dateTimePickerOpening.Size = new System.Drawing.Size(200, 23);
+ this.dateTimePickerOpening.TabIndex = 18;
+ //
+ // FormShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(737, 319);
+ this.Controls.Add(this.dateTimePickerOpening);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.textBoxAddress);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.label1);
+ this.Name = "FormShop";
+ this.Text = "Изделия магазина";
+ this.Load += new System.EventHandler(this.FormShop_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonSave;
+ private Button buttonCancel;
+ private TextBox textBoxAddress;
+ private Label label3;
+ private Label label2;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ReinforcedName;
+ private DataGridViewTextBoxColumn Price;
+ private DataGridViewTextBoxColumn Count;
+ private TextBox comboBoxShop;
+ private Label label1;
+ private DateTimePicker dateTimePickerOpening;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs
new file mode 100644
index 0000000..6daff3e
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs
@@ -0,0 +1,139 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormShop : Form
+ {
+ private readonly List? _listShops;
+ private readonly IShopLogic _logic;
+ private readonly ILogger _logger;
+
+ public int Id
+ {
+ get; set;
+ }
+
+ private IShopModel? GetShop(int id)
+ {
+ if (_listShops == null)
+ {
+ return null;
+ }
+ foreach (var elem in _listShops)
+ {
+ if (elem.Id == id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _listShops = logic.ReadList(null);
+ _logic = logic;
+ }
+
+ private void LoadData(bool extendDate = true)
+ {
+ try
+ {
+ var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.Text));
+ if (model != null)
+ {
+ comboBoxShop.Text = model.Name;
+ textBoxAddress.Text = model.Address;
+ dateTimePickerOpening.Value = model.DateOpening;
+ dataGridView.Rows.Clear();
+ foreach (var el in model.Reinforceds.Values)
+ {
+ dataGridView.Rows.Add(new object[] { el.Item1.ReinforcedName, el.Item1.Price, el.Item2 });
+ }
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ LoadData(false);
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(comboBoxShop.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxAddress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ ShopBindingModel model = new()
+ {
+ Name = comboBoxShop.Text,
+ Address = textBoxAddress.Text,
+ DateOpening = dateTimePickerOpening.Value,
+
+ };
+ var vmodel = GetShop(Id);
+ bool operationResult = false;
+
+ if (vmodel != null)
+ {
+ model.Id = vmodel.Id;
+ model.Reinforceds = vmodel.Reinforceds;
+ operationResult = _logic.Update(model);
+ }
+ else
+ {
+ operationResult = _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 void FormShop_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx
new file mode 100644
index 0000000..e78e58a
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.resx
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.Designer.cs
index 7b4f17b..fc657ee 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.Designer.cs
@@ -103,7 +103,7 @@
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormViewReinforced";
- this.Text = "FormViewReinforced";
+ this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormViewReinforced_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.cs
index 29a50ab..5f77fbe 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewReinforced.cs
@@ -56,18 +56,15 @@ namespace PrecastConcretePlantView
{
if (dataGridView.SelectedRows.Count == 1)
{
- var service =
- Program.ServiceProvider?.GetService(typeof(FormComponent));
- if (service is FormComponent form)
+ var service = Program.ServiceProvider?.GetService(typeof(FormReinforced));
+ if (service is FormReinforced form)
{
- form.Id =
- Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
-
+ LoadData();
}
}
- LoadData();
}
}
private void ButtonDel_Click(object sender, EventArgs e)
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.Designer.cs
new file mode 100644
index 0000000..2b8a689
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.Designer.cs
@@ -0,0 +1,121 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormViewShops
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonRef
+ //
+ this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRef.Location = new System.Drawing.Point(553, 189);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(90, 37);
+ this.buttonRef.TabIndex = 19;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDel.Location = new System.Drawing.Point(553, 150);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(90, 33);
+ this.buttonDel.TabIndex = 18;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUpd.Location = new System.Drawing.Point(553, 110);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(90, 34);
+ this.buttonUpd.TabIndex = 17;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAdd.Location = new System.Drawing.Point(553, 74);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(90, 30);
+ this.buttonAdd.TabIndex = 16;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(510, 310);
+ this.dataGridView.TabIndex = 15;
+ //
+ // FormViewShops
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(655, 334);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormViewShops";
+ this.Text = "Магазины";
+ this.Load += new System.EventHandler(this.FormShops_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.cs
new file mode 100644
index 0000000..1c514b3
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.cs
@@ -0,0 +1,106 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlant;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormViewShops : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ public FormViewShops(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormShops_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["Reinforceds"].Visible = false;
+ dataGridView.Columns["Name"].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(FormShop));
+ if (service is FormShop 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(FormShop));
+ if (service is FormShop 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 ShopBindingModel
+ {
+ 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/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.resx b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewShops.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/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
index d4552c1..42c5aef 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
@@ -7,6 +7,7 @@ using PrecastConcretePlantContracts.StoragesContract;
using PrecastConcretePlantListImplement.Implements;
using PrecastConcretePlantListImplement;
using PrecastConcretePlantView;
+using PrecastConcretePlantBusinessLogic;
namespace PrecastConcretePlant
@@ -40,9 +41,13 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -50,6 +55,9 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs
new file mode 100644
index 0000000..6929890
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs
@@ -0,0 +1,153 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantBusinessLogic
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+ public ShopLogic(ILogger logger, IShopStorage shopStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+ public List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ",
+ model?.Name, model?.Id);
+ var list = (model == null) ? _shopStorage.GetFullList() :
+ _shopStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}",
+ model.Name, model.Id);
+ var element = _shopStorage.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(ShopBindingModel model)
+ {
+ CheckModel(model);
+ model.Reinforceds = new();
+ if (_shopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ throw new ArgumentNullException("Нет названия магазина",
+ nameof(model.Name));
+ }
+ if (_shopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_shopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ShopBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ throw new ArgumentNullException("Нет названия магазина",
+ nameof(model.Name));
+ }
+ _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
+ model.Name, model.Address, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ Name = model.Name
+ });
+ if (element != null && element.Id != model.Id && element.Name == model.Name)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+
+ public bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
+ }
+ _logger.LogInformation("AddreinforcedInShop. ShopName:{ShopName}.Id:{ Id}",
+ model.Name, model.Id);
+ var element = _shopStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("AddreinforcedInShop element not found");
+ return false;
+ }
+ _logger.LogInformation("AddreinforcedInShop find. Id:{Id}", element.Id);
+
+
+ var prevCount = element.Reinforceds.GetValueOrDefault(reinforced.Id, (reinforced, 0)).Item2;
+ element.Reinforceds[reinforced.Id] = (reinforced, prevCount + count);
+ _logger.LogInformation(
+ "AddreinforcedInShop. Has been added {count} {reinforced} in {ShopName}",
+ count, reinforced.ReinforcedName, element.Name);
+
+ _shopStorage.Update(new()
+ {
+ Id = element.Id,
+ Address = element.Address,
+ Name = element.Name,
+ DateOpening = element.DateOpening,
+ Reinforceds = element.Reinforceds
+ });
+ return true;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..3f9f982
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,22 @@
+using PrecastConcretePlantDataModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public string Name { get; set; } = string.Empty;
+
+ public string Address { get; set; } = string.Empty;
+
+ public DateTime DateOpening { get; set; } = DateTime.Now;
+
+ public Dictionary Reinforceds
+ {
+ get;
+ set;
+ } = new();
+
+ public int Id { get; set; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..6460d8b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,17 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantContracts.BusinessLogicsContracts
+{
+ public interface IShopLogic
+ {
+ List? ReadList(ShopSearchModel? model);
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count);
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..3fed774
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,8 @@
+namespace PrecastConcretePlantContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? Name { get; set; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs
new file mode 100644
index 0000000..060b96a
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs
@@ -0,0 +1,17 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantContracts.StoragesContract
+{
+ public interface IShopStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ShopSearchModel model);
+ ShopViewModel? GetElement(ShopSearchModel model);
+ ShopViewModel? Insert(ShopBindingModel model);
+ ShopViewModel? Update(ShopBindingModel model);
+ ShopViewModel? Delete(ShopBindingModel model);
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..49cc4c2
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,27 @@
+using PrecastConcretePlantDataModels;
+using PrecastConcretePlantDataModels.Models;
+using System.ComponentModel;
+
+
+namespace PrecastConcretePlantContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ [DisplayName("Название магазина")]
+ public string Name { get; set; } = string.Empty;
+
+ [DisplayName("Адрес магазина")]
+ public string Address { get; set; } = string.Empty;
+
+ [DisplayName("Время открытия")]
+ public DateTime DateOpening { get; set; } = DateTime.Now;
+
+ public Dictionary Reinforceds
+ {
+ get;
+ set;
+ } = new();
+
+ public int Id { get; set; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs
new file mode 100644
index 0000000..7522011
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs
@@ -0,0 +1,12 @@
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantDataModels
+{
+ public interface IShopModel : IId
+ {
+ string Name { get; }
+ string Address { get; }
+ DateTime DateOpening { get; }
+ Dictionary Reinforceds { get; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
index 64027e4..e3cdb78 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
@@ -8,11 +8,13 @@ namespace PrecastConcretePlantListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Reinforced { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Reinforced = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
index 653873e..06f32b6 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
@@ -106,11 +106,11 @@ namespace PrecastConcretePlantListImplement
private OrderViewModel GetViewModel(Order model)
{
var res = model.GetViewModel;
- foreach (var pastry in _source.Reinforced)
+ foreach (var reinforced in _source.Reinforced)
{
- if (pastry.Id == model.ReinforcedId)
+ if (reinforced.Id == model.ReinforcedId)
{
- res.ReinforcedName = pastry.ReinforcedName;
+ res.ReinforcedName = reinforced.ReinforcedName;
break;
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs
new file mode 100644
index 0000000..1d07d25
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs
@@ -0,0 +1,59 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class Shop : IShopModel
+ {
+ public string Name { get; private set; } = string.Empty;
+
+ public string Address { get; private set; } = string.Empty;
+
+ public DateTime DateOpening { get; private set; }
+
+ public Dictionary Reinforceds
+ {
+ get;
+ private set;
+ } = new();
+
+ public int Id { get; private set; }
+
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ Address = model.Address,
+ DateOpening = model.DateOpening,
+ Reinforceds = new()
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Name = model.Name;
+ Address = model.Address;
+ DateOpening = model.DateOpening;
+ Reinforceds = model.Reinforceds;
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ Address = Address,
+ Reinforceds = Reinforceds,
+ DateOpening = DateOpening,
+ };
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs
new file mode 100644
index 0000000..fab9bd4
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs
@@ -0,0 +1,107 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public ShopViewModel? Delete(ShopBindingModel model)
+ {
+ for (int i = 0; i < _source.Shops.Count; ++i)
+ {
+ if (_source.Shops[i].Id == model.Id)
+ {
+ var element = _source.Shops[i];
+ _source.Shops.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var shop in _source.Shops)
+ {
+ if ((!string.IsNullOrEmpty(model.Name) &&
+ shop.Name == model.Name) ||
+ (model.Id.HasValue && shop.Id == model.Id))
+ {
+ return shop.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return result;
+ }
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Name.Contains(model.Name ?? string.Empty))
+ {
+ result.Add(shop.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var shop in _source.Shops)
+ {
+ result.Add(shop.GetViewModel);
+ }
+ return result;
+ }
+
+ public ShopViewModel? Insert(ShopBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var shop in _source.Shops)
+ {
+ if (model.Id <= shop.Id)
+ {
+ model.Id = shop.Id + 1;
+ }
+ }
+ var newShop = Shop.Create(model);
+ if (newShop == null)
+ {
+ return null;
+ }
+ _source.Shops.Add(newShop);
+ return newShop.GetViewModel;
+ }
+
+ public ShopViewModel? Update(ShopBindingModel model)
+ {
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Id == model.Id)
+ {
+ shop.Update(model);
+ return shop.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}