diff --git a/FishFactory/FormCanned.Designer.cs b/FishFactory/FormCanned.Designer.cs
index db5feff..8297f20 100644
--- a/FishFactory/FormCanned.Designer.cs
+++ b/FishFactory/FormCanned.Designer.cs
@@ -35,14 +35,14 @@
buttonDel = new Button();
buttonRef = new Button();
dataGridView = new DataGridView();
- Number = new DataGridViewTextBoxColumn();
- Component = new DataGridViewTextBoxColumn();
- Count = new DataGridViewTextBoxColumn();
textBoxName = new TextBox();
textBoxPrice = new TextBox();
groupBox1 = new GroupBox();
buttonSave = new Button();
buttonCancel = new Button();
+ Number = new DataGridViewTextBoxColumn();
+ Component = new DataGridViewTextBoxColumn();
+ Count = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBox1.SuspendLayout();
SuspendLayout();
@@ -124,27 +124,6 @@
dataGridView.Size = new Size(627, 443);
dataGridView.TabIndex = 4;
//
- // Number
- //
- Number.HeaderText = "Номер";
- Number.MinimumWidth = 6;
- Number.Name = "Number";
- Number.Width = 60;
- //
- // Component
- //
- Component.HeaderText = "Компонент";
- Component.MinimumWidth = 6;
- Component.Name = "Component";
- Component.Width = 125;
- //
- // Count
- //
- Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- Count.HeaderText = "Количество";
- Count.MinimumWidth = 6;
- Count.Name = "Count";
- //
// textBoxName
//
textBoxName.Location = new Point(107, 18);
@@ -201,6 +180,31 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
+ // Number
+ //
+ Number.HeaderText = "Номер";
+ Number.MinimumWidth = 6;
+ Number.Name = "Number";
+ Number.ReadOnly = true;
+ Number.Visible = false;
+ Number.Width = 60;
+ //
+ // Component
+ //
+ Component.HeaderText = "Компонент";
+ Component.MinimumWidth = 6;
+ Component.Name = "Component";
+ Component.ReadOnly = true;
+ Component.Width = 125;
+ //
+ // Count
+ //
+ Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ Count.HeaderText = "Количество";
+ Count.MinimumWidth = 6;
+ Count.Name = "Count";
+ Count.ReadOnly = true;
+ //
// FormCanned
//
AutoScaleDimensions = new SizeF(8F, 20F);
diff --git a/FishFactory/FormCanneds.Designer.cs b/FishFactory/FormCanneds.Designer.cs
index 59ee6c4..3ce1fb8 100644
--- a/FishFactory/FormCanneds.Designer.cs
+++ b/FishFactory/FormCanneds.Designer.cs
@@ -89,6 +89,7 @@
dataGridView.ReadOnly = true;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 24;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(709, 568);
dataGridView.TabIndex = 5;
//
diff --git a/FishFactory/FormCanneds.cs b/FishFactory/FormCanneds.cs
index 6cbeb50..840349f 100644
--- a/FishFactory/FormCanneds.cs
+++ b/FishFactory/FormCanneds.cs
@@ -1,14 +1,4 @@
-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 FishFactory;
-using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
diff --git a/FishFactory/FormComponent.cs b/FishFactory/FormComponent.cs
index 86b613f..57f0fed 100644
--- a/FishFactory/FormComponent.cs
+++ b/FishFactory/FormComponent.cs
@@ -1,15 +1,5 @@
-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 Microsoft.Extensions.Logging;
using FishFactoryContracts.BusinessLogicsContracts;
-using Microsoft.VisualBasic.Logging;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.BindingModels;
diff --git a/FishFactory/FormComponents.cs b/FishFactory/FormComponents.cs
index ef3531a..925119a 100644
--- a/FishFactory/FormComponents.cs
+++ b/FishFactory/FormComponents.cs
@@ -1,15 +1,6 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
namespace FishFactory.Forms
{
diff --git a/FishFactory/FormMain.Designer.cs b/FishFactory/FormMain.Designer.cs
index 73fef74..20fcb49 100644
--- a/FishFactory/FormMain.Designer.cs
+++ b/FishFactory/FormMain.Designer.cs
@@ -33,12 +33,14 @@
toolStripDropDownButton1 = new ToolStripDropDownButton();
компонентыToolStripMenuItem = new ToolStripMenuItem();
консервыToolStripMenuItem = new ToolStripMenuItem();
+ магазиныToolStripMenuItem = new ToolStripMenuItem();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
dataGridView = new DataGridView();
+ toolStripLabelReplenish2 = new ToolStripLabel();
toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -46,7 +48,7 @@
// toolStrip1
//
toolStrip1.ImageScalingSize = new Size(20, 20);
- toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 });
+ toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish2 });
toolStrip1.Location = new Point(0, 0);
toolStrip1.Name = "toolStrip1";
toolStrip1.Size = new Size(1107, 27);
@@ -56,7 +58,7 @@
// toolStripDropDownButton1
//
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
- toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem });
+ toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, магазиныToolStripMenuItem });
toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image");
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
@@ -77,6 +79,13 @@
консервыToolStripMenuItem.Text = "Консервы";
консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click;
//
+ // магазиныToolStripMenuItem
+ //
+ магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ магазиныToolStripMenuItem.Size = new Size(182, 26);
+ магазиныToolStripMenuItem.Text = "Магазины";
+ магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
+ //
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(914, 75);
@@ -145,6 +154,14 @@
dataGridView.Size = new Size(872, 580);
dataGridView.TabIndex = 6;
//
+ // toolStripLabelReplenish2
+ //
+ toolStripLabelReplenish2.DisplayStyle = ToolStripItemDisplayStyle.Text;
+ toolStripLabelReplenish2.Name = "toolStripLabelReplenish2";
+ toolStripLabelReplenish2.Size = new Size(168, 24);
+ toolStripLabelReplenish2.Text = "Пополнение магазина";
+ toolStripLabelReplenish2.Click += toolStripLabelReplenish_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -180,5 +197,7 @@
private ToolStripDropDownButton toolStripDropDownButton1;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem консервыToolStripMenuItem;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private ToolStripLabel toolStripLabelReplenish2;
}
}
\ No newline at end of file
diff --git a/FishFactory/FormMain.cs b/FishFactory/FormMain.cs
index b8c0b8f..ba5fd14 100644
--- a/FishFactory/FormMain.cs
+++ b/FishFactory/FormMain.cs
@@ -1,15 +1,6 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
namespace FishFactory.Forms
{
@@ -65,6 +56,26 @@ namespace FishFactory.Forms
form.ShowDialog();
}
}
+
+ private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void toolStripLabelReplenish_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenish));
+ if (service is FormShopReplenish form)
+ {
+ form.ShowDialog();
+ }
+ }
+
private void buttonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
diff --git a/FishFactory/FormShop.Designer.cs b/FishFactory/FormShop.Designer.cs
new file mode 100644
index 0000000..4724e4e
--- /dev/null
+++ b/FishFactory/FormShop.Designer.cs
@@ -0,0 +1,179 @@
+namespace FishFactory.Forms
+{
+ 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()
+ {
+ label1 = new Label();
+ label2 = new Label();
+ textBoxShopName = new TextBox();
+ textBoxAdress = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ dataGridView = new DataGridView();
+ CannedName = new DataGridViewTextBoxColumn();
+ Count = new DataGridViewTextBoxColumn();
+ label3 = new Label();
+ openingDatePicker = new DateTimePicker();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(12, 23);
+ label1.Name = "label1";
+ label1.Size = new Size(80, 20);
+ label1.TabIndex = 0;
+ label1.Text = "Название:";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(12, 67);
+ label2.Name = "label2";
+ label2.Size = new Size(54, 20);
+ label2.TabIndex = 1;
+ label2.Text = "Адрес:";
+ //
+ // textBoxShopName
+ //
+ textBoxShopName.Location = new Point(103, 20);
+ textBoxShopName.Name = "textBoxShopName";
+ textBoxShopName.Size = new Size(304, 27);
+ textBoxShopName.TabIndex = 2;
+ //
+ // textBoxAdress
+ //
+ textBoxAdress.Location = new Point(103, 60);
+ textBoxAdress.Name = "textBoxAdress";
+ textBoxAdress.Size = new Size(304, 27);
+ textBoxAdress.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(513, 509);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(123, 33);
+ buttonSave.TabIndex = 4;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(663, 509);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(123, 33);
+ buttonCancel.TabIndex = 5;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { CannedName, Count });
+ dataGridView.Location = new Point(0, 108);
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(851, 376);
+ dataGridView.TabIndex = 6;
+ //
+ // CannedName
+ //
+ CannedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ CannedName.HeaderText = "Консерва";
+ CannedName.MinimumWidth = 6;
+ CannedName.Name = "CannedName";
+ CannedName.ReadOnly = true;
+ //
+ // Count
+ //
+ Count.HeaderText = "Количество";
+ Count.MinimumWidth = 125;
+ Count.Name = "Count";
+ Count.ReadOnly = true;
+ Count.Width = 170;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(438, 23);
+ label3.Name = "label3";
+ label3.Size = new Size(113, 20);
+ label3.TabIndex = 7;
+ label3.Text = "Дата открытия:";
+ //
+ // openingDatePicker
+ //
+ openingDatePicker.Location = new Point(557, 20);
+ openingDatePicker.Name = "openingDatePicker";
+ openingDatePicker.Size = new Size(294, 27);
+ openingDatePicker.TabIndex = 8;
+ //
+ // FormShop
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(863, 568);
+ Controls.Add(openingDatePicker);
+ Controls.Add(label3);
+ Controls.Add(dataGridView);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxAdress);
+ Controls.Add(textBoxShopName);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormShop";
+ Text = "Магазин";
+ Load += FormShop_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label label1;
+ private Label label2;
+ private TextBox textBoxShopName;
+ private TextBox textBoxAdress;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn CannedName;
+ private DataGridViewTextBoxColumn Count;
+ private Label label3;
+ private DateTimePicker openingDatePicker;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/FormShop.cs b/FishFactory/FormShop.cs
new file mode 100644
index 0000000..c6d705e
--- /dev/null
+++ b/FishFactory/FormShop.cs
@@ -0,0 +1,119 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using FishFactoryDataModel.Models;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactory.Forms
+{
+ public partial class FormShop : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ private Dictionary _shopCanneds;
+ private DateTime? _openingDate = null;
+
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _shopCanneds = new Dictionary();
+ }
+
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка магазина");
+ try
+ {
+ var view = _logic.ReadElement(new ShopSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxShopName.Text = view.ShopName;
+ textBoxAdress.Text = view.Adress;
+ openingDatePicker.Value = view.OpeningDate;
+ _shopCanneds = view.ShopCanneds ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка изделий в магазине");
+ try
+ {
+ if (_shopCanneds != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var sr in _shopCanneds)
+ {
+ dataGridView.Rows.Add(new object[] { sr.Value.Item1.CannedName, sr.Value.Item2});
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделий магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxShopName.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 = textBoxShopName.Text,
+ Adress = textBoxAdress.Text,
+ OpeningDate = openingDatePicker.Value
+ };
+ 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 buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/FishFactory/FormShop.resx b/FishFactory/FormShop.resx
new file mode 100644
index 0000000..aefdb73
--- /dev/null
+++ b/FishFactory/FormShop.resx
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/FishFactory/FormShopReplenish.Designer.cs b/FishFactory/FormShopReplenish.Designer.cs
new file mode 100644
index 0000000..8a1f13b
--- /dev/null
+++ b/FishFactory/FormShopReplenish.Designer.cs
@@ -0,0 +1,142 @@
+namespace FishFactory.Forms
+{
+ partial class FormShopReplenish
+ {
+ ///
+ /// 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()
+ {
+ label1 = new Label();
+ label2 = new Label();
+ label3 = new Label();
+ comboBoxShopCanneds = new ComboBox();
+ comboBoxCanned = new ComboBox();
+ textBoxCount = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(23, 33);
+ label1.Name = "label1";
+ label1.Size = new Size(72, 20);
+ label1.TabIndex = 0;
+ label1.Text = "Магазин:";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(23, 78);
+ label2.Name = "label2";
+ label2.Size = new Size(79, 20);
+ label2.TabIndex = 1;
+ label2.Text = "Консерва:";
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(23, 126);
+ label3.Name = "label3";
+ label3.Size = new Size(93, 20);
+ label3.TabIndex = 2;
+ label3.Text = "Количество:";
+ //
+ // comboBoxShopCanneds
+ //
+ comboBoxShopCanneds.FormattingEnabled = true;
+ comboBoxShopCanneds.Location = new Point(140, 33);
+ comboBoxShopCanneds.Name = "comboBoxShopCanneds";
+ comboBoxShopCanneds.Size = new Size(383, 28);
+ comboBoxShopCanneds.TabIndex = 3;
+ //
+ // comboBoxCanned
+ //
+ comboBoxCanned.FormattingEnabled = true;
+ comboBoxCanned.Location = new Point(140, 78);
+ comboBoxCanned.Name = "comboBoxCanned";
+ comboBoxCanned.Size = new Size(383, 28);
+ comboBoxCanned.TabIndex = 4;
+ //
+ // textBoxCount
+ //
+ textBoxCount.Location = new Point(140, 123);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(199, 27);
+ textBoxCount.TabIndex = 5;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(281, 175);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(107, 34);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(407, 175);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(107, 34);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormShopReplenish
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(538, 221);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxCount);
+ Controls.Add(comboBoxCanned);
+ Controls.Add(comboBoxShopCanneds);
+ Controls.Add(label3);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormShopReplenish";
+ Text = "Пополнение магазина";
+ Load += FormShopReplenish_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label label1;
+ private Label label2;
+ private Label label3;
+ private ComboBox comboBoxShopCanneds;
+ private ComboBox comboBoxCanned;
+ private TextBox textBoxCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/FormShopReplenish.cs b/FishFactory/FormShopReplenish.cs
new file mode 100644
index 0000000..19a45f3
--- /dev/null
+++ b/FishFactory/FormShopReplenish.cs
@@ -0,0 +1,88 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactory.Forms
+{
+ public partial class FormShopReplenish : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICannedLogic _logicP;
+ private readonly IShopLogic _logicS;
+ private List _shopList = new List();
+ private List _cannedList = new List();
+
+ public FormShopReplenish(ILogger logger, ICannedLogic logicP, IShopLogic logicS)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicP = logicP;
+ _logicS = logicS;
+ }
+
+ private void FormShopReplenish_Load(object sender, EventArgs e)
+ {
+ _shopList = _logicS.ReadList(null);
+ _cannedList = _logicP.ReadList(null);
+ if (_shopList != null)
+ {
+ comboBoxShopCanneds.DisplayMember = "ShopName";
+ comboBoxShopCanneds.ValueMember = "Id";
+ comboBoxShopCanneds.DataSource = _shopList;
+ comboBoxShopCanneds.SelectedItem = null;
+ _logger.LogInformation("Загрузка магазинов для поставок");
+ }
+ if (_cannedList != null)
+ {
+ comboBoxCanned.DisplayMember = "CannedName";
+ comboBoxCanned.ValueMember = "Id";
+ comboBoxCanned.DataSource = _cannedList;
+ comboBoxCanned.SelectedItem = null;
+ _logger.LogInformation("Загрузка консерв для поставок");
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (comboBoxShopCanneds.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxCanned.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание поставки");
+ try
+ {
+ var operationResult = _logicS.Replenish(new ReplenishBindingModel
+ {
+ ShopId = Convert.ToInt32(comboBoxShopCanneds.SelectedValue),
+ CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
+ Count = 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, "Ошибка создания поставки");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/FishFactory/FormShopReplenish.resx b/FishFactory/FormShopReplenish.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/FishFactory/FormShopReplenish.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/FishFactory/FormShops.Designer.cs b/FishFactory/FormShops.Designer.cs
new file mode 100644
index 0000000..7e771a9
--- /dev/null
+++ b/FishFactory/FormShops.Designer.cs
@@ -0,0 +1,122 @@
+namespace FishFactory.Forms
+{
+ partial class FormShops
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ dataGridView = new DataGridView();
+ buttonAdd = new Button();
+ buttonUpd = new Button();
+ buttonDel = new Button();
+ buttonRef = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(525, 673);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.AccessibleRole = AccessibleRole.None;
+ buttonAdd.Location = new Point(565, 76);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(130, 35);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpd
+ //
+ buttonUpd.AccessibleRole = AccessibleRole.None;
+ buttonUpd.Location = new Point(565, 130);
+ buttonUpd.Name = "buttonUpd";
+ buttonUpd.Size = new Size(130, 35);
+ buttonUpd.TabIndex = 2;
+ buttonUpd.Text = "Изменить";
+ buttonUpd.UseVisualStyleBackColor = true;
+ buttonUpd.Click += buttonUpd_Click;
+ //
+ // buttonDel
+ //
+ buttonDel.AccessibleRole = AccessibleRole.None;
+ buttonDel.Location = new Point(565, 186);
+ buttonDel.Name = "buttonDel";
+ buttonDel.Size = new Size(130, 35);
+ buttonDel.TabIndex = 3;
+ buttonDel.Text = "Удалить";
+ buttonDel.UseVisualStyleBackColor = true;
+ buttonDel.Click += buttonDel_Click;
+ //
+ // buttonRef
+ //
+ buttonRef.AccessibleRole = AccessibleRole.None;
+ buttonRef.Location = new Point(565, 243);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(130, 35);
+ buttonRef.TabIndex = 4;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += buttonRef_Click;
+ //
+ // FormShops
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(722, 674);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonDel);
+ Controls.Add(buttonUpd);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormShops";
+ Text = "Список магазинов";
+ Load += FormShops_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDel;
+ private Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/FormShops.cs b/FishFactory/FormShops.cs
new file mode 100644
index 0000000..46e8f15
--- /dev/null
+++ b/FishFactory/FormShops.cs
@@ -0,0 +1,105 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactory.Forms
+{
+ 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["ShopCanneds"].Visible = false;
+ dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление магазина");
+ try
+ {
+ if (!_logic.Delete(new ShopBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/FishFactory/FormShops.resx b/FishFactory/FormShops.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/FishFactory/FormShops.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/FishFactory/Program.cs b/FishFactory/Program.cs
index 08c8b2d..fabfb88 100644
--- a/FishFactory/Program.cs
+++ b/FishFactory/Program.cs
@@ -38,9 +38,11 @@ namespace FishFactory
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 FishFactory
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/FishFactoryBusinessLogic/BusinessLogic/CannedLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/CannedLogic.cs
index 4bdf067..1b6822f 100644
--- a/FishFactoryBusinessLogic/BusinessLogic/CannedLogic.cs
+++ b/FishFactoryBusinessLogic/BusinessLogic/CannedLogic.cs
@@ -4,11 +4,6 @@ using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace FishFactoryBusinessLogic.BusinessLogic
{
diff --git a/FishFactoryBusinessLogic/BusinessLogic/ShopLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/ShopLogic.cs
new file mode 100644
index 0000000..843fd8e
--- /dev/null
+++ b/FishFactoryBusinessLogic/BusinessLogic/ShopLogic.cs
@@ -0,0 +1,154 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactoryBusinessLogic.BusinessLogic
+{
+ public class ShopLogic : IShopLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IShopStorage _shopStorage;
+ private readonly ICannedStorage _cannedStorage;
+
+ public ShopLogic(ILogger logger, IShopStorage shopStorage, ICannedStorage cannedStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ _cannedStorage = cannedStorage;
+ }
+ 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;
+ }
+
+ public bool Replenish(ReplenishBindingModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentException("Количество изделий должно быть больше 0");
+ }
+ var shop = _shopStorage.GetElement(new ShopSearchModel
+ {
+ Id = model.ShopId
+ });
+ if (shop == null)
+ {
+ throw new ArgumentException("Магазина не существует");
+ }
+ if (shop.ShopCanneds.ContainsKey(model.CannedId))
+ {
+ var oldValue = shop.ShopCanneds[model.CannedId];
+ oldValue.Item2 += model.Count;
+ shop.ShopCanneds[model.CannedId] = oldValue;
+ }
+ else
+ {
+ var canned = _cannedStorage.GetElement(new CannedSearchModel
+ {
+ Id = model.CannedId
+ });
+ if (canned == null)
+ {
+ throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найденн");
+ }
+ shop.ShopCanneds.Add(model.CannedId, (canned, model.Count));
+ }
+ 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.Adress))
+ {
+ throw new ArgumentException("Нет адреса магазина", nameof(model.Adress));
+ }
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия компонента", nameof(model.ShopName));
+ }
+ _logger.LogInformation("Shop. ShopName:{ShopName}.Adress:{Adress}.OpeningDate:{OpeningDate}. Id: {Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/FishFactoryContracts/BindingModels/ReplenishBindingModel.cs b/FishFactoryContracts/BindingModels/ReplenishBindingModel.cs
new file mode 100644
index 0000000..f79e120
--- /dev/null
+++ b/FishFactoryContracts/BindingModels/ReplenishBindingModel.cs
@@ -0,0 +1,11 @@
+using FishFactoryDataModel.Models;
+
+namespace FishFactoryContracts.BindingModels
+{
+ public class ReplenishBindingModel : IReplenishModel
+ {
+ public int ShopId { get; set; }
+ public int CannedId { get; set; }
+ public int Count { get; set; }
+ }
+}
diff --git a/FishFactoryContracts/BindingModels/ShopBindingModel.cs b/FishFactoryContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..d89fa75
--- /dev/null
+++ b/FishFactoryContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,13 @@
+using FishFactoryDataModel.Models;
+
+namespace FishFactoryContracts.BindingModels
+{
+ public class ShopBindingModel : IShopModel
+ {
+ public int Id { get; set; }
+ public string ShopName { get; set; } = string.Empty;
+ public string Adress { get; set; } = string.Empty;
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+ public Dictionary ShopCanneds { get; set; } = new();
+ }
+}
diff --git a/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..8005dde
--- /dev/null
+++ b/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,16 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.ViewModels;
+
+namespace FishFactoryContracts.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 Replenish(ReplenishBindingModel model);
+ }
+}
diff --git a/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactoryContracts/SearchModels/OrderSearchModel.cs
index 895b7e1..4d57da6 100644
--- a/FishFactoryContracts/SearchModels/OrderSearchModel.cs
+++ b/FishFactoryContracts/SearchModels/OrderSearchModel.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace FishFactoryContracts.SearchModels
+namespace FishFactoryContracts.SearchModels
{
public class OrderSearchModel
{
diff --git a/FishFactoryContracts/SearchModels/ShopSearchModel.cs b/FishFactoryContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..6109423
--- /dev/null
+++ b/FishFactoryContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactoryContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..7c1dfa6
--- /dev/null
+++ b/FishFactoryContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,21 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryContracts.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/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactoryContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..49058c7
--- /dev/null
+++ b/FishFactoryContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,22 @@
+using FishFactoryDataModel.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryContracts.ViewModels
+{
+ public class ShopViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название")]
+ public string ShopName { get; set; } = string.Empty;
+ [DisplayName("Адрес")]
+ public string Adress { get; set; } = string.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; }
+ public Dictionary ShopCanneds { get; set; } = new();
+ }
+}
diff --git a/FishFactoryDataModels/FishFactoryDataModel.csproj b/FishFactoryDataModels/FishFactoryDataModel.csproj
index e30cfc1..4e12194 100644
--- a/FishFactoryDataModels/FishFactoryDataModel.csproj
+++ b/FishFactoryDataModels/FishFactoryDataModel.csproj
@@ -7,8 +7,4 @@
AnyCPU;x86
-
-
-
-
diff --git a/FishFactoryDataModels/Models/IReplenishModel.cs b/FishFactoryDataModels/Models/IReplenishModel.cs
new file mode 100644
index 0000000..ad1976d
--- /dev/null
+++ b/FishFactoryDataModels/Models/IReplenishModel.cs
@@ -0,0 +1,9 @@
+namespace FishFactoryDataModel.Models
+{
+ public interface IReplenishModel
+ {
+ int ShopId { get; }
+ int CannedId { get; }
+ int Count { get; }
+ }
+}
diff --git a/FishFactoryDataModels/Models/IShopModel.cs b/FishFactoryDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..eb7381f
--- /dev/null
+++ b/FishFactoryDataModels/Models/IShopModel.cs
@@ -0,0 +1,10 @@
+namespace FishFactoryDataModel.Models
+{
+ public interface IShopModel : IId
+ {
+ string ShopName { get; }
+ string Adress { get; }
+ DateTime OpeningDate { get; }
+ Dictionary ShopCanneds { get; }
+ }
+}
diff --git a/FishFactoryListImplement/DataListSingleton.cs b/FishFactoryListImplement/DataListSingleton.cs
index fd86094..27a6009 100644
--- a/FishFactoryListImplement/DataListSingleton.cs
+++ b/FishFactoryListImplement/DataListSingleton.cs
@@ -13,11 +13,13 @@ namespace FishFactoryListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Canneds { get; set; }
+ public List Shops { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Canneds = new List();
+ Shops = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactoryListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..50007f7
--- /dev/null
+++ b/FishFactoryListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,100 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using FishFactoryListImplement.Models;
+
+namespace FishFactoryListImplement.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/FishFactoryListImplement/Models/Shop.cs b/FishFactoryListImplement/Models/Shop.cs
new file mode 100644
index 0000000..78557b3
--- /dev/null
+++ b/FishFactoryListImplement/Models/Shop.cs
@@ -0,0 +1,54 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryDataModel.Models;
+using FishFactoryContracts.ViewModels;
+
+namespace FishFactoryListImplement.Models
+{
+ internal class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+ public string ShopName { get; private set; } = string.Empty;
+ public string Adress { get; private set; } = string.Empty;
+ public DateTime OpeningDate { get; private set; }
+ public Dictionary ShopCanneds
+ {
+ 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,
+ Adress = model.Adress,
+ OpeningDate = model.OpeningDate,
+ ShopCanneds = model.ShopCanneds
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ Adress = model.Adress;
+ OpeningDate = model.OpeningDate;
+ }
+
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Adress = Adress,
+ OpeningDate = OpeningDate,
+ ShopCanneds = ShopCanneds
+ };
+ }
+}