diff --git a/Confectionery/Confectionery/FormDelivery.Designer.cs b/Confectionery/Confectionery/FormDelivery.Designer.cs
new file mode 100644
index 0000000..d5ce91f
--- /dev/null
+++ b/Confectionery/Confectionery/FormDelivery.Designer.cs
@@ -0,0 +1,143 @@
+namespace Confectionery
+{
+ partial class FormDelivery
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.comboBoxShop = new System.Windows.Forms.ComboBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.comboBoxPastry = new System.Windows.Forms.ComboBox();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(254, 130);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 15;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Location = new System.Drawing.Point(142, 130);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(94, 29);
+ this.buttonCreate.TabIndex = 14;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(129, 84);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.Size = new System.Drawing.Size(219, 27);
+ this.textBoxSum.TabIndex = 13;
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.FormattingEnabled = true;
+ this.comboBoxShop.Location = new System.Drawing.Point(129, 6);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(219, 28);
+ this.comboBoxShop.TabIndex = 11;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(12, 87);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(93, 20);
+ this.label3.TabIndex = 10;
+ this.label3.Text = "Количество:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(12, 47);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(71, 20);
+ this.label2.TabIndex = 9;
+ this.label2.Text = "Изделие:";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 9);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(72, 20);
+ this.label1.TabIndex = 8;
+ this.label1.Text = "Магазин:";
+ //
+ // comboBoxPastry
+ //
+ this.comboBoxPastry.FormattingEnabled = true;
+ this.comboBoxPastry.Location = new System.Drawing.Point(129, 44);
+ this.comboBoxPastry.Name = "comboBoxPastry";
+ this.comboBoxPastry.Size = new System.Drawing.Size(219, 28);
+ this.comboBoxPastry.TabIndex = 16;
+ //
+ // FormDelivery
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(359, 173);
+ this.Controls.Add(this.comboBoxPastry);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormDelivery";
+ this.Text = "FormDelivery";
+ this.Load += new System.EventHandler(this.FormDelivery_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonCreate;
+ private TextBox textBoxSum;
+ private ComboBox comboBoxShop;
+ private Label label3;
+ private Label label2;
+ private Label label1;
+ private ComboBox comboBoxPastry;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormDelivery.cs b/Confectionery/Confectionery/FormDelivery.cs
new file mode 100644
index 0000000..3a0832e
--- /dev/null
+++ b/Confectionery/Confectionery/FormDelivery.cs
@@ -0,0 +1,107 @@
+using ConfectioneryContracts.BusinessLogicsContracts;
+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;
+using Microsoft.Extensions.Logging;
+using System.Collections;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryContracts.BindingModels;
+
+namespace Confectionery
+{
+ public partial class FormDelivery : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IPastryLogic _logicP;
+ private readonly IShopLogic _logicS;
+ private List? _listPastry;
+ private List? _listShop;
+ public FormDelivery(ILogger logger, IPastryLogic logicP, IShopLogic logicS)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicP = logicP;
+ _logicS = logicS;
+ }
+
+ private void FormDelivery_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка магазинов для поставки");
+ _listShop = _logicS.ReadList(null);
+ if (_listShop != null)
+ {
+ comboBoxShop.DisplayMember = "ShopName";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = _listShop;
+ comboBoxShop.SelectedItem = null;
+ }
+ _logger.LogInformation("Загрузка изделий для поставки");
+ _listPastry = _logicP.ReadList(null);
+ if (_listPastry != null)
+ {
+ comboBoxPastry.DisplayMember = "PastryName";
+ comboBoxPastry.ValueMember = "Id";
+ comboBoxPastry.DataSource = _listPastry;
+ comboBoxPastry.SelectedItem = null;
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxPastry.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (String.IsNullOrEmpty(textBoxSum.Text))
+ {
+ MessageBox.Show("Заполните поле количество!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ try
+ {
+ ShopBindingModel shop = new ShopBindingModel
+ {
+ Id = Convert.ToInt32(comboBoxShop.SelectedValue)
+ };
+ PastryBindingModel pastry = new PastryBindingModel
+ {
+ Id = Convert.ToInt32(comboBoxPastry.SelectedValue),
+ PastryName = comboBoxPastry.Text
+ };
+ int count = Convert.ToInt32(textBoxSum.Text);
+ bool operationResult = _logicS.DeliverPastryToShop(shop, pastry, count);
+ 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);
+ }
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormDelivery.resx b/Confectionery/Confectionery/FormDelivery.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Confectionery/Confectionery/FormDelivery.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs
index 1b586a0..f2e480d 100644
--- a/Confectionery/Confectionery/FormMain.Designer.cs
+++ b/Confectionery/Confectionery/FormMain.Designer.cs
@@ -32,12 +32,14 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
+ this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@@ -46,7 +48,8 @@
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.справочникиToolStripMenuItem});
+ this.справочникиToolStripMenuItem,
+ this.пополнениеМагазинаToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1238, 28);
@@ -57,7 +60,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ингредиентыToolStripMenuItem,
- this.изделияToolStripMenuItem});
+ this.изделияToolStripMenuItem,
+ this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -76,6 +80,13 @@
this.изделияToolStripMenuItem.Text = "Кондитерские изделия";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click);
//
+ // магазиныToolStripMenuItem
+ //
+ this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(251, 26);
+ this.магазиныToolStripMenuItem.Text = "Магазины";
+ this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
+ //
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
@@ -139,6 +150,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
//
+ // пополнениеМагазинаToolStripMenuItem
+ //
+ this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
+ this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24);
+ this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
+ this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.пополнениеМагазинаToolStripMenuItem_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
@@ -175,5 +193,7 @@
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs
index 5a41079..390c971 100644
--- a/Confectionery/Confectionery/FormMain.cs
+++ b/Confectionery/Confectionery/FormMain.cs
@@ -152,5 +152,23 @@ namespace Confectionery
{
LoadData();
}
+
+ 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)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormDelivery));
+ if (service is FormDelivery form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/Confectionery/Confectionery/FormShop.Designer.cs b/Confectionery/Confectionery/FormShop.Designer.cs
new file mode 100644
index 0000000..1cdb588
--- /dev/null
+++ b/Confectionery/Confectionery/FormShop.Designer.cs
@@ -0,0 +1,196 @@
+namespace Confectionery
+{
+ 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.textBoxAdress = new System.Windows.Forms.TextBox();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.openingDateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.label2 = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.PastryId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.PastryName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // textBoxAdress
+ //
+ this.textBoxAdress.Location = new System.Drawing.Point(120, 38);
+ this.textBoxAdress.Name = "textBoxAdress";
+ this.textBoxAdress.Size = new System.Drawing.Size(350, 27);
+ this.textBoxAdress.TabIndex = 11;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(120, 6);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(350, 27);
+ this.textBoxName.TabIndex = 10;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(60, 41);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(54, 20);
+ this.label1.TabIndex = 9;
+ this.label1.Text = "Адрес:";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(34, 9);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(80, 20);
+ this.labelName.TabIndex = 8;
+ this.labelName.Text = "Название:";
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(376, 276);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(94, 29);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(276, 276);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(94, 29);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // openingDateTimePicker
+ //
+ this.openingDateTimePicker.Location = new System.Drawing.Point(120, 72);
+ this.openingDateTimePicker.Name = "openingDateTimePicker";
+ this.openingDateTimePicker.Size = new System.Drawing.Size(350, 27);
+ this.openingDateTimePicker.TabIndex = 12;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(1, 72);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(113, 20);
+ this.label2.TabIndex = 13;
+ this.label2.Text = "Дата открытия:";
+ //
+ // dataGridView
+ //
+ this.dataGridView.AllowUserToAddRows = false;
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.PastryId,
+ this.PastryName,
+ this.Count});
+ this.dataGridView.Location = new System.Drawing.Point(120, 105);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(350, 165);
+ this.dataGridView.TabIndex = 14;
+ //
+ // PastryId
+ //
+ this.PastryId.HeaderText = "Id";
+ this.PastryId.MinimumWidth = 6;
+ this.PastryId.Name = "PastryId";
+ this.PastryId.ReadOnly = true;
+ this.PastryId.Visible = false;
+ this.PastryId.Width = 125;
+ //
+ // PastryName
+ //
+ this.PastryName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.PastryName.HeaderText = "Название изделия";
+ this.PastryName.MinimumWidth = 6;
+ this.PastryName.Name = "PastryName";
+ this.PastryName.ReadOnly = true;
+ //
+ // Count
+ //
+ this.Count.HeaderText = "Количество";
+ this.Count.MinimumWidth = 6;
+ this.Count.Name = "Count";
+ this.Count.ReadOnly = true;
+ this.Count.Width = 125;
+ //
+ // FormShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(478, 317);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.openingDateTimePicker);
+ this.Controls.Add(this.textBoxAdress);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ 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 textBoxAdress;
+ private TextBox textBoxName;
+ private Label label1;
+ private Label labelName;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DateTimePicker openingDateTimePicker;
+ private Label label2;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn PastryId;
+ private DataGridViewTextBoxColumn PastryName;
+ private DataGridViewTextBoxColumn Count;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormShop.cs b/Confectionery/Confectionery/FormShop.cs
new file mode 100644
index 0000000..8e48dbc
--- /dev/null
+++ b/Confectionery/Confectionery/FormShop.cs
@@ -0,0 +1,109 @@
+using ConfectioneryContracts.BusinessLogicsContracts;
+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;
+using Microsoft.Extensions.Logging;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryBusinessLogic.BusinessLogics;
+using ConfectioneryDataModels.Models;
+
+namespace Confectionery
+{
+ public partial class FormShop : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ private Dictionary _shopPastries = new Dictionary();
+
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logic = logic;
+ _logger = logger;
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxAdress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение магазина");
+ try
+ {
+ var model = new ShopBindingModel
+ {
+ Id = _id ?? 0,
+ ShopName = textBoxName.Text,
+ ShopAdress = textBoxAdress.Text,
+ OpeningDate = openingDateTimePicker.Value.Date,
+ ShopPastries = _shopPastries
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение магазина");
+ var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
+ if (view != null)
+ {
+ textBoxName.Text = view.ShopName;
+ textBoxAdress.Text = view.ShopAdress;
+ openingDateTimePicker.Value = view.OpeningDate;
+ _shopPastries = view.ShopPastries;
+ foreach (var pc in view.ShopPastries)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.PastryName, pc.Value.Item2 });
+ }
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ _logger.LogInformation("Загрузка заказов");
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormShop.resx b/Confectionery/Confectionery/FormShop.resx
new file mode 100644
index 0000000..0710772
--- /dev/null
+++ b/Confectionery/Confectionery/FormShop.resx
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormShops.Designer.cs b/Confectionery/Confectionery/FormShops.Designer.cs
new file mode 100644
index 0000000..5b49c74
--- /dev/null
+++ b/Confectionery/Confectionery/FormShops.Designer.cs
@@ -0,0 +1,119 @@
+namespace Confectionery
+{
+ 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.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(524, 185);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(94, 29);
+ this.buttonRef.TabIndex = 9;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(524, 127);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(94, 29);
+ this.buttonDel.TabIndex = 8;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(524, 70);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(94, 29);
+ this.buttonUpd.TabIndex = 7;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(524, 13);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(94, 29);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(2, 1);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(489, 449);
+ this.dataGridView.TabIndex = 5;
+ //
+ // FormShops
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(626, 450);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormShops";
+ this.Text = "Магазины";
+ this.Load += new System.EventHandler(this.FormShops_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormShops.cs b/Confectionery/Confectionery/FormShops.cs
new file mode 100644
index 0000000..106bdc6
--- /dev/null
+++ b/Confectionery/Confectionery/FormShops.cs
@@ -0,0 +1,111 @@
+using ConfectioneryContracts.BusinessLogicsContracts;
+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;
+using Microsoft.Extensions.Logging;
+using ConfectioneryContracts.BindingModels;
+
+namespace Confectionery
+{
+ 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["ShopPastries"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление магазина");
+ try
+ {
+ if (!_logic.Delete(new ShopBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormShops.resx b/Confectionery/Confectionery/FormShops.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Confectionery/Confectionery/FormShops.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs
index c98764e..d812df3 100644
--- a/Confectionery/Confectionery/Program.cs
+++ b/Confectionery/Confectionery/Program.cs
@@ -38,9 +38,11 @@ namespace Confectionery
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -48,6 +50,9 @@ namespace Confectionery
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..1ba2248
--- /dev/null
+++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,160 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryBusinessLogic.BusinessLogics
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+
+ public ShopLogic(ILogger logger, IShopStorage shopStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+
+ public List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ShopName:{ShopName}. Id:{Id}", model?.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 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 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);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_shopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ShopBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия иагазина", nameof(model.ShopName));
+ }
+ if (string.IsNullOrEmpty(model.ShopAdress))
+ {
+ throw new ArgumentNullException("Нет адресса иагазина", nameof(model.ShopAdress));
+ }
+ _logger.LogInformation("Shop. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+
+ public bool DeliverPastryToShop(ShopBindingModel shopModel, IPastryModel pastryModel, int count)
+ {
+ CheckModel(shopModel, false);
+ if (pastryModel == null)
+ {
+ throw new ArgumentNullException(nameof(pastryModel));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentNullException("Количество изделий в поставке должно быть больше нуля!");
+ }
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ Id = shopModel.Id
+ });
+ if (element == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ _logger.LogInformation("Delivery. ShopName:{ShopName}. Id:{Id}. PastryName:{PastryName}. Count:{count}", element.ShopName, element.Id, pastryModel.PastryName, count);
+ if (element.ShopPastries.TryGetValue(pastryModel.Id, out var shopPastry))
+ {
+ element.ShopPastries[pastryModel.Id] = (pastryModel, shopPastry.Item2 + count);
+ }
+ else
+ {
+ element.ShopPastries.Add(pastryModel.Id, (pastryModel, count));
+ }
+ _shopStorage.Update(new ShopBindingModel
+ {
+ Id = element.Id,
+ ShopName = element.ShopName,
+ ShopAdress = element.ShopAdress,
+ OpeningDate = element.OpeningDate,
+ ShopPastries = element.ShopPastries
+ });
+ return true;
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..fcaec17
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,22 @@
+using ConfectioneryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public int Id { get; set; }
+ public string ShopName { get; set; } = string.Empty;
+ public string ShopAdress { get; set; } = string.Empty;
+ public DateTime OpeningDate { get; set; }
+ public Dictionary ShopPastries
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..24b6427
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,22 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.BusinessLogicsContracts
+{
+ public interface IShopLogic
+ {
+ List? ReadList(ShopSearchModel? model);
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ bool DeliverPastryToShop(ShopBindingModel shopModel, IPastryModel pastryModel, int count);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..36ddd80
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..86d0e18
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,21 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.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);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..d904197
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,26 @@
+using ConfectioneryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название магазина")]
+ public string ShopName { get; set; } = String.Empty;
+ [DisplayName("Адресс магазина")]
+ public string ShopAdress { get; set; } = String.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; }
+ public Dictionary ShopPastries
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs b/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..307a2eb
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/Models/IShopModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryDataModels.Models
+{
+ public interface IShopModel : IId
+ {
+ string ShopName { get; }
+ string ShopAdress { get; }
+ DateTime OpeningDate { get; }
+ Dictionary ShopPastries { get; }
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
index 2cce9b4..101ae29 100644
--- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
+++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
@@ -14,11 +14,13 @@ namespace ConfectioneryListImplement
public List Ingredients { get; set; }
public List Orders { get; set; }
public List Pastries { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Ingredients = new List();
Orders = new List();
Pastries = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..f95cb0a
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,111 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryListImplement.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var shop in _source.Shops)
+ {
+ result.Add(shop.GetViewModel);
+ }
+ return result;
+ }
+
+ 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 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 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/Confectionery/ConfectioneryListImplement/Models/Shop.cs b/Confectionery/ConfectioneryListImplement/Models/Shop.cs
new file mode 100644
index 0000000..c264be8
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Models/Shop.cs
@@ -0,0 +1,55 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryListImplement.Models
+{
+ public class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+ public string ShopName { get; private set; } = string.Empty;
+ public string ShopAdress { get; private set; } = string.Empty;
+ public DateTime OpeningDate { get; private set; }
+ public Dictionary ShopPastries { get; private set; } = new Dictionary();
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+ Id = model.Id,
+ ShopName = model.ShopName,
+ ShopAdress = model.ShopAdress,
+ OpeningDate = model.OpeningDate,
+ ShopPastries = model.ShopPastries
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ ShopAdress = model.ShopAdress;
+ OpeningDate = model.OpeningDate;
+ ShopPastries = model.ShopPastries;
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ ShopAdress = ShopAdress,
+ ShopPastries = ShopPastries,
+ OpeningDate = OpeningDate
+ };
+ }
+}