diff --git a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
index 8ad81b0..cdb78ac 100644
--- a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
+++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs
@@ -32,6 +32,8 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.buttonSupplyShop = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonSetToWork = new System.Windows.Forms.Button();
@@ -57,7 +59,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
- this.автомобилиToolStripMenuItem});
+ this.автомобилиToolStripMenuItem,
+ this.shopsToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -76,6 +79,23 @@
this.автомобилиToolStripMenuItem.Text = "Автомобили";
this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.автомобилиToolStripMenuItem_Click);
//
+ // shopsToolStripMenuItem
+ //
+ this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
+ this.shopsToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
+ this.shopsToolStripMenuItem.Text = "Магазины";
+ this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
+ //
+ // buttonSupplyShop
+ //
+ this.buttonSupplyShop.Location = new System.Drawing.Point(969, 182);
+ this.buttonSupplyShop.Name = "buttonSupplyShop";
+ this.buttonSupplyShop.Size = new System.Drawing.Size(194, 30);
+ this.buttonSupplyShop.TabIndex = 7;
+ this.buttonSupplyShop.Text = "Пополнение магазина";
+ this.buttonSupplyShop.UseVisualStyleBackColor = true;
+ this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
+ //
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@@ -141,6 +161,7 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1176, 450);
+ this.Controls.Add(this.buttonSupplyShop);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish);
this.Controls.Add(this.buttonSetToDone);
@@ -172,5 +193,7 @@
private Button buttonSetToDone;
private Button buttonSetToFinish;
private Button buttonUpdate;
+ private ToolStripMenuItem shopsToolStripMenuItem;
+ private Button buttonSupplyShop;
}
}
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormMain.cs b/AutomobilePlant/AutomobilePlant/FormMain.cs
index 02cfdf1..d43f015 100644
--- a/AutomobilePlant/AutomobilePlant/FormMain.cs
+++ b/AutomobilePlant/AutomobilePlant/FormMain.cs
@@ -1,6 +1,7 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicContracts;
using AutomobilePlantDataModels.Enums;
+using AutomobilePlant;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -163,5 +164,23 @@ namespace AutomobilePlant
{
LoadData();
}
+
+ private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void buttonSupplyShop_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
+ if (service is FormShopSupply form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/AutomobilePlant/AutomobilePlant/FormShop.Designer.cs b/AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
new file mode 100644
index 0000000..886a469
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShop.Designer.cs
@@ -0,0 +1,171 @@
+namespace AutomobilePlant
+{
+ 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.textBoxAddress = new System.Windows.Forms.TextBox();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.labelAddress = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCarName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // textBoxAddress
+ //
+ this.textBoxAddress.Location = new System.Drawing.Point(88, 34);
+ this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxAddress.Name = "textBoxAddress";
+ this.textBoxAddress.Size = new System.Drawing.Size(276, 23);
+ this.textBoxAddress.TabIndex = 7;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(88, 9);
+ this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(276, 23);
+ this.textBoxName.TabIndex = 6;
+ //
+ // labelAddress
+ //
+ this.labelAddress.AutoSize = true;
+ this.labelAddress.Location = new System.Drawing.Point(12, 38);
+ this.labelAddress.Name = "labelAddress";
+ this.labelAddress.Size = new System.Drawing.Size(43, 15);
+ this.labelAddress.TabIndex = 5;
+ this.labelAddress.Text = "Адрес:";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 11);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(62, 15);
+ this.labelName.TabIndex = 4;
+ this.labelName.Text = "Название:";
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnId,
+ this.ColumnCarName,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(12, 61);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(351, 251);
+ this.dataGridView.TabIndex = 10;
+ //
+ // ColumnId
+ //
+ this.ColumnId.HeaderText = "ID";
+ this.ColumnId.MinimumWidth = 6;
+ this.ColumnId.Name = "ColumnId";
+ this.ColumnId.Visible = false;
+ this.ColumnId.Width = 125;
+ //
+ // ColumnCarName
+ //
+ this.ColumnCarName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ColumnCarName.HeaderText = "Автомобиль";
+ this.ColumnCarName.MinimumWidth = 6;
+ this.ColumnCarName.Name = "ColumnCarName";
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 6;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 125;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(200, 327);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(136, 31);
+ this.buttonCancel.TabIndex = 12;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(42, 327);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(136, 31);
+ this.buttonSave.TabIndex = 11;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // FormShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(389, 367);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.textBoxAddress);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelAddress);
+ this.Controls.Add(this.labelName);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ 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 TextBox textBoxAddress;
+ private TextBox textBoxName;
+ private Label labelAddress;
+ private Label labelName;
+ private DataGridView dataGridView;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnCarName;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormShop.cs b/AutomobilePlant/AutomobilePlant/FormShop.cs
new file mode 100644
index 0000000..aa52a7a
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShop.cs
@@ -0,0 +1,132 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormShop : Form
+ {
+ private readonly IShopLogic _logic;
+ private readonly ILogger _logger;
+ private Dictionary _shopCars;
+ private int? _id;
+ public int Id { set { _id = value; } }
+
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _shopCars = new();
+ }
+
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Loading shop");
+
+ try
+ {
+ var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
+
+ if (view != null)
+ {
+ textBoxName.Text = view.Name;
+ textBoxAddress.Text = view.Address;
+ _shopCars = view.ShopCars ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Loading shop's cars");
+
+ try
+ {
+ if (_shopCars != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var car in _shopCars)
+ {
+ dataGridView.Rows.Add(new object[] { car.Key, car.Value.Item1.CarName, car.Value.Item2 });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shop's cars");
+ 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("Saving shop");
+
+ try
+ {
+ var model = new ShopBindingModel
+ {
+ Id = _id ?? 0,
+ Name = textBoxName.Text,
+ Address = textBoxAddress.Text,
+ OpeningDate = DateTime.Now
+ };
+
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during saving shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlant/FormShop.resx b/AutomobilePlant/AutomobilePlant/FormShop.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShop.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormShopSupply.Designer.cs b/AutomobilePlant/AutomobilePlant/FormShopSupply.Designer.cs
new file mode 100644
index 0000000..55b63bc
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShopSupply.Designer.cs
@@ -0,0 +1,149 @@
+namespace AutomobilePlant
+{
+ partial class FormShopSupply
+ {
+ ///
+ /// 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.labelShop = new System.Windows.Forms.Label();
+ this.labelCar = new System.Windows.Forms.Label();
+ this.labelCarCount = new System.Windows.Forms.Label();
+ this.comboBoxShop = new System.Windows.Forms.ComboBox();
+ this.comboBoxCar = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelShop
+ //
+ this.labelShop.AutoSize = true;
+ this.labelShop.Location = new System.Drawing.Point(23, 14);
+ this.labelShop.Name = "labelShop";
+ this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.labelShop.Size = new System.Drawing.Size(57, 15);
+ this.labelShop.TabIndex = 0;
+ this.labelShop.Text = "Магазин:";
+ //
+ // labelCar
+ //
+ this.labelCar.AutoSize = true;
+ this.labelCar.Location = new System.Drawing.Point(23, 54);
+ this.labelCar.Name = "labelCar";
+ this.labelCar.Size = new System.Drawing.Size(40, 15);
+ this.labelCar.TabIndex = 1;
+ this.labelCar.Text = "Автомобиль:";
+ //
+ // labelCarCount
+ //
+ this.labelCarCount.AutoSize = true;
+ this.labelCarCount.Location = new System.Drawing.Point(23, 92);
+ this.labelCarCount.Name = "labelCarCount";
+ this.labelCarCount.Size = new System.Drawing.Size(75, 15);
+ this.labelCarCount.TabIndex = 2;
+ this.labelCarCount.Text = "Количество:";
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.FormattingEnabled = true;
+ this.comboBoxShop.Location = new System.Drawing.Point(130, 14);
+ this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
+ this.comboBoxShop.TabIndex = 3;
+ //
+ // comboBoxCar
+ //
+ this.comboBoxCar.FormattingEnabled = true;
+ this.comboBoxCar.Location = new System.Drawing.Point(130, 52);
+ this.comboBoxCar.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.comboBoxCar.Name = "comboBoxCar";
+ this.comboBoxCar.Size = new System.Drawing.Size(220, 23);
+ this.comboBoxCar.TabIndex = 4;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(130, 89);
+ this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(110, 23);
+ this.textBoxCount.TabIndex = 5;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(288, 137);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(82, 34);
+ 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(200, 137);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(82, 34);
+ this.buttonSave.TabIndex = 8;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // FormShopSupply
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(382, 182);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxCar);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.labelCarCount);
+ this.Controls.Add(this.labelCar);
+ this.Controls.Add(this.labelShop);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormShopSupply";
+ this.Text = "Пополнение магазина";
+ this.Load += new System.EventHandler(this.FormShopSupply_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelShop;
+ private Label labelCar;
+ private Label labelCarCount;
+ private ComboBox comboBoxShop;
+ private ComboBox comboBoxCar;
+ private TextBox textBoxCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormShopSupply.cs b/AutomobilePlant/AutomobilePlant/FormShopSupply.cs
new file mode 100644
index 0000000..a61af11
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShopSupply.cs
@@ -0,0 +1,126 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormShopSupply : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICarLogic _logicCar;
+ private readonly IShopLogic _logicShop;
+
+ public FormShopSupply(ILogger logger, ICarLogic logicCar, IShopLogic logicShop)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicCar = logicCar;
+ _logicShop = logicShop;
+ }
+
+ private void FormShopSupply_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Loading cars for supplying");
+
+ try
+ {
+ var list = _logicCar.ReadList(null);
+ if (list != null)
+ {
+ comboBoxCar.DisplayMember = "CarName";
+ comboBoxCar.ValueMember = "Id";
+ comboBoxCar.DataSource = list;
+ comboBoxCar.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading cars for supplying");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ _logger.LogInformation("Loading shops for supplying");
+
+ try
+ {
+ var list = _logicShop.ReadList(null);
+ if (list != null)
+ {
+ comboBoxShop.DisplayMember = "Name";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = list;
+ comboBoxShop.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shops for supplying");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (comboBoxCar.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите авто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Creation of supply");
+
+ try
+ {
+ var operationResult = _logicShop.SupplyCars(
+ new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text },
+ new CarBindingModel { Id = Convert.ToInt32(comboBoxCar.SelectedValue), CarName = comboBoxCar.Text },
+ 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, "Error during creation of supply");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlant/FormShopSupply.resx b/AutomobilePlant/AutomobilePlant/FormShopSupply.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShopSupply.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormShops.Designer.cs b/AutomobilePlant/AutomobilePlant/FormShops.Designer.cs
new file mode 100644
index 0000000..8bc2914
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShops.Designer.cs
@@ -0,0 +1,120 @@
+namespace AutomobilePlant
+{
+ partial class FormShops
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(10, 9);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(491, 320);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(549, 294);
+ this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(133, 33);
+ this.buttonUpdate.TabIndex = 9;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(549, 83);
+ this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(133, 33);
+ this.buttonDelete.TabIndex = 8;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(549, 46);
+ this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(133, 33);
+ this.buttonEdit.TabIndex = 7;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(549, 9);
+ this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(133, 33);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
+ //
+ // FormShops
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(700, 338);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormShops";
+ this.Text = "Магазины";
+ this.Load += new System.EventHandler(this.FormShops_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonEdit;
+ private Button buttonAdd;
+ }
+}
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/FormShops.cs b/AutomobilePlant/AutomobilePlant/FormShops.cs
new file mode 100644
index 0000000..dd363f9
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShops.cs
@@ -0,0 +1,120 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AutomobilePlant
+{
+ public partial class FormShops : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+
+ public FormShops(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["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ShopCars"].Visible = false;
+ }
+
+ _logger.LogInformation("Loading shops");
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shops");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ 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 buttonEdit_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 buttonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить магазин?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Deleting shop");
+
+ try
+ {
+ if (!_logic.Delete(new ShopBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during deleting shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlant/FormShops.resx b/AutomobilePlant/AutomobilePlant/FormShops.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlant/FormShops.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs
index 263d671..1acc6fd 100644
--- a/AutomobilePlant/AutomobilePlant/Program.cs
+++ b/AutomobilePlant/AutomobilePlant/Program.cs
@@ -33,9 +33,11 @@ namespace AutomobilePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -43,6 +45,9 @@ namespace AutomobilePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..6294354
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,183 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.BusinessLogicContracts;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantBusinessLogic.BusinessLogics
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+
+ public ShopLogic(ILogger logger, IShopStorage shopStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", 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 List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", 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 bool SupplyCars(ShopSearchModel model, ICarModel car, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (car == null)
+ {
+ throw new ArgumentNullException(nameof(car));
+ }
+
+ if (count <= 0)
+ {
+ throw new ArgumentNullException("Count of cars in supply must be more than 0", nameof(count));
+ }
+
+ var shopElement = _shopStorage.GetElement(model);
+ if (shopElement == null)
+ {
+ _logger.LogWarning("Required shop element not found in storage");
+ return false;
+ }
+
+ _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
+
+ if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar))
+ {
+ shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count);
+ _logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
+ }
+ else
+ {
+ shopElement.ShopCars[car.Id] = (car, count);
+ _logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name);
+ }
+
+ _shopStorage.Update(new()
+ {
+ Id = shopElement.Id,
+ Name = shopElement.Name,
+ Address = shopElement.Address,
+ OpeningDate = shopElement.OpeningDate,
+ ShopCars = shopElement.ShopCars
+ });
+
+ return true;
+ }
+
+ public bool Create(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool Update(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool Delete(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+
+ 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. Name: {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)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..f975864
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,22 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public int Id { get; set; }
+
+ public string Name { get; set; } = string.Empty;
+
+ public string Address { get; set; } = string.Empty;
+
+ public DateTime OpeningDate { get; set; }
+
+ public Dictionary ShopCars { get; set; }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IShopLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IShopLogic.cs
new file mode 100644
index 0000000..1f3f790
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicContracts/IShopLogic.cs
@@ -0,0 +1,22 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.BusinessLogicContracts
+{
+ public interface IShopLogic
+ {
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ List? ReadList(ShopSearchModel? model);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ bool SupplyCars(ShopSearchModel model, ICarModel car, int count);
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..9af1a3d
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? Name { get; set; }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantContracts/StorageContracts/IShopStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StorageContracts/IShopStorage.cs
new file mode 100644
index 0000000..86f1fbb
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantContracts/StorageContracts/IShopStorage.cs
@@ -0,0 +1,21 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.StorageContracts
+{
+ public interface IShopStorage
+ {
+ ShopViewModel? GetElement(ShopSearchModel model);
+ List GetFullList();
+ List GetFilteredList(ShopSearchModel model);
+ ShopViewModel? Insert(ShopBindingModel model);
+ ShopViewModel? Update(ShopBindingModel model);
+ ShopViewModel? Delete(ShopBindingModel model);
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..9566b0d
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,26 @@
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ public int Id { get; set; }
+
+ [DisplayName("Название магазина")]
+ public string Name { get; set; } = string.Empty;
+
+ [DisplayName("Адрес")]
+ public string Address { get; set; } = string.Empty;
+
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; }
+
+ public Dictionary ShopCars { get; set; } = new();
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..8ee298b
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantDataModels.Models
+{
+ public interface IShopModel : IId
+ {
+ string Name { get; }
+ string Address { get; }
+ DateTime OpeningDate { get; }
+ Dictionary ShopCars { get; }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantListImplements/DataListSingleton.cs b/AutomobilePlant/AutomobilePlantListImplements/DataListSingleton.cs
index d18f01f..740db2b 100644
--- a/AutomobilePlant/AutomobilePlantListImplements/DataListSingleton.cs
+++ b/AutomobilePlant/AutomobilePlantListImplements/DataListSingleton.cs
@@ -8,11 +8,13 @@ namespace AutomobilePlantListImplements
public List Components { get; set; }
public List Orders { get; set; }
public List Cars { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Cars = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/AutomobilePlant/AutomobilePlantListImplements/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantListImplements/Implements/ShopStorage.cs
new file mode 100644
index 0000000..f295093
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantListImplements/Implements/ShopStorage.cs
@@ -0,0 +1,126 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.SearchModels;
+using AutomobilePlantContracts.StorageContracts;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantListImplements.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantListImplements.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ 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))
+ {
+ 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;
+ }
+
+ 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;
+ }
+ }
+}
diff --git a/AutomobilePlant/AutomobilePlantListImplements/Models/Shop.cs b/AutomobilePlant/AutomobilePlantListImplements/Models/Shop.cs
new file mode 100644
index 0000000..6de3c15
--- /dev/null
+++ b/AutomobilePlant/AutomobilePlantListImplements/Models/Shop.cs
@@ -0,0 +1,62 @@
+using AutomobilePlantContracts.BindingModels;
+using AutomobilePlantContracts.ViewModels;
+using AutomobilePlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutomobilePlantListImplements.Models
+{
+ public class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+
+ public string Name { get; private set; } = string.Empty;
+
+ public string Address { get; private set; } = string.Empty;
+
+ public DateTime OpeningDate { get; private set; }
+
+ public Dictionary ShopCars { get; private set; } = new();
+
+ public static Shop? Create(ShopBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Shop()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ Address = model.Address,
+ OpeningDate = model.OpeningDate,
+ ShopCars = new()
+ };
+ }
+
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ Name = model.Name;
+ Address = model.Address;
+ ShopCars = model.ShopCars;
+ }
+
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ Address = Address,
+ OpeningDate = OpeningDate,
+ ShopCars = ShopCars
+ };
+ }
+}