diff --git a/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs
index 6a02953..d5e0186 100644
--- a/FlowerShop/FlowerShop/FormMain.Designer.cs
+++ b/FlowerShop/FlowerShop/FormMain.Designer.cs
@@ -38,6 +38,8 @@
this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.buttonSupplyShop = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
@@ -124,7 +126,8 @@
//
this.guidesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
- this.bouquetsToolStripMenuItem});
+ this.bouquetsToolStripMenuItem,
+ this.shopsToolStripMenuItem});
this.guidesToolStripMenuItem.Name = "guidesToolStripMenuItem";
this.guidesToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
this.guidesToolStripMenuItem.Text = "Справочники";
@@ -143,11 +146,29 @@
this.bouquetsToolStripMenuItem.Text = "Букеты";
this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click);
//
+ // shopsToolStripMenuItem
+ //
+ this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
+ this.shopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.shopsToolStripMenuItem.Text = "Магазины";
+ this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
+ //
+ // buttonSupplyShop
+ //
+ this.buttonSupplyShop.Location = new System.Drawing.Point(891, 202);
+ this.buttonSupplyShop.Name = "buttonSupplyShop";
+ this.buttonSupplyShop.Size = new System.Drawing.Size(150, 30);
+ this.buttonSupplyShop.TabIndex = 7;
+ this.buttonSupplyShop.Text = "Пополнение магазина";
+ this.buttonSupplyShop.UseVisualStyleBackColor = true;
+ this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1071, 401);
+ this.Controls.Add(this.buttonSupplyShop);
this.Controls.Add(this.buttonRefresh);
this.Controls.Add(this.buttonPut);
this.Controls.Add(this.buttonReady);
@@ -180,5 +201,7 @@
private ToolStripMenuItem componentsToolStripMenuItem;
private ToolStripMenuItem bouquetsToolStripMenuItem;
private Button buttonReady;
+ private ToolStripMenuItem shopsToolStripMenuItem;
+ private Button buttonSupplyShop;
}
}
\ No newline at end of file
diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs
index 63f690d..71b96b4 100644
--- a/FlowerShop/FlowerShop/FormMain.cs
+++ b/FlowerShop/FlowerShop/FormMain.cs
@@ -1,6 +1,5 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
-using FlowerShopDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace FlowerShop
@@ -154,5 +153,23 @@ namespace FlowerShop
{
LoadData();
}
+
+ private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void buttonSupplyShop_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
+ if (service is FormShopSupply form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/FlowerShop/FlowerShop/FormShop.Designer.cs b/FlowerShop/FlowerShop/FormShop.Designer.cs
new file mode 100644
index 0000000..c5f88b2
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShop.Designer.cs
@@ -0,0 +1,194 @@
+namespace FlowerShop
+{
+ partial class FormShop
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBoxAddress = new System.Windows.Forms.TextBox();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.labelAddress = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnBouquetName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.openDateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.openDateLabel = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // textBoxAddress
+ //
+ this.textBoxAddress.Location = new System.Drawing.Point(88, 34);
+ this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxAddress.Name = "textBoxAddress";
+ this.textBoxAddress.Size = new System.Drawing.Size(276, 23);
+ this.textBoxAddress.TabIndex = 7;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(88, 9);
+ this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(276, 23);
+ this.textBoxName.TabIndex = 6;
+ //
+ // labelAddress
+ //
+ this.labelAddress.AutoSize = true;
+ this.labelAddress.Location = new System.Drawing.Point(12, 38);
+ this.labelAddress.Name = "labelAddress";
+ this.labelAddress.Size = new System.Drawing.Size(43, 15);
+ this.labelAddress.TabIndex = 5;
+ this.labelAddress.Text = "Адрес:";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 11);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(62, 15);
+ this.labelName.TabIndex = 4;
+ this.labelName.Text = "Название:";
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ColumnId,
+ this.ColumnBouquetName,
+ this.ColumnCount});
+ this.dataGridView.Location = new System.Drawing.Point(12, 99);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(351, 224);
+ this.dataGridView.TabIndex = 10;
+ //
+ // ColumnId
+ //
+ this.ColumnId.HeaderText = "ID";
+ this.ColumnId.MinimumWidth = 6;
+ this.ColumnId.Name = "ColumnId";
+ this.ColumnId.Visible = false;
+ this.ColumnId.Width = 125;
+ //
+ // ColumnBouquetName
+ //
+ this.ColumnBouquetName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ColumnBouquetName.HeaderText = "Букет";
+ this.ColumnBouquetName.MinimumWidth = 6;
+ this.ColumnBouquetName.Name = "ColumnBouquetName";
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.MinimumWidth = 6;
+ this.ColumnCount.Name = "ColumnCount";
+ this.ColumnCount.Width = 125;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(200, 327);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(136, 31);
+ this.buttonCancel.TabIndex = 12;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(42, 327);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(136, 31);
+ this.buttonSave.TabIndex = 11;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // openDateTimePicker
+ //
+ this.openDateTimePicker.Location = new System.Drawing.Point(108, 62);
+ this.openDateTimePicker.Name = "openDateTimePicker";
+ this.openDateTimePicker.Size = new System.Drawing.Size(255, 23);
+ this.openDateTimePicker.TabIndex = 13;
+ //
+ // openDateLabel
+ //
+ this.openDateLabel.AutoSize = true;
+ this.openDateLabel.Location = new System.Drawing.Point(12, 68);
+ this.openDateLabel.Name = "openDateLabel";
+ this.openDateLabel.Size = new System.Drawing.Size(90, 15);
+ this.openDateLabel.TabIndex = 14;
+ this.openDateLabel.Text = "Дата открытия:";
+ //
+ // FormShop
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(389, 367);
+ this.Controls.Add(this.openDateLabel);
+ this.Controls.Add(this.openDateTimePicker);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.textBoxAddress);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelAddress);
+ this.Controls.Add(this.labelName);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormShop";
+ this.Text = "Магазин";
+ this.Load += new System.EventHandler(this.FormShop_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private TextBox textBoxAddress;
+ private TextBox textBoxName;
+ private Label labelAddress;
+ private Label labelName;
+ private DataGridView dataGridView;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnBouquetName;
+ private DataGridViewTextBoxColumn ColumnCount;
+ private DateTimePicker openDateTimePicker;
+ private Label openDateLabel;
+ }
+}
\ No newline at end of file
diff --git a/FlowerShop/FlowerShop/FormShop.cs b/FlowerShop/FlowerShop/FormShop.cs
new file mode 100644
index 0000000..c9beeb2
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShop.cs
@@ -0,0 +1,126 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.BusinessLogicsContracts;
+using FlowerShopContracts.SearchModels;
+using FlowerShopDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+namespace FlowerShop
+{
+ public partial class FormShop : Form
+ {
+
+ private readonly IShopLogic _logic;
+ private readonly ILogger _logger;
+ private Dictionary _shopBouquets;
+ private int? _id;
+ public int Id { set { _id = value; } }
+
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _shopBouquets = new();
+ }
+
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Loading shop");
+
+ try
+ {
+ var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
+
+ if (view != null)
+ {
+ textBoxName.Text = view.Name;
+ textBoxAddress.Text = view.Address;
+ openDateTimePicker.Value = view.OpeningDate;
+ _shopBouquets = view.ShopBouquets ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Loading shop's bouquets");
+
+ try
+ {
+ if (_shopBouquets != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var bouquet in _shopBouquets)
+ {
+ dataGridView.Rows.Add(new object[] { bouquet.Key, bouquet.Value.Item1.BouquetName, bouquet.Value.Item2 });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shop's bouquets");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (string.IsNullOrEmpty(textBoxAddress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Saving shop");
+
+ try
+ {
+ var model = new ShopBindingModel
+ {
+ Id = _id ?? 0,
+ Name = textBoxName.Text,
+ Address = textBoxAddress.Text,
+ OpeningDate = openDateTimePicker.Value,
+ ShopBouquets = _shopBouquets
+ };
+
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during saving shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/FlowerShop/FlowerShop/FormShop.resx b/FlowerShop/FlowerShop/FormShop.resx
new file mode 100644
index 0000000..325b208
--- /dev/null
+++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormShopSupply.Designer.cs b/FlowerShop/FlowerShop/FormShopSupply.Designer.cs
new file mode 100644
index 0000000..020c467
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShopSupply.Designer.cs
@@ -0,0 +1,150 @@
+namespace FlowerShop
+{
+ partial class FormShopSupply
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelShop = new System.Windows.Forms.Label();
+ this.labelBouquet = new System.Windows.Forms.Label();
+ this.labelBouquetsCount = new System.Windows.Forms.Label();
+ this.comboBoxShop = new System.Windows.Forms.ComboBox();
+ this.comboBoxBouquet = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelShop
+ //
+ this.labelShop.AutoSize = true;
+ this.labelShop.Location = new System.Drawing.Point(23, 14);
+ this.labelShop.Name = "labelShop";
+ this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.labelShop.Size = new System.Drawing.Size(57, 15);
+ this.labelShop.TabIndex = 0;
+ this.labelShop.Text = "Магазин:";
+ //
+ // labelBouquet
+ //
+ this.labelBouquet.AutoSize = true;
+ this.labelBouquet.Location = new System.Drawing.Point(23, 54);
+ this.labelBouquet.Name = "labelBouquet";
+ this.labelBouquet.Size = new System.Drawing.Size(40, 15);
+ this.labelBouquet.TabIndex = 1;
+ this.labelBouquet.Text = "Букет:";
+ //
+ // labelBouquetsCount
+ //
+ this.labelBouquetsCount.AutoSize = true;
+ this.labelBouquetsCount.Location = new System.Drawing.Point(23, 92);
+ this.labelBouquetsCount.Name = "labelBouquetsCount";
+ this.labelBouquetsCount.Size = new System.Drawing.Size(75, 15);
+ this.labelBouquetsCount.TabIndex = 2;
+ this.labelBouquetsCount.Text = "Количество:";
+ //
+ // comboBoxShop
+ //
+ this.comboBoxShop.FormattingEnabled = true;
+ this.comboBoxShop.Location = new System.Drawing.Point(130, 14);
+ this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.comboBoxShop.Name = "comboBoxShop";
+ this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
+ this.comboBoxShop.TabIndex = 3;
+ //
+ // comboBoxBouquet
+ //
+ this.comboBoxBouquet.FormattingEnabled = true;
+ this.comboBoxBouquet.Location = new System.Drawing.Point(130, 52);
+ this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.comboBoxBouquet.Name = "comboBoxBouquet";
+ this.comboBoxBouquet.Size = new System.Drawing.Size(220, 23);
+ this.comboBoxBouquet.TabIndex = 4;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(130, 89);
+ this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(110, 23);
+ this.textBoxCount.TabIndex = 5;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(288, 137);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(82, 34);
+ this.buttonCancel.TabIndex = 9;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(200, 137);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(82, 34);
+ this.buttonSave.TabIndex = 8;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // FormShopSupply
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(382, 182);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxBouquet);
+ this.Controls.Add(this.comboBoxShop);
+ this.Controls.Add(this.labelBouquetsCount);
+ this.Controls.Add(this.labelBouquet);
+ this.Controls.Add(this.labelShop);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormShopSupply";
+ this.Text = "Пополнение магазина";
+ this.Load += new System.EventHandler(this.FormShopSupply_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelShop;
+ private Label labelBouquet;
+ private Label labelBouquetsCount;
+ private ComboBox comboBoxShop;
+ private ComboBox comboBoxBouquet;
+ private TextBox textBoxCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/FlowerShop/FlowerShop/FormShopSupply.cs b/FlowerShop/FlowerShop/FormShopSupply.cs
new file mode 100644
index 0000000..8d93dad
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShopSupply.cs
@@ -0,0 +1,118 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.BusinessLogicsContracts;
+using FlowerShopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace FlowerShop
+{
+ public partial class FormShopSupply : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IBouquetLogic _logicBouquet;
+ private readonly IShopLogic _logicShop;
+
+ public FormShopSupply(ILogger logger, IBouquetLogic logicBouquet, IShopLogic logicShop)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicBouquet = logicBouquet;
+ _logicShop = logicShop;
+ }
+
+ private void FormShopSupply_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Loading bouquets for supplying");
+
+ try
+ {
+ var list = _logicBouquet.ReadList(null);
+ if (list != null)
+ {
+ comboBoxBouquet.DisplayMember = "BouquetName";
+ comboBoxBouquet.ValueMember = "Id";
+ comboBoxBouquet.DataSource = list;
+ comboBoxBouquet.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading bouquets for supplying");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ _logger.LogInformation("Loading shops for supplying");
+
+ try
+ {
+ var list = _logicShop.ReadList(null);
+ if (list != null)
+ {
+ comboBoxShop.DisplayMember = "Name";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = list;
+ comboBoxShop.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shops for supplying");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (comboBoxBouquet.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите букет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (comboBoxShop.SelectedValue== null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Creation of supply");
+
+ try
+ {
+ var operationResult = _logicShop.SupplyBouquets(
+ new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text },
+ new BouquetBindingModel { Id = Convert.ToInt32(comboBoxBouquet.SelectedValue), BouquetName = comboBoxBouquet.Text },
+ Convert.ToInt32(textBoxCount.Text)
+ );
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during creation of supply");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/FlowerShop/FlowerShop/FormShopSupply.resx b/FlowerShop/FlowerShop/FormShopSupply.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShopSupply.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/FlowerShop/FlowerShop/FormShops.Designer.cs b/FlowerShop/FlowerShop/FormShops.Designer.cs
new file mode 100644
index 0000000..25f541c
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShops.Designer.cs
@@ -0,0 +1,121 @@
+namespace FlowerShop
+{
+ partial class FormShops
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonEdit = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(10, 9);
+ this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(491, 320);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(549, 294);
+ this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(133, 33);
+ this.buttonUpdate.TabIndex = 9;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(549, 83);
+ this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(133, 33);
+ this.buttonDelete.TabIndex = 8;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
+ //
+ // buttonEdit
+ //
+ this.buttonEdit.Location = new System.Drawing.Point(549, 46);
+ this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonEdit.Name = "buttonEdit";
+ this.buttonEdit.Size = new System.Drawing.Size(133, 33);
+ this.buttonEdit.TabIndex = 7;
+ this.buttonEdit.Text = "Изменить";
+ this.buttonEdit.UseVisualStyleBackColor = true;
+ this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(549, 9);
+ this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(133, 33);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
+ //
+ // FormShops
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(700, 338);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.buttonEdit);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormShops";
+ this.Text = "Магазины";
+ this.Load += new System.EventHandler(this.FormShops_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonEdit;
+ private Button buttonAdd;
+ }
+}
\ No newline at end of file
diff --git a/FlowerShop/FlowerShop/FormShops.cs b/FlowerShop/FlowerShop/FormShops.cs
new file mode 100644
index 0000000..94df965
--- /dev/null
+++ b/FlowerShop/FlowerShop/FormShops.cs
@@ -0,0 +1,113 @@
+using FlowerShop;
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+
+namespace FlowerShop
+{
+ public partial class FormShops : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+
+ public FormShops(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormShops_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ShopBouquets"].Visible = false;
+ }
+
+ _logger.LogInformation("Loading shops");
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during loading shops");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+
+ if (service is FormShop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+
+ if (service is FormShop form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить магазин?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Deleting shop");
+
+ try
+ {
+ if (!_logic.Delete(new ShopBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error during deleting shop");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/FlowerShop/FlowerShop/FormShops.resx b/FlowerShop/FlowerShop/FormShops.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/Program.cs b/FlowerShop/FlowerShop/Program.cs
index d80bfe5..1ffdfe6 100644
--- a/FlowerShop/FlowerShop/Program.cs
+++ b/FlowerShop/FlowerShop/Program.cs
@@ -35,9 +35,11 @@ namespace FlowerShop
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -45,6 +47,9 @@ namespace FlowerShop
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs
index ec7e25c..9ef4477 100644
--- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -33,6 +33,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
+
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
@@ -53,51 +54,70 @@ namespace FlowerShopBusinessLogic.BusinessLogics
return true;
}
+
public bool TakeOrderInWork(OrderBindingModel model)
{
- return ChangeStatus(model, OrderStatus.Выполняется);
+ CheckModel(model, false);
+
+ if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят)
+ {
+ _logger.LogWarning("Invalid order status");
+ return false;
+ }
+
+ model.Status = OrderStatus.Выполняется;
+
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ }
+
+ return true;
}
public bool FinishOrder(OrderBindingModel model)
{
- return ChangeStatus(model, OrderStatus.Готов);
- }
- public bool DeliveryOrder(OrderBindingModel model)
- {
- return ChangeStatus(model, OrderStatus.Выдан);
- }
- public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
- {
- var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
- if (viewModel == null)
+ CheckModel(model, false);
+
+ if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется)
{
- throw new ArgumentNullException(nameof(model));
- }
- if (viewModel.Status + 1 != newStatus)
- {
- _logger.LogWarning("Change status operation failed");
+ _logger.LogWarning("Invalid order status");
return false;
}
- model.Status = newStatus;
- model.BouquetId = viewModel.BouquetId;
- model.Count = viewModel.Count;
- model.Sum = viewModel.Sum;
- model.DateCreate = viewModel.DateCreate;
- if (model.Status == OrderStatus.Готов)
- {
- model.DateImplement = DateTime.Now;
- }
- else
- {
- model.DateImplement = viewModel.DateImplement;
- }
- CheckModel(model);
+
+ model.Status = OrderStatus.Готов;
+ model.DateImplement = DateTime.Now;
+
if (_orderStorage.Update(model) == null)
{
- _logger.LogWarning("Change status operation failed");
- return false;
+ _logger.LogWarning("Update operation failed");
}
+
return true;
}
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+
+ var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
+
+ if (order?.Status != OrderStatus.Готов)
+ {
+ _logger.LogWarning("Invalid order status");
+ return false;
+ }
+
+ model.Status = OrderStatus.Выдан;
+ model.DateImplement = order.DateImplement;
+
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ }
+
+ return true;
+ }
+
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
@@ -110,22 +130,18 @@ namespace FlowerShopBusinessLogic.BusinessLogics
return;
}
- if (model.BouquetId < 0)
- {
- throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.BouquetId));
- }
-
- if (model.Count <= 0)
- {
- throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
- }
-
if (model.Sum <= 0)
{
- throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
+ throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum));
}
- _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. BouquetId: { BouquetId}", model.Id, model.Sum, model.BouquetId);
+ _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId);
+
+ var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
+ if (element != null && element.Id == model.Id)
+ {
+ throw new InvalidOperationException("Заказ с таким идентификатором уже есть");
+ }
}
}
}
diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ShopLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..560f0a8
--- /dev/null
+++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,178 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.BusinessLogicsContracts;
+using FlowerShopContracts.SearchModels;
+using FlowerShopContracts.StoragesContracts;
+using FlowerShopContracts.ViewModels;
+using FlowerShopDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+
+namespace FlowerShopBusinessLogic.BusinessLogics
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+
+ public ShopLogic(ILogger logger, IShopStorage shopStorage) {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.Name, model.Id);
+
+ var element = _shopStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement. element not found");
+ return null;
+ }
+
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+
+ return element;
+ }
+
+ public List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", model?.Name, model?.Id);
+
+ var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
+
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+
+ return list;
+ }
+
+ public bool SupplyBouquets(ShopSearchModel model, IBouquetModel bouquet, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (bouquet == null)
+ {
+ throw new ArgumentNullException(nameof(bouquet));
+ }
+
+ if (count <= 0)
+ {
+ throw new ArgumentNullException("Count of bouquets in supply must be more than 0", nameof(count));
+ }
+
+ var shopElement = _shopStorage.GetElement(model);
+ if (shopElement == null)
+ {
+ _logger.LogWarning("Required shop element not found in storage");
+ return false;
+ }
+
+ _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
+
+ if (shopElement.ShopBouquets.TryGetValue(bouquet.Id, out var sameBouquet))
+ {
+ shopElement.ShopBouquets[bouquet.Id] = (bouquet, sameBouquet.Item2 + count);
+ _logger.LogInformation("Same bouquet found by supply. Added {0} of {1} in {2} shop", count, bouquet.BouquetName, shopElement.Name);
+ }
+ else
+ {
+ shopElement.ShopBouquets[bouquet.Id] = (bouquet, count);
+ _logger.LogInformation("New bouquet added by supply. Added {0} of {1} in {2} shop", count, bouquet.BouquetName, shopElement.Name);
+ }
+
+ _shopStorage.Update(new()
+ {
+ Id = shopElement.Id,
+ Name = shopElement.Name,
+ Address = shopElement.Address,
+ OpeningDate = shopElement.OpeningDate,
+ ShopBouquets = shopElement.ShopBouquets
+ });
+
+ return true;
+ }
+
+ public bool Create(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool Update(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool Delete(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+
+ if (_shopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ private void CheckModel(ShopBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (!withParams)
+ {
+ return;
+ }
+
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
+ }
+
+ _logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id);
+
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ Name = model.Name
+ });
+
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ShopBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..783aafe
--- /dev/null
+++ b/FlowerShop/FlowerShopContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,17 @@
+using FlowerShopDataModels.Models;
+
+namespace FlowerShopContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public int Id { get; set; }
+
+ public string Name { get; set; } = string.Empty;
+
+ public string Address { get; set; } = string.Empty;
+
+ public DateTime OpeningDate { get; set; }
+
+ public Dictionary ShopBouquets { get; set; }
+ }
+}
diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..fc1d683
--- /dev/null
+++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,17 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.SearchModels;
+using FlowerShopContracts.ViewModels;
+using FlowerShopDataModels.Models;
+
+namespace FlowerShopContracts.BusinessLogicsContracts
+{
+ public interface IShopLogic
+ {
+ ShopViewModel? ReadElement(ShopSearchModel model);
+ List? ReadList(ShopSearchModel? model);
+ bool Create(ShopBindingModel model);
+ bool Update(ShopBindingModel model);
+ bool Delete(ShopBindingModel model);
+ bool SupplyBouquets(ShopSearchModel model, IBouquetModel bouquet, int count);
+ }
+}
diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ShopSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..5b03d1c
--- /dev/null
+++ b/FlowerShop/FlowerShopContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,8 @@
+namespace FlowerShopContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? Name { get; set; }
+ }
+}
diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..307e37c
--- /dev/null
+++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,16 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.SearchModels;
+using FlowerShopContracts.ViewModels;
+
+namespace FlowerShopContracts.StoragesContracts
+{
+ public interface IShopStorage
+ {
+ ShopViewModel? GetElement(ShopSearchModel model);
+ List GetFullList();
+ List GetFilteredList(ShopSearchModel model);
+ ShopViewModel? Insert(ShopBindingModel model);
+ ShopViewModel? Update(ShopBindingModel model);
+ ShopViewModel? Delete(ShopBindingModel model);
+ }
+}
diff --git a/FlowerShop/FlowerShopContracts/ViewModels/ShopViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..c2330da
--- /dev/null
+++ b/FlowerShop/FlowerShopContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,21 @@
+using FlowerShopDataModels.Models;
+using System.ComponentModel;
+
+namespace FlowerShopContracts.ViewModels
+{
+ public class ShopViewModel : IShopModel
+ {
+ public int Id { get; set; }
+
+ [DisplayName("Название магазина")]
+ public string Name { get; set; } = string.Empty;
+
+ [DisplayName("Адрес")]
+ public string Address { get; set; } = string.Empty;
+
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; }
+
+ public Dictionary ShopBouquets { get; set; } = new();
+ }
+}
diff --git a/FlowerShop/FlowerShopDataModels/Models/IShopModel.cs b/FlowerShop/FlowerShopDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..e9df4aa
--- /dev/null
+++ b/FlowerShop/FlowerShopDataModels/Models/IShopModel.cs
@@ -0,0 +1,10 @@
+namespace FlowerShopDataModels.Models
+{
+ public interface IShopModel : IId
+ {
+ string Name { get; }
+ string Address { get; }
+ DateTime OpeningDate { get; }
+ Dictionary ShopBouquets { get; }
+ }
+}
diff --git a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs
index 59460c6..e030e40 100644
--- a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs
+++ b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs
@@ -8,12 +8,14 @@ namespace FlowerShopListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Bouquets { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Bouquets = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
diff --git a/FlowerShop/FlowerShopListImplement/Implements/ShopStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..ad16fc1
--- /dev/null
+++ b/FlowerShop/FlowerShopListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,121 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.SearchModels;
+using FlowerShopContracts.StoragesContracts;
+using FlowerShopContracts.ViewModels;
+using FlowerShopListImplement.Models;
+
+
+namespace FlowerShopListImplement.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public ShopStorage()
{
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if ((!string.IsNullOrEmpty(model.Name) && shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id))
+ {
+ return shop.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ var result = new List();
+
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return result;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Name.Contains(model.Name))
+ {
+ result.Add(shop.GetViewModel);
+ }
+ }
+
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var shop in _source.Shops)
+ {
+ result.Add(shop.GetViewModel);
+ }
+
+ return result;
+ }
+
+ public ShopViewModel? Insert(ShopBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var shop in _source.Shops)
+ {
+ if (model.Id <= shop.Id)
+ {
+ model.Id = shop.Id + 1;
+ }
+ }
+
+ var newShop = Shop.Create(model);
+
+ if (newShop == null)
+ {
+ return null;
+ }
+
+ _source.Shops.Add(newShop);
+
+ return newShop.GetViewModel;
+ }
+
+ public ShopViewModel? Update(ShopBindingModel model)
+ {
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Id == model.Id)
+ {
+ shop.Update(model);
+ return shop.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ public ShopViewModel? Delete(ShopBindingModel model)
+ {
+ for (int i = 0; i < _source.Shops.Count; ++i)
+ {
+ if (_source.Shops[i].Id == model.Id)
+ {
+ var element = _source.Shops[i];
+ _source.Shops.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/FlowerShop/FlowerShopListImplement/Models/Shop.cs b/FlowerShop/FlowerShopListImplement/Models/Shop.cs
new file mode 100644
index 0000000..abbdf34
--- /dev/null
+++ b/FlowerShop/FlowerShopListImplement/Models/Shop.cs
@@ -0,0 +1,57 @@
+using FlowerShopContracts.BindingModels;
+using FlowerShopContracts.ViewModels;
+using FlowerShopDataModels.Models;
+
+namespace FlowerShopListImplement.Models
+{
+ public class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+
+ public string Name { get; private set; } = string.Empty;
+
+ public string Address { get; private set; } = string.Empty;
+
+ public DateTime OpeningDate { get; private set; }
+
+ public Dictionary ShopBouquets { get; private set; } = new();
+
+ public static Shop? Create(ShopBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Shop()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ Address = model.Address,
+ OpeningDate = model.OpeningDate,
+ ShopBouquets = new()
+ };
+ }
+
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ Name = model.Name;
+ Address = model.Address;
+ ShopBouquets = model.ShopBouquets;
+ }
+
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ Address = Address,
+ OpeningDate = OpeningDate,
+ ShopBouquets = ShopBouquets
+ };
+ }
+}