diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
index 26b30db..cde146c 100644
--- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
+++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs
@@ -32,12 +32,14 @@
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
+ магазиныToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRefresh = new Button();
+ shopReplenishment = new Button();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -55,7 +57,7 @@
//
// справочникиToolStripMenuItem
//
- справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
+ справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
@@ -74,6 +76,13 @@
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
//
+ // магазиныToolStripMenuItem
+ //
+ магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ магазиныToolStripMenuItem.Size = new Size(182, 26);
+ магазиныToolStripMenuItem.Text = "Магазины";
+ магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
+ //
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
@@ -150,6 +159,16 @@
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRef_Click;
//
+ // shopReplenishment
+ //
+ shopReplenishment.Location = new Point(885, 312);
+ shopReplenishment.Name = "shopReplenishment";
+ shopReplenishment.Size = new Size(178, 41);
+ shopReplenishment.TabIndex = 7;
+ shopReplenishment.Text = "Пополнение магазина";
+ shopReplenishment.UseVisualStyleBackColor = true;
+ shopReplenishment.Click += ShopReplenishment_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -162,6 +181,7 @@
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
+ Controls.Add(shopReplenishment);
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 4, 3, 4);
Name = "FormMain";
@@ -186,5 +206,7 @@
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRefresh;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private Button shopReplenishment;
}
}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs
index 107d13b..d6db763 100644
--- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs
+++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs
@@ -51,6 +51,24 @@ namespace SoftwareInstallationView
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
+ private void ShopReplenishment_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
+
+ if (service is FormShopReplenishment form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs
e)
{
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShop.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormShop.Designer.cs
new file mode 100644
index 0000000..2245683
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShop.Designer.cs
@@ -0,0 +1,193 @@
+namespace SoftwareInstallationView
+{
+ 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()
+ {
+ shopNameLabel = new Label();
+ shopAddressLabel = new Label();
+ openingDateLabel = new Label();
+ addressTextBox = new TextBox();
+ openingDatePicker = new DateTimePicker();
+ dataGridView = new DataGridView();
+ PackageName = new DataGridViewTextBoxColumn();
+ PackagePrice = new DataGridViewTextBoxColumn();
+ PackageCount = new DataGridViewTextBoxColumn();
+ SaveButton = new Button();
+ ButtonCancel = new Button();
+ nameTextBox = new TextBox();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // shopNameLabel
+ //
+ shopNameLabel.AutoSize = true;
+ shopNameLabel.Location = new Point(14, 12);
+ shopNameLabel.Name = "shopNameLabel";
+ shopNameLabel.Size = new Size(154, 20);
+ shopNameLabel.TabIndex = 0;
+ shopNameLabel.Text = "Название магазина: ";
+ //
+ // shopAddressLabel
+ //
+ shopAddressLabel.AutoSize = true;
+ shopAddressLabel.Location = new Point(14, 53);
+ shopAddressLabel.Name = "shopAddressLabel";
+ shopAddressLabel.Size = new Size(128, 20);
+ shopAddressLabel.TabIndex = 1;
+ shopAddressLabel.Text = "Адрес магазина: ";
+ //
+ // openingDateLabel
+ //
+ openingDateLabel.AutoSize = true;
+ openingDateLabel.Location = new Point(14, 96);
+ openingDateLabel.Name = "openingDateLabel";
+ openingDateLabel.Size = new Size(117, 20);
+ openingDateLabel.TabIndex = 2;
+ openingDateLabel.Text = "Дата открытия: ";
+ //
+ // addressTextBox
+ //
+ addressTextBox.Location = new Point(163, 50);
+ addressTextBox.Margin = new Padding(3, 4, 3, 4);
+ addressTextBox.Name = "addressTextBox";
+ addressTextBox.Size = new Size(198, 27);
+ addressTextBox.TabIndex = 4;
+ //
+ // openingDatePicker
+ //
+ openingDatePicker.Location = new Point(163, 91);
+ openingDatePicker.Name = "openingDatePicker";
+ openingDatePicker.Size = new Size(198, 27);
+ openingDatePicker.TabIndex = 9;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { PackageName, PackagePrice, PackageCount });
+ dataGridView.Location = new Point(14, 145);
+ dataGridView.Margin = new Padding(3, 4, 3, 4);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(887, 384);
+ dataGridView.TabIndex = 6;
+ //
+ // PackageName
+ //
+ PackageName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ PackageName.HeaderText = "Название изделия";
+ PackageName.MinimumWidth = 6;
+ PackageName.Name = "PackageName";
+ //
+ // PackagePrice
+ //
+ PackagePrice.HeaderText = "Цена";
+ PackagePrice.MinimumWidth = 6;
+ PackagePrice.Name = "PackagePrice";
+ PackagePrice.Width = 125;
+ //
+ // PackageCount
+ //
+ PackageCount.HeaderText = "Количество";
+ PackageCount.MinimumWidth = 6;
+ PackageCount.Name = "PackageCount";
+ PackageCount.Width = 125;
+ //
+ // SaveButton
+ //
+ SaveButton.Location = new Point(631, 537);
+ SaveButton.Margin = new Padding(3, 4, 3, 4);
+ SaveButton.Name = "SaveButton";
+ SaveButton.Size = new Size(131, 47);
+ SaveButton.TabIndex = 7;
+ SaveButton.Text = "Сохранить";
+ SaveButton.UseVisualStyleBackColor = true;
+ SaveButton.Click += SaveButton_Click;
+ //
+ // ButtonCancel
+ //
+ ButtonCancel.Location = new Point(769, 537);
+ ButtonCancel.Margin = new Padding(3, 4, 3, 4);
+ ButtonCancel.Name = "ButtonCancel";
+ ButtonCancel.Size = new Size(131, 47);
+ ButtonCancel.TabIndex = 8;
+ ButtonCancel.Text = "Отменить";
+ ButtonCancel.UseVisualStyleBackColor = true;
+ ButtonCancel.Click += ButtonCancel_Click;
+ //
+ // nameTextBox
+ //
+ nameTextBox.Location = new Point(163, 9);
+ nameTextBox.Name = "nameTextBox";
+ nameTextBox.Size = new Size(198, 27);
+ nameTextBox.TabIndex = 10;
+ //
+ // FormShop
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(914, 600);
+ Controls.Add(nameTextBox);
+ Controls.Add(ButtonCancel);
+ Controls.Add(SaveButton);
+ Controls.Add(dataGridView);
+ Controls.Add(openingDatePicker);
+ Controls.Add(addressTextBox);
+ Controls.Add(openingDateLabel);
+ Controls.Add(shopAddressLabel);
+ Controls.Add(shopNameLabel);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormShop";
+ Text = "Магазин";
+ Load += FormShop_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label shopNameLabel;
+ private Label shopAddressLabel;
+ private Label openingDateLabel;
+ private TextBox addressTextBox;
+ private DateTimePicker openingDatePicker;
+ private DataGridView dataGridView;
+ private Button SaveButton;
+ private Button ButtonCancel;
+ private DataGridViewTextBoxColumn PackageName;
+ private DataGridViewTextBoxColumn PackagePrice;
+ private DataGridViewTextBoxColumn PackageCount;
+ private TextBox nameTextBox;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShop.cs b/SoftwareInstallation/SoftwareInstallation/FormShop.cs
new file mode 100644
index 0000000..079b7f3
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShop.cs
@@ -0,0 +1,140 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+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 SoftwareInstallationView
+{
+ public partial class FormShop : Form
+ {
+ private readonly List? _listShops;
+ private readonly IShopLogic _logic;
+ private readonly ILogger _logger;
+ public int Id { get; set; }
+
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _listShops = logic.ReadList(null);
+ _logic = logic;
+ }
+
+ private IShopModel? GetShop(int id)
+ {
+ if (_listShops == null)
+ {
+ return null;
+ }
+ foreach (var elem in _listShops)
+ {
+ if (elem.Id == id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(nameTextBox.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (string.IsNullOrEmpty(addressTextBox.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Сохранение изделия");
+
+ try
+ {
+ DateTime.TryParse(openingDatePicker.Text, out var dateTime);
+ ShopBindingModel model = new()
+ {
+ ShopName = nameTextBox.Text,
+ ShopAddress = addressTextBox.Text,
+ OpeningDate = dateTime
+ };
+ var vmodel = GetShop(Id);
+ bool operationResult = false;
+
+ if (vmodel != null)
+ {
+ model.Id = vmodel.Id;
+ model.Packages = vmodel.Packages;
+ 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();
+ }
+ private void LoadData(bool extendDate = true)
+ {
+ try
+ {
+ var model = GetShop(extendDate ? Id : Convert.ToInt32(nameTextBox.Text));
+ if (model != null)
+ {
+ nameTextBox.Text = model.ShopName;
+ addressTextBox.Text = model.ShopAddress;
+ openingDatePicker.Text = Convert.ToString(model.OpeningDate);
+ dataGridView.Rows.Clear();
+ foreach (var el in model.Packages.Values)
+ {
+ dataGridView.Rows.Add(new object[] { el.Item1.PackageName, el.Item1.Price, el.Item2 });
+ }
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShop.resx b/SoftwareInstallation/SoftwareInstallation/FormShop.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/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/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.Designer.cs
new file mode 100644
index 0000000..34d3218
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.Designer.cs
@@ -0,0 +1,147 @@
+namespace SoftwareInstallationView
+{
+ partial class FormShopReplenishment
+ {
+ ///
+ /// 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()
+ {
+ shopNameLabel = new Label();
+ packageNameLabel = new Label();
+ countLabel = new Label();
+ shopNameComboBox = new ComboBox();
+ packageNameComboBox = new ComboBox();
+ countTextBox = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // shopNameLabel
+ //
+ shopNameLabel.AutoSize = true;
+ shopNameLabel.Location = new Point(14, 12);
+ shopNameLabel.Name = "shopNameLabel";
+ shopNameLabel.Size = new Size(154, 20);
+ shopNameLabel.TabIndex = 0;
+ shopNameLabel.Text = "Название магазина: ";
+ //
+ // packageNameLabel
+ //
+ packageNameLabel.AutoSize = true;
+ packageNameLabel.Location = new Point(14, 49);
+ packageNameLabel.Name = "packageNameLabel";
+ packageNameLabel.Size = new Size(145, 20);
+ packageNameLabel.TabIndex = 1;
+ packageNameLabel.Text = "Название изделия: ";
+ //
+ // countLabel
+ //
+ countLabel.AutoSize = true;
+ countLabel.Location = new Point(14, 88);
+ countLabel.Name = "countLabel";
+ countLabel.Size = new Size(97, 20);
+ countLabel.TabIndex = 2;
+ countLabel.Text = "Количество: ";
+ //
+ // shopNameComboBox
+ //
+ shopNameComboBox.FormattingEnabled = true;
+ shopNameComboBox.Location = new Point(171, 9);
+ shopNameComboBox.Margin = new Padding(3, 4, 3, 4);
+ shopNameComboBox.Name = "shopNameComboBox";
+ shopNameComboBox.Size = new Size(170, 28);
+ shopNameComboBox.TabIndex = 3;
+ //
+ // packageNameComboBox
+ //
+ packageNameComboBox.FormattingEnabled = true;
+ packageNameComboBox.Location = new Point(171, 49);
+ packageNameComboBox.Margin = new Padding(3, 4, 3, 4);
+ packageNameComboBox.Name = "packageNameComboBox";
+ packageNameComboBox.Size = new Size(170, 28);
+ packageNameComboBox.TabIndex = 4;
+ //
+ // countTextBox
+ //
+ countTextBox.Location = new Point(171, 87);
+ countTextBox.Margin = new Padding(3, 4, 3, 4);
+ countTextBox.Name = "countTextBox";
+ countTextBox.Size = new Size(170, 27);
+ countTextBox.TabIndex = 5;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(151, 144);
+ buttonSave.Margin = new Padding(3, 4, 3, 4);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(98, 31);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += SaveButton_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(255, 144);
+ buttonCancel.Margin = new Padding(3, 4, 3, 4);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(86, 31);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // FormShopReplenishment
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(353, 200);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(countTextBox);
+ Controls.Add(packageNameComboBox);
+ Controls.Add(shopNameComboBox);
+ Controls.Add(countLabel);
+ Controls.Add(packageNameLabel);
+ Controls.Add(shopNameLabel);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormShopReplenishment";
+ Text = "Пополнение магазина";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label shopNameLabel;
+ private Label packageNameLabel;
+ private Label countLabel;
+ private ComboBox shopNameComboBox;
+ private ComboBox packageNameComboBox;
+ private TextBox countTextBox;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.cs b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.cs
new file mode 100644
index 0000000..4924ff9
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.cs
@@ -0,0 +1,104 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.ViewModels;
+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 SoftwareInstallationView
+{
+ public partial class FormShopReplenishment : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _ShopLogic;
+ private readonly IPackageLogic _packageLogic;
+ private readonly List? _listShops;
+ private readonly List? _listPackages;
+ public FormShopReplenishment(ILogger logger, IShopLogic ShopLogic, IPackageLogic packageLogic)
+ {
+ InitializeComponent();
+ _ShopLogic = ShopLogic;
+ _packageLogic = packageLogic;
+ _logger = logger;
+ _listShops = ShopLogic.ReadList(null);
+ if (_listShops != null)
+ {
+ shopNameComboBox.DisplayMember = "ShopName";
+ shopNameComboBox.ValueMember = "Id";
+ shopNameComboBox.DataSource = _listShops;
+ shopNameComboBox.SelectedItem = null;
+ }
+
+ _listPackages = packageLogic.ReadList(null);
+ if (_listPackages != null)
+ {
+ packageNameComboBox.DisplayMember = "PackageName";
+ packageNameComboBox.ValueMember = "Id";
+ packageNameComboBox.DataSource = _listPackages;
+ packageNameComboBox.SelectedItem = null;
+ }
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ if (shopNameComboBox.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (packageNameComboBox.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Добавление изделия в магазин");
+
+ try
+ {
+ var package = _packageLogic.ReadElement(new()
+ {
+ Id = (int)packageNameComboBox.SelectedValue
+ });
+
+ if (package == null)
+ {
+ throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
+ }
+
+ var resultOperation = _ShopLogic.AddPackage(
+ model: new() { Id = (int)shopNameComboBox.SelectedValue },
+ package: package,
+ quantity: Convert.ToInt32(countTextBox.Text)
+ );
+
+ 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/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.resx b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShopReplenishment.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/SoftwareInstallation/SoftwareInstallation/FormShops.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormShops.Designer.cs
new file mode 100644
index 0000000..c20e9c0
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShops.Designer.cs
@@ -0,0 +1,125 @@
+namespace SoftwareInstallationView
+{
+ 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()
+ {
+ dataGridView = new DataGridView();
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonRefresh = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(1, 1);
+ dataGridView.Margin = new Padding(3, 4, 3, 4);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(629, 596);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(669, 16);
+ buttonAdd.Margin = new Padding(3, 4, 3, 4);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(138, 53);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += AddButton_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(669, 89);
+ buttonUpdate.Margin = new Padding(3, 4, 3, 4);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(138, 53);
+ buttonUpdate.TabIndex = 2;
+ buttonUpdate.Text = "Изменить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += UpdateButton_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(669, 163);
+ buttonDelete.Margin = new Padding(3, 4, 3, 4);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(138, 53);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += DeleteButton_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(669, 239);
+ buttonRefresh.Margin = new Padding(3, 4, 3, 4);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(138, 53);
+ buttonRefresh.TabIndex = 4;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += RefreshButton_Click;
+ //
+ // FormShops
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(821, 600);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormShops";
+ Text = "Магазины";
+ Load += FormShops_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShops.cs b/SoftwareInstallation/SoftwareInstallation/FormShops.cs
new file mode 100644
index 0000000..cb5b572
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/FormShops.cs
@@ -0,0 +1,123 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallation;
+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 SoftwareInstallationView
+{
+ 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["Packages"].Visible = false;
+ }
+
+ _logger.LogInformation("Загрузка магазинов");
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void RefreshButton_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void DeleteButton_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 UpdateButton_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 AddButton_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+
+ if (service is FormShop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallation/FormShops.resx b/SoftwareInstallation/SoftwareInstallation/FormShops.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallation/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/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs
index 3c94573..9c9489d 100644
--- a/SoftwareInstallation/SoftwareInstallation/Program.cs
+++ b/SoftwareInstallation/SoftwareInstallation/Program.cs
@@ -40,9 +40,11 @@ namespace SoftwareInstallation
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -50,6 +52,9 @@ namespace SoftwareInstallation
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..ef5e5f8
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,180 @@
+using Microsoft.Extensions.Logging;
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.BusinessLogicContracts;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationBusinessLogic.BusinessLogics
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _ShopStorage;
+ public ShopLogic(ILogger logger, IShopStorage ShopStorage)
+ {
+ _logger = logger;
+ _ShopStorage = ShopStorage;
+ }
+ public bool AddPackage(ShopSearchModel model, IPackageModel package, int quantity)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (quantity <= 0)
+ {
+ throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
+ }
+
+ _logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{Id}", model.ShopName, model.Id);
+ var element = _ShopStorage.GetElement(model);
+
+ if (element == null)
+ {
+ _logger.LogWarning("AddPackageInShop element not found");
+ return false;
+ }
+
+ _logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id);
+
+ if (element.Packages.TryGetValue(package.Id, out var pair))
+ {
+ element.Packages[package.Id] = (package, quantity + pair.Item2);
+ _logger.LogInformation("AddPackageInShop. Has been added {quantity} {package} in {ShopName}", quantity, package.PackageName, element.ShopName);
+ }
+ else
+ {
+ element.Packages[package.Id] = (package, quantity);
+ _logger.LogInformation("AddPackageInShop. Has been added {quantity} new Package {package} in {ShopName}", quantity, package.PackageName, element.ShopName);
+ }
+
+ _ShopStorage.Update(new()
+ {
+ Id = element.Id,
+ ShopAddress = element.ShopAddress,
+ ShopName = element.ShopName,
+ OpeningDate = element.OpeningDate,
+ Packages = element.Packages
+ });
+ return true;
+ }
+
+ public bool Create(ShopBindingModel model)
+ {
+ CheckModel(model);
+ model.Packages = new();
+
+ if (_ShopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert 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;
+ }
+
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, 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. ShopName:{ShopName}.Id:{ Id} ", model?.ShopName, 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 Update(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
+ }
+
+ if (_ShopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update 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.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
+ }
+
+ _logger.LogInformation("Shop. ShopName:{0}.ShopAddress:{1}. Id: {2}", model.ShopName, model.ShopAddress, model.Id);
+ var element = _ShopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+
+ if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..ef5c66e
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,18 @@
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public string ShopName { get; set; } = string.Empty;
+ public string ShopAddress { get; set; } = string.Empty;
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+ public Dictionary Packages { get; set; } = new();
+ public int Id { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IShopLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IShopLogic.cs
new file mode 100644
index 0000000..abecdbe
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicContracts/IShopLogic.cs
@@ -0,0 +1,22 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.BusinessLogicContracts
+{
+ public interface IShopLogic
+ {
+ List? ReadList(ShopSearchModel? model);
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ bool AddPackage(ShopSearchModel model, IPackageModel package, int quantity);
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..a8a3e96
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..b7db259
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,21 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.StoragesContracts
+{
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..fbda17d
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,23 @@
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ public Dictionary Packages { get; set; } = new();
+ public int Id { get; set; }
+
+ [DisplayName("Название магазина")]
+ public string ShopName { get; set; } = string.Empty;
+ [DisplayName("Адрес магазина")]
+ public string ShopAddress { get; set; } = string.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IShopModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..a644274
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IShopModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationDataModels.Models
+{
+ public interface IShopModel : IId
+ {
+ public string ShopName { get; }
+ public string ShopAddress { get; }
+ DateTime OpeningDate { get; }
+ Dictionary Packages { get; }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
index 00565cd..81f4fb1 100644
--- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs
@@ -13,11 +13,13 @@ namespace SoftwareInstallationListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Packages { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Packages = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ShopStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..8befbfc
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,124 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.SearchModels;
+using SoftwareInstallationContracts.StoragesContracts;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Formats.Asn1.AsnWriter;
+
+namespace SoftwareInstallationListImplement.Implements
+{
+ 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.ShopName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (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.ShopName))
+ {
+ return result;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.ShopName.Contains(model.ShopName))
+ {
+ 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;
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Shop.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Shop.cs
new file mode 100644
index 0000000..0df1b1b
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Shop.cs
@@ -0,0 +1,60 @@
+using SoftwareInstallationContracts.BindingModels;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SoftwareInstallationListImplement.Models
+{
+ public class Shop : IShopModel
+ {
+ public string ShopName { get; private set; } = string.Empty;
+ public string ShopAddress { get; private set; } = string.Empty;
+
+ public DateTime OpeningDate { get; private set; }
+
+ public Dictionary Packages { 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,
+ ShopName = model.ShopName,
+ ShopAddress = model.ShopAddress,
+ OpeningDate = model.OpeningDate,
+ Packages = new()
+ };
+ }
+
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ ShopAddress = model.ShopAddress;
+ OpeningDate = model.OpeningDate;
+ Packages = model.Packages;
+ }
+
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ ShopAddress = ShopAddress,
+ OpeningDate = OpeningDate,
+ Packages = Packages
+ };
+ }
+}