diff --git a/PrecastConcretePlant/PrecastConcretePlant.sln b/PrecastConcretePlant/PrecastConcretePlant.sln
index eb09aac..bed8fc1 100644
--- a/PrecastConcretePlant/PrecastConcretePlant.sln
+++ b/PrecastConcretePlant/PrecastConcretePlant.sln
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantBusines
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{471A4697-59C0-40C0-8B5E-8BEC01BD20BD}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{6251B4B7-A78D-458B-A926-FD0A8DF31076}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
{471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
index 4908d6e..9fc0826 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
@@ -38,8 +38,9 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reinforcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.buttonAddReinforcedInShop = new System.Windows.Forms.Button();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.buttonAddReinforcedInShop = new System.Windows.Forms.Button();
+ this.buttonSellReinforced = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -47,7 +48,7 @@
// buttonRef
//
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRef.Location = new System.Drawing.Point(840, 276);
+ this.buttonRef.Location = new System.Drawing.Point(786, 276);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(147, 32);
this.buttonRef.TabIndex = 12;
@@ -58,7 +59,7 @@
// buttonFinish
//
this.buttonFinish.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonFinish.Location = new System.Drawing.Point(840, 217);
+ this.buttonFinish.Location = new System.Drawing.Point(786, 217);
this.buttonFinish.Name = "buttonFinish";
this.buttonFinish.Size = new System.Drawing.Size(147, 32);
this.buttonFinish.TabIndex = 11;
@@ -69,7 +70,7 @@
// buttonReady
//
this.buttonReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonReady.Location = new System.Drawing.Point(840, 159);
+ this.buttonReady.Location = new System.Drawing.Point(786, 159);
this.buttonReady.Name = "buttonReady";
this.buttonReady.Size = new System.Drawing.Size(147, 32);
this.buttonReady.TabIndex = 10;
@@ -80,7 +81,7 @@
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonTakeOrderInWork.Location = new System.Drawing.Point(840, 100);
+ this.buttonTakeOrderInWork.Location = new System.Drawing.Point(786, 100);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 32);
this.buttonTakeOrderInWork.TabIndex = 9;
@@ -91,7 +92,7 @@
// buttonCreateOrder
//
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonCreateOrder.Location = new System.Drawing.Point(840, 41);
+ this.buttonCreateOrder.Location = new System.Drawing.Point(786, 41);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(147, 32);
this.buttonCreateOrder.TabIndex = 8;
@@ -108,7 +109,7 @@
this.dataGridView.Location = new System.Drawing.Point(12, 29);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
- this.dataGridView.Size = new System.Drawing.Size(805, 348);
+ this.dataGridView.Size = new System.Drawing.Size(751, 396);
this.dataGridView.TabIndex = 7;
//
// menuStrip1
@@ -117,7 +118,7 @@
this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
- this.menuStrip1.Size = new System.Drawing.Size(999, 24);
+ this.menuStrip1.Size = new System.Drawing.Size(945, 24);
this.menuStrip1.TabIndex = 13;
this.menuStrip1.Text = "menuStrip1";
//
@@ -145,10 +146,17 @@
this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
+ // магазиныToolStripMenuItem
+ //
+ this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.магазиныToolStripMenuItem.Text = "Магазины";
+ this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
+ //
// buttonAddReinforcedInShop
//
- this.buttonAddReinforcedInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(840, 337);
+ this.buttonAddReinforcedInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(786, 337);
this.buttonAddReinforcedInShop.Name = "buttonAddReinforcedInShop";
this.buttonAddReinforcedInShop.Size = new System.Drawing.Size(147, 31);
this.buttonAddReinforcedInShop.TabIndex = 14;
@@ -156,18 +164,23 @@
this.buttonAddReinforcedInShop.UseVisualStyleBackColor = true;
this.buttonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click);
//
- // магазиныToolStripMenuItem
+ // buttonSellReinforced
//
- this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
- this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.магазиныToolStripMenuItem.Text = "Магазины";
- this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
+ this.buttonSellReinforced.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSellReinforced.Location = new System.Drawing.Point(786, 395);
+ this.buttonSellReinforced.Name = "buttonSellReinforced";
+ this.buttonSellReinforced.Size = new System.Drawing.Size(147, 31);
+ this.buttonSellReinforced.TabIndex = 15;
+ this.buttonSellReinforced.Text = "Продать изделие";
+ this.buttonSellReinforced.UseVisualStyleBackColor = true;
+ this.buttonSellReinforced.Click += new System.EventHandler(this.ButtonSellReinforced_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(999, 389);
+ this.ClientSize = new System.Drawing.Size(945, 437);
+ this.Controls.Add(this.buttonSellReinforced);
this.Controls.Add(this.buttonAddReinforcedInShop);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.buttonRef);
@@ -178,6 +191,7 @@
this.Controls.Add(this.dataGridView);
this.Name = "FormMain";
this.Text = "Заказы";
+ this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
@@ -200,5 +214,6 @@
private ToolStripMenuItem componentToolStripMenuItem;
private Button buttonAddReinforcedInShop;
private ToolStripMenuItem магазиныToolStripMenuItem;
+ private Button buttonSellReinforced;
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
index 3c41bda..9601a51 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
@@ -170,5 +170,14 @@ namespace PrecastConcretePlantView
form.ShowDialog();
}
}
+
+ private void ButtonSellReinforced_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced));
+ if (service is FormSellReinforced form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs
new file mode 100644
index 0000000..28e6a01
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs
@@ -0,0 +1,133 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormSellReinforced
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSell = new System.Windows.Forms.Button();
+ this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ this.comboBoxReinforced = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(179, 79);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(123, 23);
+ this.buttonCancel.TabIndex = 11;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSell
+ //
+ this.buttonSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSell.Location = new System.Drawing.Point(32, 79);
+ this.buttonSell.Name = "buttonSell";
+ this.buttonSell.Size = new System.Drawing.Size(123, 23);
+ this.buttonSell.TabIndex = 10;
+ this.buttonSell.Text = "Продать";
+ this.buttonSell.UseVisualStyleBackColor = true;
+ this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
+ //
+ // numericUpDownCount
+ //
+ this.numericUpDownCount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.numericUpDownCount.Location = new System.Drawing.Point(142, 40);
+ this.numericUpDownCount.Maximum = new decimal(new int[] {
+ 10000000,
+ 0,
+ 0,
+ 0});
+ this.numericUpDownCount.Name = "numericUpDownCount";
+ this.numericUpDownCount.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.numericUpDownCount.Size = new System.Drawing.Size(160, 23);
+ this.numericUpDownCount.TabIndex = 9;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(60, 40);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(75, 15);
+ this.label2.TabIndex = 8;
+ this.label2.Text = "Количество:";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 9);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(123, 15);
+ this.label1.TabIndex = 7;
+ this.label1.Text = "Изделие на продажу:";
+ //
+ // comboBoxReinforced
+ //
+ this.comboBoxReinforced.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.comboBoxReinforced.FormattingEnabled = true;
+ this.comboBoxReinforced.Location = new System.Drawing.Point(141, 6);
+ this.comboBoxReinforced.Name = "comboBoxReinforced";
+ this.comboBoxReinforced.Size = new System.Drawing.Size(161, 23);
+ this.comboBoxReinforced.TabIndex = 6;
+ //
+ // FormSellReinforced
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(314, 114);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSell);
+ this.Controls.Add(this.numericUpDownCount);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.comboBoxReinforced);
+ this.Name = "FormSellReinforced";
+ this.Text = "Продать изделие";
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSell;
+ private NumericUpDown numericUpDownCount;
+ private Label label2;
+ private Label label1;
+ private ComboBox comboBoxReinforced;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs
new file mode 100644
index 0000000..46626c9
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs
@@ -0,0 +1,56 @@
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormSellReinforced : Form
+ {
+ private readonly IShopLogic _shopLogic;
+ private readonly IReinforcedLogic _reinforcedLogic;
+ public FormSellReinforced(IReinforcedLogic logic, IShopLogic shopLogic)
+ {
+ InitializeComponent();
+ _reinforcedLogic = logic;
+ _shopLogic = shopLogic;
+ var list = logic.ReadList(null);
+ if (list != null)
+ {
+ comboBoxReinforced.DisplayMember = "ReinforcedName";
+ comboBoxReinforced.ValueMember = "Id";
+ comboBoxReinforced.DataSource = list;
+ comboBoxReinforced.SelectedItem = null;
+ }
+ }
+
+ private void ButtonSell_Click(object sender, EventArgs e)
+ {
+ if (comboBoxReinforced.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (numericUpDownCount.Value <= 0)
+ {
+ MessageBox.Show("Количество должно быть больше нуля", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ var count = (int)numericUpDownCount.Value;
+ var reinforced = _reinforcedLogic.ReadElement(new() { Id = (int)comboBoxReinforced.SelectedValue });
+ if (reinforced == null || !_shopLogic.SellReinforceds(reinforced, count))
+ {
+ MessageBox.Show("Не удалось продать изделия. Информацию смотрите в логах", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.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/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs
index 035854b..5dec33e 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs
@@ -40,7 +40,10 @@
this.comboBoxShop = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.dateTimePickerOpening = new System.Windows.Forms.DateTimePicker();
+ this.label4 = new System.Windows.Forms.Label();
+ this.numericUpDownMaxReinforced = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).BeginInit();
this.SuspendLayout();
//
// buttonSave
@@ -145,11 +148,29 @@
this.dateTimePickerOpening.Size = new System.Drawing.Size(200, 23);
this.dateTimePickerOpening.TabIndex = 18;
//
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(606, 10);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(115, 15);
+ this.label4.TabIndex = 19;
+ this.label4.Text = "Максимум изделий";
+ //
+ // numericUpDownMaxReinforced
+ //
+ this.numericUpDownMaxReinforced.Location = new System.Drawing.Point(606, 26);
+ this.numericUpDownMaxReinforced.Name = "numericUpDownMaxReinforced";
+ this.numericUpDownMaxReinforced.Size = new System.Drawing.Size(120, 23);
+ this.numericUpDownMaxReinforced.TabIndex = 20;
+ //
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(737, 319);
+ this.Controls.Add(this.numericUpDownMaxReinforced);
+ this.Controls.Add(this.label4);
this.Controls.Add(this.dateTimePickerOpening);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
@@ -163,6 +184,7 @@
this.Text = "Изделия магазина";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -182,5 +204,7 @@
private TextBox comboBoxShop;
private Label label1;
private DateTimePicker dateTimePickerOpening;
+ private Label label4;
+ private NumericUpDown numericUpDownMaxReinforced;
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs
index 6daff3e..ed629e3 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs
@@ -48,6 +48,7 @@ namespace PrecastConcretePlantView
var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.Text));
if (model != null)
{
+ numericUpDownMaxReinforced.Value = model.MaxCountReinforceds;
comboBoxShop.Text = model.Name;
textBoxAddress.Text = model.Address;
dateTimePickerOpening.Value = model.DateOpening;
@@ -91,6 +92,7 @@ namespace PrecastConcretePlantView
{
ShopBindingModel model = new()
{
+ MaxCountReinforceds = (int)numericUpDownMaxReinforced.Value,
Name = comboBoxShop.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePickerOpening.Value,
diff --git a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj
index 9ebf5ea..34aaa18 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj
+++ b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj
@@ -16,6 +16,7 @@
+
diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
index 42c5aef..d6086ea 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
@@ -1,12 +1,12 @@
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using NLog.Extensions.Logging;
+using PrecastConcretePlantFileImplement.Implements;
using PrecastConcretePlantBusinessLogic.BusinessLogic;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.StoragesContract;
-using PrecastConcretePlantListImplement.Implements;
-using PrecastConcretePlantListImplement;
+using PrecastConcretePlantFileImplement;
using PrecastConcretePlantView;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
using PrecastConcretePlantBusinessLogic;
namespace PrecastConcretePlant
@@ -58,6 +58,7 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs
index b40d4ad..25156cf 100644
--- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs
@@ -12,10 +12,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
- public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ private readonly IReinforcedStorage _reinforcedStorage;
+ private readonly IShopLogic _shopLogic;
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
+ _reinforcedStorage = reinforcedStorage;
+ _shopLogic = shopLogic;
}
public bool CreateOrder(OrderBindingModel model)
@@ -94,6 +98,15 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
$"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}",
nameof(vmodel));
}
+ if (orderStatus == OrderStatus.Готов)
+ {
+ var vreinforced = _reinforcedStorage.GetElement(new() { Id = vmodel.ReinforcedId });
+
+ if (vreinforced == null || !_shopLogic.AddReinforcedsInShops(vreinforced, vmodel.Count))
+ {
+ throw new Exception($"Не удалось заполнить магазины изделием '{vreinforced?.ReinforcedName ?? string.Empty}' из заказа {vmodel.Id}");
+ }
+ }
model.Status = orderStatus;
model.ReinforcedId = vmodel.ReinforcedId;
model.Sum = vmodel.Sum;
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs
index 6929890..ed8fabd 100644
--- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs
@@ -100,6 +100,12 @@ namespace PrecastConcretePlantBusinessLogic
throw new ArgumentNullException("Нет названия магазина",
nameof(model.Name));
}
+ if (model.MaxCountReinforceds < 0)
+ {
+ throw new ArgumentException(
+ "Максимальное количество изделий в магазине не должно быть отрицательным",
+ nameof(model.MaxCountReinforceds));
+ }
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
model.Name, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
@@ -122,9 +128,14 @@ namespace PrecastConcretePlantBusinessLogic
{
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
}
+
_logger.LogInformation("AddreinforcedInShop. ShopName:{ShopName}.Id:{ Id}",
model.Name, model.Id);
var element = _shopStorage.GetElement(model);
+ if (element.MaxCountReinforceds < count + element.Reinforceds.Sum(x => x.Value.Item2))
+ {
+ throw new ArgumentException("Количество добавляемого изделия не должно быть больше максимального кол-ва изделий в магазине", nameof(count));
+ }
if (element == null)
{
_logger.LogWarning("AddreinforcedInShop element not found");
@@ -144,10 +155,59 @@ namespace PrecastConcretePlantBusinessLogic
Id = element.Id,
Address = element.Address,
Name = element.Name,
+ MaxCountReinforceds = element.MaxCountReinforceds,
DateOpening = element.DateOpening,
Reinforceds = element.Reinforceds
});
return true;
}
+
+ public int GetFreePlacesWithReinforcedsInShops(int countReinforceds)
+ {
+ return _shopStorage.GetFullList()
+ .Select(x => x.MaxCountReinforceds - x.Reinforceds
+ .Select(p => p.Value.Item2).Sum())
+ .Sum() - countReinforceds;
+ }
+
+ public bool AddReinforcedsInShops(IReinforcedModel reinforced, int count)
+ {
+ if (count <= 0)
+ {
+ _logger.LogWarning("AddReinforcedsInShops. Количество добавляемых изделий должно быть больше 0. Количество - {count}", count);
+ return false;
+ }
+ var freePlaces = GetFreePlacesWithReinforcedsInShops(count);
+ if (freePlaces < 0)
+ {
+ _logger.LogInformation("AddReinforcedsInShops. Не удалось добавить изделия в магазины, поскольку они переполнены." +
+ "Освободите магазины на {places} изделий", -freePlaces);
+ return false;
+ }
+ foreach (var shop in _shopStorage.GetFullList())
+ {
+ var cnt = Math.Min(count, shop.MaxCountReinforceds - shop.Reinforceds.Select(x => x.Value.Item2).Sum());
+ if (cnt <= 0)
+ {
+ continue;
+ }
+ if (!AddReinforced(new() { Id = shop.Id }, reinforced, cnt))
+ {
+ _logger.LogWarning("При добавления изделий во все магазины произошла ошибка");
+ return false;
+ }
+ count -= cnt;
+ if (count == 0)
+ {
+ return true;
+ }
+ }
+ return true;
+ }
+
+ public bool SellReinforceds(IReinforcedModel reinforced, int needCount)
+ {
+ return _shopStorage.SellReinforceds(reinforced, needCount);
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs
index 3f9f982..7ddddc4 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs
@@ -9,6 +9,8 @@ namespace PrecastConcretePlantContracts.BindingModels
public string Address { get; set; } = string.Empty;
+ public int MaxCountReinforceds { get; set; }
+
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary Reinforceds
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs
index 6460d8b..0094dce 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -13,5 +13,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count);
+ bool AddReinforcedsInShops(IReinforcedModel reinforced, int count);
+ public bool SellReinforceds(IReinforcedModel reinforced, int needCount);
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs
index 060b96a..43e86b2 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs
@@ -13,5 +13,6 @@ namespace PrecastConcretePlantContracts.StoragesContract
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
+ public bool SellReinforceds(IReinforcedModel reinforced, int needCount);
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs
index 49cc4c2..3ecfc28 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs
@@ -13,6 +13,9 @@ namespace PrecastConcretePlantContracts.ViewModels
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
+ [DisplayName("Максимальное количество изделий в магазине")]
+ public int MaxCountReinforceds { get; set; }
+
[DisplayName("Время открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;
diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs
index 7522011..5e252ae 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs
@@ -6,6 +6,7 @@ namespace PrecastConcretePlantDataModels
{
string Name { get; }
string Address { get; }
+ int MaxCountReinforceds { get; }
DateTime DateOpening { get; }
Dictionary Reinforceds { get; }
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs
new file mode 100644
index 0000000..00c37c8
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs
@@ -0,0 +1,62 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+using System.Xml.Linq;
+
+
+
+namespace PrecastConcretePlantFileImplement.Models
+{
+ public 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/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs
new file mode 100644
index 0000000..37c3ae8
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs
@@ -0,0 +1,80 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantFileImplement.Models;
+
+namespace PrecastConcretePlantFileImplement.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
new file mode 100644
index 0000000..2a44e84
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
@@ -0,0 +1,54 @@
+using PrecastConcretePlantFileImplement.Models;
+using System.Xml.Linq;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class DataFileSingleton
+ {
+ private static DataFileSingleton? instance;
+ private readonly string ComponentFileName = "Component.xml";
+ private readonly string OrderFileName = "Order.xml";
+ private readonly string ReinforcedFileName = "Reinforced.xml";
+ private readonly string ShopFileName = "Shop.xml";
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Reinforceds { get; 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 SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", 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)!)!;
+ Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
new file mode 100644
index 0000000..a6fede1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
@@ -0,0 +1,91 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Enums;
+using PrecastConcretePlantDataModels.Models;
+using System.Xml.Linq;
+
+
+namespace PrecastConcretePlantFileImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+
+ public int ReinforcedId { get; private set; }
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; }
+
+ public DateTime DateCreate { get; private set; }
+
+ public DateTime? DateImplement { get; private set; }
+
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ ReinforcedId = model.ReinforcedId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement,
+ Id = model.Id,
+ };
+ }
+ public static Order? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ var dateImplement = element.Element("DateImplement")!.Value;
+ return new()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ Sum = Convert.ToDouble(element.Element("Sum")!.Value),
+ Count = Convert.ToInt32(element.Element("Count")!.Value),
+ Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
+ ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.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()
+ {
+ ReinforcedId = ReinforcedId,
+ ReinforcedName = DataFileSingleton.GetInstance().Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement,
+ Id = Id,
+ };
+ public XElement GetXElement => new("Order",
+ new XAttribute("Id", Id),
+ new XElement("ReinforcedId", ReinforcedId),
+ new XElement("Count", Count),
+ new XElement("Sum", Sum.ToString()),
+ new XElement("Status", (int)Status),
+ new XElement("DateCreate", DateCreate),
+ new XElement("DateImplement", DateImplement)
+);
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs
new file mode 100644
index 0000000..c9c760f
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs
@@ -0,0 +1,76 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantFileImplement.Models;
+
+namespace PrecastConcretePlantFileImplement
+{
+ 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 element.GetViewModel;
+ }
+ return null;
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = GetElement(model);
+ return result != null ? new() { result } : new();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Orders
+ .Select(x => x.GetViewModel)
+ .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 newOrder.GetViewModel;
+ }
+
+ 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 order.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj
new file mode 100644
index 0000000..3b2c1a9
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs
new file mode 100644
index 0000000..a710fb4
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs
@@ -0,0 +1,86 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+using System.Xml.Linq;
+
+namespace PrecastConcretePlantFileImplement.Models
+{
+ public class Reinforced : IReinforcedModel
+ {
+ public int Id { get; private set; }
+ public string ReinforcedName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary Components { get; private set; } = new();
+ private Dictionary? _ReinforcedComponents = null;
+ public Dictionary ReinforcedComponents
+ {
+ get
+ {
+ if (_ReinforcedComponents == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _ReinforcedComponents = Components.ToDictionary(x => x.Key, y =>
+ ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
+ y.Value));
+ }
+ return _ReinforcedComponents;
+ }
+ }
+ public static Reinforced? Create(ReinforcedBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Reinforced()
+ {
+ Id = model.Id,
+ ReinforcedName = model.ReinforcedName,
+ Price = model.Price,
+ Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
+ };
+ }
+ public static Reinforced? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Reinforced()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ReinforcedName = element.Element("ReinforcedName")!.Value,
+ Price = Convert.ToDouble(element.Element("Price")!.Value),
+ Components = element.Element("ReinforcedComponents")!.Elements("ReinforcedComponent").ToDictionary(x =>
+ Convert.ToInt32(x.Element("Key")?.Value), x =>
+ Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+ public void Update(ReinforcedBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ReinforcedName = model.ReinforcedName;
+ Price = model.Price;
+ Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _ReinforcedComponents = null;
+ }
+ public ReinforcedViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ReinforcedName = ReinforcedName,
+ Price = Price,
+ ReinforcedComponents = ReinforcedComponents
+ };
+ public XElement GetXElement => new("Reinforced",
+ new XAttribute("Id", Id),
+ new XElement("ReinforcedName", ReinforcedName),
+ new XElement("Price", Price.ToString()),
+ new XElement("ReinforcedComponents", Components.Select(x =>
+ new XElement("ReinforcedComponent",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))).ToArray()));
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs
new file mode 100644
index 0000000..c31a0b1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs
@@ -0,0 +1,85 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantFileImplement.Models;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class ReinforcedStorage : IReinforcedStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ReinforcedStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+
+ public ReinforcedViewModel? Delete(ReinforcedBindingModel model)
+ {
+ var element = _source.Reinforceds.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ _source.Reinforceds.Remove(element);
+ _source.SaveReinforceds();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public ReinforcedViewModel? GetElement(ReinforcedSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return _source.Reinforceds.FirstOrDefault
+ (x => (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) ||
+ (model.Id.HasValue && x.Id == model.Id)
+ )?.GetViewModel;
+ }
+
+ public List GetFilteredList(ReinforcedSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ReinforcedName))
+ {
+ return new();
+ }
+ return _source.Reinforceds
+ .Select(x => x.GetViewModel)
+ .Where(x => x.ReinforcedName.Contains(model.ReinforcedName))
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Reinforceds
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ReinforcedViewModel? Insert(ReinforcedBindingModel model)
+ {
+ model.Id = _source.Reinforceds.Count > 0 ? _source.Reinforceds.Max(x => x.Id) + 1 : 1;
+ var newReinforced = Reinforced.Create(model);
+ if (newReinforced == null)
+ {
+ return null;
+ }
+ _source.Reinforceds.Add(newReinforced);
+ _source.SaveReinforceds();
+ return newReinforced.GetViewModel;
+ }
+
+ public ReinforcedViewModel? Update(ReinforcedBindingModel model)
+ {
+ var reinforced = _source.Reinforceds.FirstOrDefault(x => x.Id == model.Id);
+ if (reinforced == null)
+ {
+ return null;
+ }
+ reinforced.Update(model);
+ _source.SaveReinforceds();
+ return reinforced.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs
new file mode 100644
index 0000000..1c105ed
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs
@@ -0,0 +1,110 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using PrecastConcretePlantDataModels.Models;
+using System.Xml.Linq;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class Shop : IShopModel
+ {
+ public string Name { get; private set; } = string.Empty;
+
+ public string Address { get; private set; } = string.Empty;
+
+ public int MaxCountReinforceds { get; private set; }
+
+ public DateTime DateOpening { get; private set; }
+
+ public Dictionary CountReinforceds { get; private set; } = new();
+
+ private Dictionary? _cachedReinforceds = null;
+ public Dictionary Reinforceds
+ {
+ get
+ {
+ if (_cachedReinforceds == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _cachedReinforceds = CountReinforceds
+ .ToDictionary(x => x.Key, x => (source.Reinforceds
+ .FirstOrDefault(y => y.Id == x.Key)! as IReinforcedModel, x.Value));
+ }
+ return _cachedReinforceds;
+ }
+ }
+
+ public int Id { get; private set; }
+
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+ Id = model.Id,
+ Name = model.Name,
+ Address = model.Address,
+ DateOpening = model.DateOpening,
+ MaxCountReinforceds = model.MaxCountReinforceds,
+ CountReinforceds = new()
+ };
+ }
+ public static Shop? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ Name = element.Element("Name")!.Value,
+ Address = element.Element("Address")!.Value,
+ DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
+ MaxCountReinforceds = Convert.ToInt32(element.Element("MaxCountReinforceds")!.Value),
+ CountReinforceds = element.Element("CountReinforceds")!.Elements("CountReinforced")
+ .ToDictionary(
+ x => Convert.ToInt32(x.Element("Key")?.Value),
+ x => Convert.ToInt32(x.Element("Value")?.Value)
+ )
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Name = model.Name;
+ Address = model.Address;
+ DateOpening = model.DateOpening;
+ MaxCountReinforceds = model.MaxCountReinforceds;
+ CountReinforceds = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _cachedReinforceds = null;
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ Address = Address,
+ Reinforceds = Reinforceds,
+ DateOpening = DateOpening,
+ MaxCountReinforceds = MaxCountReinforceds,
+ };
+ public XElement GetXElement => new("Shop",
+ new XAttribute("Id", Id),
+ new XElement("Name", Name),
+ new XElement("Address", Address),
+ new XElement("DateOpening", DateOpening),
+ new XElement("MaxCountReinforceds", MaxCountReinforceds),
+ new XElement("CountReinforceds", CountReinforceds
+ .Select(x => new XElement("CountReinforced",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))
+ ))
+ );
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs
new file mode 100644
index 0000000..92d2ffc
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs
@@ -0,0 +1,107 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ShopStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+
+ 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 ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ return _source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
+ }
+
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ return new();
+ }
+ return _source.Shops
+ .Select(x => x.GetViewModel)
+ .Where(x => x.Name.Contains(model.Name ?? string.Empty))
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Shops
+ .Select(shop => shop.GetViewModel)
+ .ToList();
+ }
+
+ 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 bool SellReinforceds(IReinforcedModel reinforced, int needCount)
+ {
+ var resultCount = _source.Shops
+ .Select(shop => shop.Reinforceds
+ .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2)
+ .Sum();
+ if (resultCount < needCount)
+ {
+ return false;
+ }
+ foreach (var shop in _source.Shops.Where(shop => shop.Reinforceds.ContainsKey(reinforced.Id)))
+ {
+ var tuple = shop.Reinforceds[reinforced.Id];
+ var diff = Math.Min(tuple.Item2, needCount);
+ shop.Reinforceds[reinforced.Id] = (tuple.Item1, tuple.Item2 - diff);
+
+ needCount -= diff;
+ if (needCount <= 0)
+ {
+ return true;
+ }
+ }
+ return true;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs
index 1d07d25..fcbaa3c 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs
@@ -11,6 +11,8 @@ namespace PrecastConcretePlantListImplement
public string Address { get; private set; } = string.Empty;
+ public int MaxCountReinforceds { get; private set; }
+
public DateTime DateOpening { get; private set; }
public Dictionary Reinforceds
@@ -33,6 +35,7 @@ namespace PrecastConcretePlantListImplement
Name = model.Name,
Address = model.Address,
DateOpening = model.DateOpening,
+ MaxCountReinforceds = model.MaxCountReinforceds,
Reinforceds = new()
};
}
@@ -45,6 +48,7 @@ namespace PrecastConcretePlantListImplement
Name = model.Name;
Address = model.Address;
DateOpening = model.DateOpening;
+ MaxCountReinforceds = model.MaxCountReinforceds;
Reinforceds = model.Reinforceds;
}
public ShopViewModel GetViewModel => new()
@@ -54,6 +58,7 @@ namespace PrecastConcretePlantListImplement
Address = Address,
Reinforceds = Reinforceds,
DateOpening = DateOpening,
+ MaxCountReinforceds = MaxCountReinforceds,
};
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs
index fab9bd4..de78c61 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs
@@ -2,6 +2,7 @@
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContract;
using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Models;
namespace PrecastConcretePlantListImplement
{
@@ -103,5 +104,10 @@ namespace PrecastConcretePlantListImplement
}
return null;
}
+
+ public bool SellReinforceds(IReinforcedModel reinforced, int needCount)
+ {
+ throw new NotImplementedException();
+ }
}
}