diff --git a/.gitignore b/.gitignore
index ca1c7a3..a299f6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+*.dll
diff --git a/FishFactory/FishFactory.sln b/FishFactory/FishFactory.sln
index 78078c9..802abb8 100644
--- a/FishFactory/FishFactory.sln
+++ b/FishFactory/FishFactory.sln
@@ -5,13 +5,15 @@ VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactory\FishFactoryView.csproj", "{63C0DA49-83D6-4B3C-A0C9-40E5B65CCFC9}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{6F3F6A6A-CE91-4829-8BF0-DE395F5664BA}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{6F3F6A6A-CE91-4829-8BF0-DE395F5664BA}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{C60A3D7A-BD1B-425D-821B-B70DFEE4DD2C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{C60A3D7A-BD1B-425D-821B-B70DFEE4DD2C}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{5869B7C9-358A-4BE3-A15F-E738215040FF}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{5869B7C9-358A-4BE3-A15F-E738215040FF}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{F857DB04-D408-4285-A81C-FA26D236014A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{F857DB04-D408-4285-A81C-FA26D236014A}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement", "FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{6C503B98-AEB3-4322-B8DF-1C0E3E294041}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
{F857DB04-D408-4285-A81C-FA26D236014A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F857DB04-D408-4285-A81C-FA26D236014A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F857DB04-D408-4285-A81C-FA26D236014A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6C503B98-AEB3-4322-B8DF-1C0E3E294041}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6C503B98-AEB3-4322-B8DF-1C0E3E294041}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6C503B98-AEB3-4322-B8DF-1C0E3E294041}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6C503B98-AEB3-4322-B8DF-1C0E3E294041}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/FishFactory/FishFactory/FishFactoryView.csproj b/FishFactory/FishFactory/FishFactoryView.csproj
index 7f57f85..81b3f1e 100644
--- a/FishFactory/FishFactory/FishFactoryView.csproj
+++ b/FishFactory/FishFactory/FishFactoryView.csproj
@@ -16,6 +16,7 @@
+
diff --git a/FishFactory/FishFactory/FormMain.Designer.cs b/FishFactory/FishFactory/FormMain.Designer.cs
index 3b7ee84..9695d2e 100644
--- a/FishFactory/FishFactory/FormMain.Designer.cs
+++ b/FishFactory/FishFactory/FormMain.Designer.cs
@@ -37,9 +37,10 @@
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.консервыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.магазиныStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.ButtonAddInShop = new System.Windows.Forms.Button();
- this.магазиныStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.ButtonSell = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -66,7 +67,7 @@
//
// ButtonTakeOrderInWork
//
- this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(786, 83);
+ this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(786, 61);
this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(186, 23);
this.ButtonTakeOrderInWork.TabIndex = 2;
@@ -76,7 +77,7 @@
//
// ButtonOrderReady
//
- this.ButtonOrderReady.Location = new System.Drawing.Point(786, 137);
+ this.ButtonOrderReady.Location = new System.Drawing.Point(786, 90);
this.ButtonOrderReady.Name = "ButtonOrderReady";
this.ButtonOrderReady.Size = new System.Drawing.Size(186, 23);
this.ButtonOrderReady.TabIndex = 3;
@@ -86,7 +87,7 @@
//
// ButtonIssuedOrder
//
- this.ButtonIssuedOrder.Location = new System.Drawing.Point(786, 194);
+ this.ButtonIssuedOrder.Location = new System.Drawing.Point(786, 119);
this.ButtonIssuedOrder.Name = "ButtonIssuedOrder";
this.ButtonIssuedOrder.Size = new System.Drawing.Size(186, 23);
this.ButtonIssuedOrder.TabIndex = 4;
@@ -96,7 +97,7 @@
//
// ButtonRef
//
- this.ButtonRef.Location = new System.Drawing.Point(786, 250);
+ this.ButtonRef.Location = new System.Drawing.Point(786, 148);
this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(186, 23);
this.ButtonRef.TabIndex = 5;
@@ -117,17 +118,24 @@
// компонентыToolStripMenuItem1
//
this.компонентыToolStripMenuItem1.Name = "компонентыToolStripMenuItem1";
- this.компонентыToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
+ this.компонентыToolStripMenuItem1.Size = new System.Drawing.Size(145, 22);
this.компонентыToolStripMenuItem1.Text = "Компоненты";
this.компонентыToolStripMenuItem1.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// консервыToolStripMenuItem
//
this.консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
- this.консервыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.консервыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.консервыToolStripMenuItem.Text = "Консервы";
this.консервыToolStripMenuItem.Click += new System.EventHandler(this.КонсервыToolStripMenuItem_Click);
//
+ // магазиныStripMenuItem
+ //
+ this.магазиныStripMenuItem.Name = "магазиныStripMenuItem";
+ this.магазиныStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.магазиныStripMenuItem.Text = "Магазины";
+ this.магазиныStripMenuItem.Click += new System.EventHandler(this.магазиныStripMenuItem_Click);
+ //
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
@@ -142,7 +150,7 @@
//
// ButtonAddInShop
//
- this.ButtonAddInShop.Location = new System.Drawing.Point(786, 289);
+ this.ButtonAddInShop.Location = new System.Drawing.Point(786, 178);
this.ButtonAddInShop.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonAddInShop.Name = "ButtonAddInShop";
this.ButtonAddInShop.Size = new System.Drawing.Size(186, 25);
@@ -151,18 +159,22 @@
this.ButtonAddInShop.UseVisualStyleBackColor = true;
this.ButtonAddInShop.Click += new System.EventHandler(this.ButtonAddInShop_Click);
//
- // магазиныStripMenuItem
+ // ButtonSell
//
- this.магазиныStripMenuItem.Name = "магазиныStripMenuItem";
- this.магазиныStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.магазиныStripMenuItem.Text = "Магазины";
- this.магазиныStripMenuItem.Click += new System.EventHandler(this.магазиныStripMenuItem_Click);
+ this.ButtonSell.Location = new System.Drawing.Point(786, 210);
+ this.ButtonSell.Name = "ButtonSell";
+ this.ButtonSell.Size = new System.Drawing.Size(186, 23);
+ this.ButtonSell.TabIndex = 8;
+ this.ButtonSell.Text = "Продать";
+ this.ButtonSell.UseVisualStyleBackColor = true;
+ this.ButtonSell.Click += new System.EventHandler(this.ButtonSell_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(978, 446);
+ this.Controls.Add(this.ButtonSell);
this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonAddInShop);
this.Controls.Add(this.ButtonIssuedOrder);
@@ -196,5 +208,6 @@
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button ButtonAddInShop;
private ToolStripMenuItem магазиныStripMenuItem;
+ private Button ButtonSell;
}
}
\ No newline at end of file
diff --git a/FishFactory/FishFactory/FormMain.cs b/FishFactory/FishFactory/FormMain.cs
index 02c1c5f..4c7f6f6 100644
--- a/FishFactory/FishFactory/FormMain.cs
+++ b/FishFactory/FishFactory/FormMain.cs
@@ -194,5 +194,15 @@ namespace FishFactoryView
form.ShowDialog();
}
}
+
+ private void ButtonSell_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSellCanneds));
+ if (service is FormSellCanneds form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
}
}
diff --git a/FishFactory/FishFactory/FormSellCanneds.Designer.cs b/FishFactory/FishFactory/FormSellCanneds.Designer.cs
new file mode 100644
index 0000000..b8d823f
--- /dev/null
+++ b/FishFactory/FishFactory/FormSellCanneds.Designer.cs
@@ -0,0 +1,126 @@
+namespace FishFactoryView
+{
+ partial class FormSellCanneds
+ {
+ ///
+ /// 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.labelCanneds = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.comboBoxCanneds = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // labelCanneds
+ //
+ this.labelCanneds.AutoSize = true;
+ this.labelCanneds.Location = new System.Drawing.Point(11, 19);
+ this.labelCanneds.Name = "labelCanneds";
+ this.labelCanneds.Size = new System.Drawing.Size(62, 15);
+ this.labelCanneds.TabIndex = 0;
+ this.labelCanneds.Text = "Консервы";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(12, 56);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(72, 15);
+ this.labelCount.TabIndex = 1;
+ this.labelCount.Text = "Количество";
+ //
+ // comboBoxCanneds
+ //
+ this.comboBoxCanneds.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxCanneds.FormattingEnabled = true;
+ this.comboBoxCanneds.Location = new System.Drawing.Point(100, 11);
+ this.comboBoxCanneds.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.comboBoxCanneds.Name = "comboBoxCanneds";
+ this.comboBoxCanneds.Size = new System.Drawing.Size(230, 23);
+ this.comboBoxCanneds.TabIndex = 3;
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(100, 48);
+ this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(230, 23);
+ this.textBoxCount.TabIndex = 4;
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(160, 78);
+ this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(82, 22);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(248, 78);
+ this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(82, 22);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // FormSellCanneds
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(335, 106);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxCanneds);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelCanneds);
+ this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.Name = "FormSellCanneds";
+ this.Text = "Продажа консерв";
+ this.Load += new System.EventHandler(this.FormSellCanneds_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelCanneds;
+ private Label labelCount;
+ private ComboBox comboBoxCanneds;
+ private TextBox textBoxCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/FishFactory/FormSellCanneds.cs b/FishFactory/FishFactory/FormSellCanneds.cs
new file mode 100644
index 0000000..0507e6d
--- /dev/null
+++ b/FishFactory/FishFactory/FormSellCanneds.cs
@@ -0,0 +1,90 @@
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace FishFactoryView
+{
+ public partial class FormSellCanneds : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ICannedLogic _logicCanned;
+ private readonly IShopLogic _logicShop;
+ public FormSellCanneds(ILogger logger, ICannedLogic logicCanned, IShopLogic logicShop)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicCanned = logicCanned;
+ _logicShop = logicShop;
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле 'Количество'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxCanneds.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Продажа консерв");
+ try
+ {
+ var operationResult = _logicShop.SellCanneds(_logicCanned.ReadElement(new CannedSearchModel()
+ {
+ Id = Convert.ToInt32(comboBoxCanneds.SelectedValue)
+ })!, 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();
+ }
+
+ private void FormSellCanneds_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка списка консерв для продажи");
+ try
+ {
+ var list = _logicCanned.ReadList(null);
+ if (list != null)
+ {
+ comboBoxCanneds.DisplayMember = "CannedName";
+ comboBoxCanneds.ValueMember = "Id";
+ comboBoxCanneds.DataSource = list;
+ comboBoxCanneds.SelectedItem = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка консерв");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/FishFactory/FishFactory/FormSellCanneds.resx b/FishFactory/FishFactory/FormSellCanneds.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/FishFactory/FishFactory/FormSellCanneds.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/FishFactory/FishFactory/FormShop.Designer.cs b/FishFactory/FishFactory/FormShop.Designer.cs
index 65f3e30..a262f00 100644
--- a/FishFactory/FishFactory/FormShop.Designer.cs
+++ b/FishFactory/FishFactory/FormShop.Designer.cs
@@ -28,13 +28,16 @@
this.labelTime = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.dataGridView = new System.Windows.Forms.DataGridView();
- this.labelShop = new System.Windows.Forms.Label();
- this.textBoxShop = new System.Windows.Forms.TextBox();
- this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCannedName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.labelShop = new System.Windows.Forms.Label();
+ this.textBoxShop = new System.Windows.Forms.TextBox();
+ this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
+ this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
+ this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// buttonSave
@@ -63,13 +66,13 @@
//
this.textBoxAddress.Location = new System.Drawing.Point(159, 27);
this.textBoxAddress.Name = "textBoxAddress";
- this.textBoxAddress.Size = new System.Drawing.Size(221, 23);
+ this.textBoxAddress.Size = new System.Drawing.Size(157, 23);
this.textBoxAddress.TabIndex = 14;
//
// labelTime
//
this.labelTime.AutoSize = true;
- this.labelTime.Location = new System.Drawing.Point(386, 9);
+ this.labelTime.Location = new System.Drawing.Point(322, 9);
this.labelTime.Name = "labelTime";
this.labelTime.Size = new System.Drawing.Size(87, 15);
this.labelTime.TabIndex = 13;
@@ -86,8 +89,8 @@
//
// dataGridView
//
- this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
@@ -100,6 +103,23 @@
this.dataGridView.Size = new System.Drawing.Size(581, 240);
this.dataGridView.TabIndex = 11;
//
+ // ColumnID
+ //
+ this.ColumnID.HeaderText = "ID";
+ this.ColumnID.Name = "ColumnID";
+ this.ColumnID.Visible = false;
+ //
+ // ColumnCannedName
+ //
+ this.ColumnCannedName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ColumnCannedName.HeaderText = "Консервы";
+ this.ColumnCannedName.Name = "ColumnCannedName";
+ //
+ // ColumnCount
+ //
+ this.ColumnCount.HeaderText = "Количество";
+ this.ColumnCount.Name = "ColumnCount";
+ //
// labelShop
//
this.labelShop.AutoSize = true;
@@ -118,33 +138,34 @@
//
// dateTimePicker
//
- this.dateTimePicker.Location = new System.Drawing.Point(386, 27);
+ this.dateTimePicker.Location = new System.Drawing.Point(322, 27);
this.dateTimePicker.Name = "dateTimePicker";
- this.dateTimePicker.Size = new System.Drawing.Size(207, 23);
+ this.dateTimePicker.Size = new System.Drawing.Size(162, 23);
this.dateTimePicker.TabIndex = 19;
//
- // ColumnID
+ // numericUpDownCount
//
- this.ColumnID.HeaderText = "ID";
- this.ColumnID.Name = "ColumnID";
- this.ColumnID.Visible = false;
+ this.numericUpDownCount.Location = new System.Drawing.Point(490, 27);
+ this.numericUpDownCount.Name = "numericUpDownCount";
+ this.numericUpDownCount.Size = new System.Drawing.Size(103, 23);
+ this.numericUpDownCount.TabIndex = 20;
//
- // ColumnSushiName
+ // label1
//
- this.ColumnCannedName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
- this.ColumnCannedName.HeaderText = "Консервы";
- this.ColumnCannedName.Name = "ColumnCannedName";
- //
- // ColumnCount
- //
- this.ColumnCount.HeaderText = "Количество";
- this.ColumnCount.Name = "ColumnCount";
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(490, 9);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(75, 15);
+ this.label1.TabIndex = 21;
+ this.label1.Text = "Вместимось";
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(605, 337);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.textBoxShop);
this.Controls.Add(this.buttonSave);
@@ -159,6 +180,7 @@
this.Load += new System.EventHandler(this.FormShop_Load);
this.Click += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -177,5 +199,7 @@
private DataGridViewTextBoxColumn ColumnID;
private DataGridViewTextBoxColumn ColumnCannedName;
private DataGridViewTextBoxColumn ColumnCount;
+ private NumericUpDown numericUpDownCount;
+ private Label label1;
}
}
\ No newline at end of file
diff --git a/FishFactory/FishFactory/FormShop.cs b/FishFactory/FishFactory/FormShop.cs
index a041d0a..4549243 100644
--- a/FishFactory/FishFactory/FormShop.cs
+++ b/FishFactory/FishFactory/FormShop.cs
@@ -47,6 +47,7 @@ namespace FishFactoryView
textBoxShop.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePicker.Text = view.DateOpening.ToString();
+ numericUpDownCount.Value = view.MaxCountCanneds;
_shopListCanneds = view.ListCanneds ?? new Dictionary();
LoadData();
}
@@ -102,6 +103,7 @@ namespace FishFactoryView
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value.Date,
ListCanneds = _shopListCanneds,
+ MaxCountCanneds = (int)numericUpDownCount.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
diff --git a/FishFactory/FishFactory/FormShop.resx b/FishFactory/FishFactory/FormShop.resx
index 1af7de1..f298a7b 100644
--- a/FishFactory/FishFactory/FormShop.resx
+++ b/FishFactory/FishFactory/FormShop.resx
@@ -1,64 +1,4 @@
-
-
-
+
diff --git a/FishFactory/FishFactory/Program.cs b/FishFactory/FishFactory/Program.cs
index 03883e9..ab2c0ce 100644
--- a/FishFactory/FishFactory/Program.cs
+++ b/FishFactory/FishFactory/Program.cs
@@ -3,8 +3,8 @@ using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.StoragesContracts;
using FishFactoryView;
using Microsoft.Extensions.DependencyInjection;
-using FishFactoryListImplement.Implements;
using System;
+using FishFactoryFileImplement.Implements;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using FishFactoryBusinessLogic;
@@ -54,6 +54,7 @@ namespace ProjectFishFactory
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/FishFactory/FishFactoryBusinessLogic/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/OrderLogic.cs
index 0c4879a..cf52fd2 100644
--- a/FishFactory/FishFactoryBusinessLogic/OrderLogic.cs
+++ b/FishFactory/FishFactoryBusinessLogic/OrderLogic.cs
@@ -17,10 +17,14 @@ namespace FishFactoryBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
- public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ private readonly IShopLogic _shopLogic;
+ private readonly ICannedStorage _cannedStorage;
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICannedStorage cannedStorage)
{
_logger = logger;
_orderStorage = orderStorage;
+ _shopLogic = shopLogic;
+ _cannedStorage = cannedStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
@@ -41,31 +45,42 @@ namespace FishFactoryBusinessLogic.BusinessLogics
}
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
- CheckModel(model, false);
- var element = _orderStorage.GetElement(new OrderSearchModel()
+ var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
+ if (viewModel == null)
{
- Id = model.Id
- });
- if (element == null)
- {
- throw new ArgumentNullException(nameof(element));
+ throw new ArgumentNullException(nameof(model));
}
- model.DateImplement = element.DateImplement;
- model.Status = element.Status;
- if (newStatus - model.Status == 1)
+ if (viewModel.Status + 1 != newStatus)
{
- model.Status = newStatus;
- if (model.Status == OrderStatus.Выдан)
- model.DateImplement = DateTime.Now;
- if (_orderStorage.Update(model) == null)
+ _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
+ return false;
+ }
+ model.Status = newStatus;
+ if (model.Status == OrderStatus.Готов)
+ {
+ model.DateImplement = DateTime.Now;
+ var canned = _cannedStorage.GetElement(new() { Id = viewModel.CannedId });
+ if (canned == null)
{
- _logger.LogWarning("Update operation failed");
- return false;
+ throw new ArgumentNullException(nameof(canned));
+ }
+ if (!_shopLogic.AddCanneds(canned, viewModel.Count))
+ {
+ throw new Exception($"AddCanneds operation failed. Shop is full.");
}
- return true;
}
- _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, newStatus);
- throw new ArgumentException($"Невозможно приствоить статус {newStatus} заказу с текущим статусом {model.Status}");
+ else
+ {
+ model.DateImplement = viewModel.DateImplement;
+ }
+ CheckModel(model, false);
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
@@ -83,8 +98,7 @@ namespace FishFactoryBusinessLogic.BusinessLogics
public List? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
- var list = model == null ? _orderStorage.GetFullList() :
- _orderStorage.GetFilteredList(model);
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
diff --git a/FishFactory/FishFactoryBusinessLogic/ShopLogic.cs b/FishFactory/FishFactoryBusinessLogic/ShopLogic.cs
index 2161288..b358551 100644
--- a/FishFactory/FishFactoryBusinessLogic/ShopLogic.cs
+++ b/FishFactory/FishFactoryBusinessLogic/ShopLogic.cs
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -39,6 +40,10 @@ namespace FishFactoryBusinessLogic
_logger.LogWarning("AddCannedInShop element not found");
return false;
}
+ if (element.MaxCountCanneds - element.ListCanneds.Select(x => x.Value.Item2).Sum() < count)
+ {
+ throw new ArgumentNullException("Магазин переполнен", nameof(count));
+ }
_logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id);
if (element.ListCanneds.TryGetValue(canned.Id, out var pair))
@@ -57,7 +62,8 @@ namespace FishFactoryBusinessLogic
Address = element.Address,
ShopName = element.ShopName,
DateOpening = element.DateOpening,
- ListCanneds = element.ListCanneds
+ ListCanneds = element.ListCanneds,
+ MaxCountCanneds = element.MaxCountCanneds,
});
return true;
}
@@ -140,6 +146,10 @@ namespace FishFactoryBusinessLogic
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
+ if (model.MaxCountCanneds < 0)
+ {
+ throw new ArgumentException("Максимальное количество консерв в магазине не может быть меньше нуля", nameof(model.MaxCountCanneds));
+ }
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
@@ -150,5 +160,57 @@ namespace FishFactoryBusinessLogic
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
+
+ public bool SellCanneds(ICannedModel model, int count)
+ {
+ return _shopStorage.SellCanneds(model, count);
+ }
+
+ public bool AddCanneds(ICannedModel model, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count));
+ }
+ var freeCount = _shopStorage.GetFullList()
+ .Select(x => x.MaxCountCanneds - x.ListCanneds
+ .Select(p => p.Value.Item2).Sum()).Sum() - count;
+ if (freeCount < 0)
+ {
+ _logger.LogInformation("AddCanned. Не удалось добавить изделия в магазины, они переполнены.");
+ return false;
+ }
+ foreach (var shop in _shopStorage.GetFullList())
+ {
+ int countFree = shop.MaxCountCanneds - shop.ListCanneds.Select(x => x.Value.Item2).Sum();
+ if (countFree < count)
+ {
+ if (!AddCannedInShop(new() { Id = shop.Id }, model, countFree))
+ {
+ _logger.LogWarning("AddCannedInShop operation failed.");
+ return false;
+ }
+ count -= countFree;
+ }
+ else
+ {
+ if (!AddCannedInShop(new() { Id = shop.Id }, model, count))
+ {
+ _logger.LogWarning("AddCannedInShop operation failed.");
+ return false;
+ }
+ count = 0;
+ }
+ if (count == 0)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}
}
diff --git a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs
index 285c4ff..b829394 100644
--- a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs
+++ b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs
@@ -22,5 +22,6 @@ namespace FishFactoryContracts.BindingModels
get;
set;
} = new();
+ public int MaxCountCanneds { get; set; }
}
}
diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs
index 5d0338d..a5a320d 100644
--- a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs
+++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -18,5 +18,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count);
+ bool AddCanneds(ICannedModel canned, int count);
+ bool SellCanneds(ICannedModel canned, int count);
}
}
diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs
index 7c1dfa6..4d39c04 100644
--- a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs
+++ b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs
@@ -1,6 +1,7 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -17,5 +18,6 @@ namespace FishFactoryContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
+ bool SellCanneds(ICannedModel model, int count);
}
}
diff --git a/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs
index 43b167e..778e3b7 100644
--- a/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs
+++ b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs
@@ -21,6 +21,9 @@ namespace FishFactoryContracts.ViewModels
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;
+ [DisplayName("Максимальное количество консерв")]
+ public int MaxCountCanneds { get; set; }
+
public Dictionary ListCanneds
{
get;
diff --git a/FishFactory/FishFactoryDataModels/IShopModel.cs b/FishFactory/FishFactoryDataModels/IShopModel.cs
index dfba83f..dcea084 100644
--- a/FishFactory/FishFactoryDataModels/IShopModel.cs
+++ b/FishFactory/FishFactoryDataModels/IShopModel.cs
@@ -13,5 +13,6 @@ namespace FishFactoryDataModels
string Address { get; }
DateTime DateOpening { get; }
Dictionary ListCanneds { get; }
+ int MaxCountCanneds { get; }
}
}
diff --git a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs
new file mode 100644
index 0000000..889077f
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs
@@ -0,0 +1,57 @@
+using FishFactoryFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace FishFactoryFileImplement
+{
+ internal class DataFileSingleton
+ {
+ private static DataFileSingleton? instance;
+ private readonly string ComponentFileName = "Component.xml";
+ private readonly string OrderFileName = "Order.xml";
+ private readonly string CannedFileName = "Canned.xml";
+ private readonly string ShopFileName = "Shop.xml";
+ public List Components { get; private set; }
+ public List Orders { get; private set; }
+ public List Canneds { get; private set; }
+ public List Shops { get; private set; }
+ public static DataFileSingleton GetInstance()
+ {
+ if (instance == null)
+ {
+ instance = new DataFileSingleton();
+ }
+ return instance;
+ }
+ public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
+ public void SaveCanneds() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement);
+ public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
+ public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
+ private DataFileSingleton()
+ {
+ Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
+ Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!;
+ Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
+ Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
+ }
+ private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
+ {
+ if (File.Exists(filename))
+ {
+ return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
+ }
+ return new List();
+ }
+ private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction)
+ {
+ if (data != null)
+ {
+ new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
+ }
+ }
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj
new file mode 100644
index 0000000..b8faca4
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/FishFactoryFileImplement.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/FishFactory/FishFactoryFileImplement/Implements/CannedStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/CannedStorage.cs
new file mode 100644
index 0000000..5a2a399
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Implements/CannedStorage.cs
@@ -0,0 +1,87 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using FishFactoryFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryFileImplement.Implements
+{
+ public class CannedStorage : ICannedStorage
+ {
+ private readonly DataFileSingleton source;
+ public CannedStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Canneds.Select(x => x.GetViewModel).ToList();
+ }
+ public List GetFilteredList(CannedSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.CannedName))
+ {
+ return new();
+ }
+ return source.Canneds
+ .Where(x => x.CannedName.Contains(model.CannedName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public CannedViewModel? GetElement(CannedSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source.Canneds
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.CannedName) && x.CannedName ==
+ model.CannedName) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+ public CannedViewModel? Insert(CannedBindingModel model)
+ {
+ model.Id = source.Canneds.Count > 0 ? source.Canneds.Max(x =>
+ x.Id) + 1 : 1;
+ var newCanned = Canned.Create(model);
+ if (newCanned == null)
+ {
+ return null;
+ }
+ source.Canneds.Add(newCanned);
+ source.SaveCanneds();
+ return newCanned.GetViewModel;
+ }
+ public CannedViewModel? Update(CannedBindingModel model)
+ {
+ var canned = source.Canneds.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (canned == null)
+ {
+ return null;
+ }
+ canned.Update(model);
+ source.SaveCanneds();
+ return canned.GetViewModel;
+ }
+ public CannedViewModel? Delete(CannedBindingModel model)
+ {
+ var element = source.Canneds.FirstOrDefault(x => x.Id ==
+ model.Id);
+ if (element != null)
+ {
+ source.Canneds.Remove(element);
+ source.SaveCanneds();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Implements/ComponentStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..1c9f758
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,85 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using FishFactoryFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryFileImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataFileSingleton source;
+ public ComponentStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Components
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return new();
+ }
+ return source.Components
+ .Where(x => x.ComponentName.Contains(model.ComponentName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source.Components
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ source.Components.Add(newComponent);
+ source.SaveComponents();
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ source.SaveComponents();
+ return component.GetViewModel;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Components.Remove(element);
+ source.SaveComponents();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..c21f097
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs
@@ -0,0 +1,103 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using FishFactoryFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryFileImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public OrderStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
+ if (element != null)
+ {
+ source.Orders.Remove(element);
+ source.SaveOrders();
+ return GetViewModel(element);
+ }
+
+ return null;
+ }
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+
+ return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source.Orders.Select(x => GetViewModel(x)).ToList();
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
+ var newOrder = Order.Create(model);
+
+ if (newOrder == null)
+ {
+ return null;
+ }
+
+ source.Orders.Add(newOrder);
+ source.SaveOrders();
+ return GetViewModel(newOrder);
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
+ if (order == null)
+ {
+ return null;
+ }
+
+ order.Update(model);
+ source.SaveOrders();
+ return GetViewModel(order);
+ }
+ private OrderViewModel GetViewModel(Order order)
+ {
+ var viewModel = order.GetViewModel;
+ foreach (var can in source.Canneds)
+ {
+ if (can.Id == order.CannedId)
+ {
+ viewModel.CannedName = can.CannedName;
+ break;
+ }
+ }
+ return viewModel;
+ }
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..e33e2c5
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Implements/ShopStorage.cs
@@ -0,0 +1,106 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.StoragesContracts;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Models;
+using FishFactoryFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FishFactoryFileImplement.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataFileSingleton source;
+ public ShopStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return source.Shops.Select(x => x.GetViewModel).ToList();
+ }
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ return new();
+ }
+ return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
+ }
+ public ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source.Shops.FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
+ model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+ public ShopViewModel? Insert(ShopBindingModel model)
+ {
+ model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
+ var newShop = Shop.Create(model);
+ if (newShop == null)
+ {
+ return null;
+ }
+ source.Shops.Add(newShop);
+ source.SaveShops();
+ return newShop.GetViewModel;
+ }
+ public ShopViewModel? Update(ShopBindingModel model)
+ {
+ var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
+ if (shop == null)
+ {
+ return null;
+ }
+ shop.Update(model);
+ source.SaveShops();
+ return shop.GetViewModel;
+ }
+ public ShopViewModel? Delete(ShopBindingModel model)
+ {
+ var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Shops.Remove(element);
+ source.SaveShops();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public bool SellCanneds(ICannedModel model, int count)
+ {
+ if (source.Shops.Select(x => x.ListCanneds.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < count)
+ {
+ return false;
+ }
+ foreach (var shop in source.Shops.Where(x => x.ListCanneds.ContainsKey(model.Id)))
+ {
+ int countInCurrentShop = shop.ListCanneds[model.Id].Item2;
+ if (countInCurrentShop <= count)
+ {
+ shop.ListCanneds.Remove(model.Id);
+ count -= countInCurrentShop;
+ }
+ else
+ {
+ shop.ListCanneds[model.Id] = (shop.ListCanneds[model.Id].Item1, countInCurrentShop - count);
+ count = 0;
+ }
+ if (count == 0)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Models/Canned.cs b/FishFactory/FishFactoryFileImplement/Models/Canned.cs
new file mode 100644
index 0000000..f73b81e
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Models/Canned.cs
@@ -0,0 +1,93 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace FishFactoryFileImplement.Models
+{
+ internal class Canned : ICannedModel
+ {
+ public string CannedName { get; private set; } = string.Empty;
+
+ public double Price { get; private set; }
+
+ public int Id { get; private set; }
+
+ public Dictionary Components { get; private set; } = new();
+ private Dictionary? _cannedComponents = null;
+ public Dictionary CannedComponents
+ {
+ get
+ {
+ if (_cannedComponents == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _cannedComponents = Components.ToDictionary(x => x.Key, y =>
+ ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
+ y.Value));
+ }
+ return _cannedComponents;
+ }
+ }
+ public static Canned? Create(CannedBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Canned()
+ {
+ Id = model.Id,
+ CannedName = model.CannedName,
+ Price = model.Price,
+ Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
+ };
+ }
+ public static Canned? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Canned()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ CannedName = element.Element("CannedName")!.Value,
+ Price = Convert.ToDouble(element.Element("Price")!.Value),
+ Components = element.Element("CannedComponents")!.Elements("CannedComponent").ToDictionary(x =>
+ Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+ public void Update(CannedBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ CannedName = model.CannedName;
+ Price = model.Price;
+ Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _cannedComponents = null;
+ }
+ public CannedViewModel GetViewModel => new()
+ {
+ Id = Id,
+ CannedName = CannedName,
+ Price = Price,
+ CannedComponents = CannedComponents
+ };
+ public XElement GetXElement => new("Canned",
+ new XAttribute("Id", Id),
+ new XElement("CannedName", CannedName),
+ new XElement("Price", Price.ToString()),
+ new XElement("CannedComponents", Components.Select(x =>
+ new XElement("CannedComponent",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))).ToArray()));
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Models/Component.cs b/FishFactory/FishFactoryFileImplement/Models/Component.cs
new file mode 100644
index 0000000..daa1eb4
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Models/Component.cs
@@ -0,0 +1,64 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace FishFactoryFileImplement.Models
+{
+ internal class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Component? Create(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public static Component? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ComponentName = element.Element("ComponentName")!.Value,
+ Cost = Convert.ToDouble(element.Element("Cost")!.Value)
+ };
+ }
+ public void Update(ComponentBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ public XElement GetXElement => new("Component",
+ new XAttribute("Id", Id),
+ new XElement("ComponentName", ComponentName),
+ new XElement("Cost", Cost.ToString()));
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs
new file mode 100644
index 0000000..94d47fb
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs
@@ -0,0 +1,93 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Enums;
+using FishFactoryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace FishFactoryFileImplement.Models
+{
+ internal class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+ public int CannedId { get; private set; }
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ CannedId = model.CannedId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+ public static Order? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ string dateImplement = element.Element("DateImplement")!.Value;
+ return new Order()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ CannedId = Convert.ToInt32(element.Element("CannedId")!.Value),
+ Count = Convert.ToInt32(element.Element("Count")!.Value),
+ Sum = Convert.ToInt32(element.Element("Sum")!.Value),
+ Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
+ DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
+ DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement)
+ };
+ }
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Status = model.Status;
+ DateImplement = model.DateImplement;
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ CannedId = CannedId,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+
+ public XElement GetXElement => new("Order",
+ new XAttribute("Id", Id),
+ new XElement("CannedId", CannedId.ToString()),
+ new XElement("Count", Count.ToString()),
+ new XElement("Sum", Sum.ToString()),
+ new XElement("Status", Status.ToString()),
+ new XElement("DateCreate", DateCreate.ToString()),
+ new XElement("DateImplement", DateImplement.ToString()));
+ }
+}
diff --git a/FishFactory/FishFactoryFileImplement/Models/Shop.cs b/FishFactory/FishFactoryFileImplement/Models/Shop.cs
new file mode 100644
index 0000000..9a90d8e
--- /dev/null
+++ b/FishFactory/FishFactoryFileImplement/Models/Shop.cs
@@ -0,0 +1,104 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels;
+using FishFactoryDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace FishFactoryFileImplement.Models
+{
+ public class Shop : IShopModel
+ {
+ public int Id { get; private set; }
+ public string ShopName { get; private set; } = string.Empty;
+ public string Address { get; private set; } = string.Empty;
+ public DateTime DateOpening { get; private set; }
+ public int MaxCountCanneds { get; private set; }
+
+ private Dictionary? _shopCanned = null;
+ public Dictionary CountCanned { get; private set; } = new();
+
+ public Dictionary ListCanneds {
+ get
+ {
+ if (_shopCanned == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _shopCanned = CountCanned.ToDictionary(x => x.Key, y => ((source.Canneds.FirstOrDefault(z => z.Id == y.Key) as ICannedModel)!, y.Value));
+ }
+ return _shopCanned;
+ }
+ }
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+ Id = model.Id,
+ ShopName = model.ShopName,
+ Address = model.Address,
+ MaxCountCanneds = model.MaxCountCanneds,
+ DateOpening = model.DateOpening,
+ CountCanned = model.ListCanneds.ToDictionary(x => x.Key, x => x.Value.Item2),
+ };
+ }
+ public static Shop? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ShopName = element.Element("ShopName")!.Value,
+ Address = element.Element("Address")!.Value,
+ DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
+ MaxCountCanneds = Convert.ToInt32(element.Element("MaxCountCanneds")!.Value),
+ CountCanned = element.Element("Canneds")!.Elements("Canned").ToDictionary(
+ x => Convert.ToInt32(x.Element("Key")?.Value),
+ x => Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ Address = model.Address;
+ DateOpening = model.DateOpening;
+ MaxCountCanneds = model.MaxCountCanneds;
+ CountCanned = model.ListCanneds.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _shopCanned = null;
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Address = Address,
+ ListCanneds = ListCanneds,
+ DateOpening = DateOpening,
+ MaxCountCanneds = MaxCountCanneds,
+ };
+ public XElement GetXElement => new("Shop",
+ new XAttribute("Id", Id),
+ new XElement("ShopName", ShopName),
+ new XElement("Address", Address),
+ new XElement("DateOpening", DateOpening),
+ new XElement("MaxCountCanneds", MaxCountCanneds),
+ new XElement("Canneds", CountCanned
+ .Select(x => new XElement("Canned",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))
+ ).ToArray()));
+ }
+}
diff --git a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs
index a7bbe9d..3a42e65 100644
--- a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs
+++ b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs
@@ -2,6 +2,7 @@
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
+using FishFactoryDataModels.Models;
using FishFactoryListImplement.Models;
using System;
using System.Collections.Generic;
@@ -103,5 +104,10 @@ namespace FishFactoryListImplement.Implements
}
return null;
}
+
+ public bool SellCanneds(ICannedModel model, int count)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/FishFactory/FishFactoryListImplement/Models/Shop.cs b/FishFactory/FishFactoryListImplement/Models/Shop.cs
index f3d75c6..0ae5500 100644
--- a/FishFactory/FishFactoryListImplement/Models/Shop.cs
+++ b/FishFactory/FishFactoryListImplement/Models/Shop.cs
@@ -55,5 +55,7 @@ namespace FishFactoryListImplement.Models
ListCanneds = ListCanneds,
DateOpening = DateOpening,
};
+
+ public int MaxCountCanneds => throw new NotImplementedException();
}
}