Шаг 1. Сложная лабораторная работа 2
This commit is contained in:
parent
51991ea387
commit
98f5f1b41d
@ -32,6 +32,7 @@
|
||||
this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.CreateOrderButton = new System.Windows.Forms.Button();
|
||||
this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
|
||||
@ -39,7 +40,7 @@
|
||||
this.IssuedOrderButton = new System.Windows.Forms.Button();
|
||||
this.UpdateListButton = new System.Windows.Forms.Button();
|
||||
this.ButtonAddReinforcedInShop = new System.Windows.Forms.Button();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SellPackageButton = new System.Windows.Forms.Button();
|
||||
this.MenuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -67,17 +68,24 @@
|
||||
// Изделия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);
|
||||
//
|
||||
// Компоненты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);
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
@ -147,18 +155,22 @@
|
||||
this.ButtonAddReinforcedInShop.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click);
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
// SellPackageButton
|
||||
//
|
||||
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
this.SellPackageButton.Location = new System.Drawing.Point(905, 276);
|
||||
this.SellPackageButton.Name = "SellPackageButton";
|
||||
this.SellPackageButton.Size = new System.Drawing.Size(125, 29);
|
||||
this.SellPackageButton.TabIndex = 8;
|
||||
this.SellPackageButton.Text = "Продать изделие";
|
||||
this.SellPackageButton.UseVisualStyleBackColor = true;
|
||||
this.SellPackageButton.Click += new System.EventHandler(this.SellPackageButton_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1042, 450);
|
||||
this.Controls.Add(this.SellPackageButton);
|
||||
this.Controls.Add(this.ButtonAddReinforcedInShop);
|
||||
this.Controls.Add(this.UpdateListButton);
|
||||
this.Controls.Add(this.IssuedOrderButton);
|
||||
@ -192,5 +204,6 @@
|
||||
private Button UpdateListButton;
|
||||
private Button ButtonAddReinforcedInShop;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button SellPackageButton;
|
||||
}
|
||||
}
|
@ -216,5 +216,15 @@ namespace PrecastConcretePlantView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void SellPackageButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced));
|
||||
|
||||
if (service is FormSellReinforced form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
119
PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs
generated
Normal file
119
PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace PrecastConcretePlantView
|
||||
{
|
||||
partial class FormSellReinforced
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.ReinforcedLabel = new System.Windows.Forms.Label();
|
||||
this.QuantityLabel = new System.Windows.Forms.Label();
|
||||
this.ReindorcedСomboBox = new System.Windows.Forms.ComboBox();
|
||||
this.QuantityTextBox = new System.Windows.Forms.TextBox();
|
||||
this.SaveButton = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ReinforcedLabel
|
||||
//
|
||||
this.ReinforcedLabel.AutoSize = true;
|
||||
this.ReinforcedLabel.Location = new System.Drawing.Point(12, 18);
|
||||
this.ReinforcedLabel.Name = "ReinforcedLabel";
|
||||
this.ReinforcedLabel.Size = new System.Drawing.Size(56, 15);
|
||||
this.ReinforcedLabel.TabIndex = 0;
|
||||
this.ReinforcedLabel.Text = "Изделие:";
|
||||
//
|
||||
// QuantityLabel
|
||||
//
|
||||
this.QuantityLabel.AutoSize = true;
|
||||
this.QuantityLabel.Location = new System.Drawing.Point(12, 51);
|
||||
this.QuantityLabel.Name = "QuantityLabel";
|
||||
this.QuantityLabel.Size = new System.Drawing.Size(75, 15);
|
||||
this.QuantityLabel.TabIndex = 1;
|
||||
this.QuantityLabel.Text = "Количество:";
|
||||
//
|
||||
// ReindorcedСomboBox
|
||||
//
|
||||
this.ReindorcedСomboBox.FormattingEnabled = true;
|
||||
this.ReindorcedСomboBox.Location = new System.Drawing.Point(88, 15);
|
||||
this.ReindorcedСomboBox.Name = "ReindorcedСomboBox";
|
||||
this.ReindorcedСomboBox.Size = new System.Drawing.Size(184, 23);
|
||||
this.ReindorcedСomboBox.TabIndex = 2;
|
||||
//
|
||||
// QuantityTextBox
|
||||
//
|
||||
this.QuantityTextBox.Location = new System.Drawing.Point(88, 48);
|
||||
this.QuantityTextBox.Name = "QuantityTextBox";
|
||||
this.QuantityTextBox.Size = new System.Drawing.Size(184, 23);
|
||||
this.QuantityTextBox.TabIndex = 3;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
this.SaveButton.Location = new System.Drawing.Point(72, 100);
|
||||
this.SaveButton.Name = "SaveButton";
|
||||
this.SaveButton.Size = new System.Drawing.Size(97, 29);
|
||||
this.SaveButton.TabIndex = 4;
|
||||
this.SaveButton.Text = "Сохранить";
|
||||
this.SaveButton.UseVisualStyleBackColor = true;
|
||||
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(175, 100);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(97, 29);
|
||||
this.ButtonCancel.TabIndex = 5;
|
||||
this.ButtonCancel.Text = "Отмена";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormSellReinforced
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(284, 141);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.SaveButton);
|
||||
this.Controls.Add(this.QuantityTextBox);
|
||||
this.Controls.Add(this.ReindorcedСomboBox);
|
||||
this.Controls.Add(this.QuantityLabel);
|
||||
this.Controls.Add(this.ReinforcedLabel);
|
||||
this.Name = "FormSellReinforced";
|
||||
this.Text = "Продать Изделие";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label ReinforcedLabel;
|
||||
private Label QuantityLabel;
|
||||
private ComboBox ReindorcedСomboBox;
|
||||
private TextBox QuantityTextBox;
|
||||
private Button SaveButton;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
|
||||
namespace PrecastConcretePlantView
|
||||
{
|
||||
public partial class FormSellReinforced : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IReinforcedLogic _logicReinforced;
|
||||
private readonly IShopLogic _logicShop;
|
||||
public FormSellReinforced(ILogger<FormSellReinforced> logger, IReinforcedLogic logicReinforced, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicReinforced = logicReinforced;
|
||||
_logicShop = logicShop;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormSellReinforced_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Loading reinforcediss for sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicReinforced.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
ReindorcedСomboBox.DisplayMember = "ReinforcedName";
|
||||
ReindorcedСomboBox.ValueMember = "Id";
|
||||
ReindorcedСomboBox.DataSource = list;
|
||||
ReindorcedСomboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "List loading error.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(QuantityTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReindorcedСomboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Product sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SellReinforced(_logicReinforced.ReadElement(new ReinforcedSearchModel()
|
||||
{
|
||||
Id = Convert.ToInt32(ReindorcedСomboBox.SelectedValue)
|
||||
})!, Convert.ToInt32(QuantityTextBox.Text));
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Product sale error.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -40,7 +40,10 @@
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker();
|
||||
this.ReinforcedMaxCountLable = new System.Windows.Forms.Label();
|
||||
this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
@ -71,10 +74,10 @@
|
||||
this.PastryName,
|
||||
this.Price,
|
||||
this.Count});
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 64);
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 116);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(583, 213);
|
||||
this.dataGridView.Size = new System.Drawing.Size(583, 249);
|
||||
this.dataGridView.TabIndex = 2;
|
||||
//
|
||||
// PastryName
|
||||
@ -121,7 +124,7 @@
|
||||
// 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(492, 283);
|
||||
this.buttonCancel.Location = new System.Drawing.Point(492, 371);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(103, 23);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
@ -132,7 +135,7 @@
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonSave.Location = new System.Drawing.Point(366, 284);
|
||||
this.buttonSave.Location = new System.Drawing.Point(366, 372);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(120, 22);
|
||||
this.buttonSave.TabIndex = 8;
|
||||
@ -147,11 +150,29 @@
|
||||
this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23);
|
||||
this.textBoxDateOpening.TabIndex = 9;
|
||||
//
|
||||
// ReinforcedMaxCountLable
|
||||
//
|
||||
this.ReinforcedMaxCountLable.AutoSize = true;
|
||||
this.ReinforcedMaxCountLable.Location = new System.Drawing.Point(12, 53);
|
||||
this.ReinforcedMaxCountLable.Name = "ReinforcedMaxCountLable";
|
||||
this.ReinforcedMaxCountLable.Size = new System.Drawing.Size(140, 15);
|
||||
this.ReinforcedMaxCountLable.TabIndex = 10;
|
||||
this.ReinforcedMaxCountLable.Text = "Вместимость магазина: ";
|
||||
//
|
||||
// VolumeNumericUpDown
|
||||
//
|
||||
this.VolumeNumericUpDown.Location = new System.Drawing.Point(12, 71);
|
||||
this.VolumeNumericUpDown.Name = "VolumeNumericUpDown";
|
||||
this.VolumeNumericUpDown.Size = new System.Drawing.Size(141, 23);
|
||||
this.VolumeNumericUpDown.TabIndex = 11;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(607, 317);
|
||||
this.ClientSize = new System.Drawing.Size(607, 405);
|
||||
this.Controls.Add(this.VolumeNumericUpDown);
|
||||
this.Controls.Add(this.ReinforcedMaxCountLable);
|
||||
this.Controls.Add(this.textBoxDateOpening);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
@ -165,6 +186,7 @@
|
||||
this.Text = "Просмотр изделий магазина";
|
||||
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -184,5 +206,7 @@
|
||||
private DataGridViewTextBoxColumn Price;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private DateTimePicker textBoxDateOpening;
|
||||
private Label ReinforcedMaxCountLable;
|
||||
private NumericUpDown VolumeNumericUpDown;
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ namespace ConfectioneryView
|
||||
_logic = logic;
|
||||
if (_listShops != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "Reinforcedies";
|
||||
comboBoxShop.DisplayMember = "Name";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = _listShops;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
@ -69,8 +69,9 @@ namespace ConfectioneryView
|
||||
comboBoxShop.Text = model.Name;
|
||||
textBoxAddress.Text = model.Address;
|
||||
textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
|
||||
VolumeNumericUpDown.Value = model.ReinforcedMaxCount;
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var el in model.Reinforcedies.Values)
|
||||
foreach (var el in model.ShopReinforcedies.Values)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[]{el.Item1.ReinforcedName, el.Item1.Price, el.Item2 });
|
||||
}
|
||||
@ -104,7 +105,7 @@ namespace ConfectioneryView
|
||||
MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение изделия");
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
|
||||
@ -112,7 +113,8 @@ namespace ConfectioneryView
|
||||
{
|
||||
Name = comboBoxShop.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTime
|
||||
DateOpening = dateTime,
|
||||
ReinforcedMaxCount = (int)VolumeNumericUpDown.Value
|
||||
};
|
||||
var vmodel = GetShop(Id);
|
||||
bool operationResult = false;
|
||||
|
@ -1,64 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
@ -117,14 +57,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="ReinforcedName.UserAddedColumn" type="System.Boolean, mscorlib">
|
||||
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="Price.UserAddedColumn" type="System.Boolean, mscorlib">
|
||||
</metadata>
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="Count.UserAddedColumn" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
</metadata>
|
||||
</root>
|
@ -29,7 +29,7 @@ namespace ConfectioneryView
|
||||
dataGridView.DataSource = list;
|
||||
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Reinforcedies"].Visible = false;
|
||||
dataGridView.Columns["ShopReinforcedies"].Visible = false;
|
||||
dataGridView.Columns["Name"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ namespace PrecastConcretePlantView
|
||||
services.AddTransient<FormReinforceds>();
|
||||
services.AddTransient<FormReinforcedShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormSellReinforced>();
|
||||
services.AddTransient<FormShop>();
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IReinforcedStorage _reinforcedStorage;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_reinforcedStorage = reinforcedStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -48,19 +51,38 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
CheckModel(model);
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
|
||||
if (model.Status + 1 != newStatus)
|
||||
if (viewModel == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
model.Status = newStatus;
|
||||
if (viewModel.Status + 1 != newStatus)
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.Status = newStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId });
|
||||
|
||||
if (reinforced == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(reinforced));
|
||||
}
|
||||
|
||||
if (!_shopLogic.AddReinforced(reinforced, viewModel.Count))
|
||||
{
|
||||
throw new Exception($"AddReinforced operation failed. Shop is full.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
|
@ -25,7 +25,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ",
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ",
|
||||
model?.Name, model?.Id);
|
||||
var list = (model == null) ? _shopStorage.GetFullList() :
|
||||
_shopStorage.GetFilteredList(model);
|
||||
@ -43,7 +43,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}",
|
||||
_logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}",
|
||||
model.Name, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
@ -57,7 +57,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.Reinforcedies = new();
|
||||
model.ShopReinforcedies = new();
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
@ -65,6 +65,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool SellReinforced(IReinforcedModel reinforced, int count)
|
||||
{
|
||||
return _shopStorage.SellReinforced(reinforced, count);
|
||||
}
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
@ -73,6 +77,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
throw new ArgumentNullException("Нет названия магазина",
|
||||
nameof(model.Name));
|
||||
}
|
||||
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
@ -106,7 +111,11 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
throw new ArgumentNullException("Нет названия магазина",
|
||||
nameof(model.Name));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
|
||||
if (model.ReinforcedMaxCount < 0)
|
||||
{
|
||||
throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount));
|
||||
}
|
||||
_logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}",
|
||||
model.Name, model.Address, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
@ -124,43 +133,95 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count));
|
||||
}
|
||||
_logger.LogInformation("AddReinforcedInShop. ShopName:{ShopName}.Id:{ Id}",
|
||||
model.Name, model.Id);
|
||||
|
||||
_logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddReinforcedInShop element not found");
|
||||
_logger.LogWarning("AddReinforced element not found");
|
||||
return false;
|
||||
}
|
||||
_logger.LogInformation("AddReinforcedInShop find. Id:{Id}", element.Id);
|
||||
|
||||
|
||||
if (element.Reinforcedies.TryGetValue(reinforced.Id, out var pair))
|
||||
if (element.ReinforcedMaxCount - element.ShopReinforcedies.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
element.Reinforcedies[reinforced.Id] = (reinforced, count + pair.Item2);
|
||||
_logger.LogInformation(
|
||||
"AddReinforcedInShop. Has been added {count} {reinforced} in {ShopName}",
|
||||
count, reinforced.ReinforcedName, element.Name);
|
||||
throw new ArgumentNullException("Магазин переполнен", nameof(count));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddReinforced find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair))
|
||||
{
|
||||
element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2);
|
||||
_logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Reinforcedies[reinforced.Id] = (reinforced, count);
|
||||
_logger.LogInformation(
|
||||
"AddReinforcedInShop. Has been added {count} new Reinforced {reinforced} in {ShopName}",
|
||||
count, reinforced.ReinforcedName, element.Name);
|
||||
element.ShopReinforcedies[reinforced.Id] = (reinforced, count);
|
||||
_logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
Address = element.Address,
|
||||
Name = element.Name,
|
||||
DateOpening = element.DateOpening,
|
||||
Reinforcedies = element.Reinforcedies
|
||||
ReinforcedMaxCount = element.ReinforcedMaxCount,
|
||||
ShopReinforcedies = element.ShopReinforcedies,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool AddReinforced(IReinforcedModel reinforced, int count)
|
||||
{
|
||||
if (reinforced == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(reinforced));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
var freePlaces = _shopStorage.GetFullList()
|
||||
.Select(x => x.ReinforcedMaxCount - x.ShopReinforcedies
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - count;
|
||||
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddReinforced. Failed to add reinforced to shop. It's full.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
var temp = Math.Min(count, shop.ReinforcedMaxCount - shop.ShopReinforcedies.Select(x => x.Value.Item2).Sum());
|
||||
|
||||
if (temp <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AddReinforced(new() { Id = shop.Id }, reinforced, temp))
|
||||
{
|
||||
_logger.LogWarning("An error occurred while adding reinforced to shops");
|
||||
return false;
|
||||
}
|
||||
|
||||
count -= temp;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,10 @@ namespace PrecastConcretePlantContracts.BindingModels
|
||||
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforcedies
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies { get; set; } = new();
|
||||
|
||||
|
||||
public int Id { get; set; }
|
||||
public int ReinforcedMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,8 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count);
|
||||
bool AddReinforced(IReinforcedModel reinforced, int quantity);
|
||||
bool SellReinforced(IReinforcedModel reinforced, int quantity);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,5 +18,6 @@ namespace PrecastConcretePlantContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellReinforced(IReinforcedModel model, int quantity);
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ namespace PrecastConcretePlantContracts.ViewModels
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Время открытия")]
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
public DateTime DateOpening { get; set; }
|
||||
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int ReinforcedMaxCount { get; set; }
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforcedies
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models
|
||||
string Name { get; }
|
||||
string Address { get; }
|
||||
DateTime DateOpening { get; }
|
||||
Dictionary<int, (IReinforcedModel, int)> Reinforcedies { get; }
|
||||
Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies { get; }
|
||||
public int ReinforcedMaxCount { get; }
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@ namespace PrecastConcretePlantFileImplement
|
||||
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<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Reinforced> Reinforceds { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -32,6 +34,7 @@ namespace PrecastConcretePlantFileImplement
|
||||
"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 =>
|
||||
@ -39,6 +42,7 @@ namespace PrecastConcretePlantFileImplement
|
||||
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<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
@ -0,0 +1,112 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using PrecastConcretePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PrecastConcretePlantFileImplement.Implements
|
||||
{
|
||||
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 (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name ==
|
||||
model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(x => x.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 bool SellReinforced(IReinforcedModel model, int quantity)
|
||||
{
|
||||
if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id)))
|
||||
{
|
||||
int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2;
|
||||
if (QuantityInCurrentShop <= quantity)
|
||||
{
|
||||
shop.ShopReinforcedies.Remove(model.Id);
|
||||
quantity -= QuantityInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity);
|
||||
quantity = 0;
|
||||
}
|
||||
if (quantity == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using PrecastConcretePlantContracts.BindingModels;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PrecastConcretePlantFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime DateOpening { get; private set; }
|
||||
public Dictionary<int, int> Reinforcedies { get; private set; } = new();
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> _shopReinforcedies = null;
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopReinforcedies == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopReinforcedies = Reinforcedies.ToDictionary(x => x.Key, y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value));
|
||||
}
|
||||
return _shopReinforcedies;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ReinforcedMaxCount { 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,
|
||||
ReinforcedMaxCount = model.ReinforcedMaxCount,
|
||||
DateOpening = model.DateOpening,
|
||||
Reinforcedies = model.ShopReinforcedies.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),
|
||||
Name = element.Element("Name")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
|
||||
ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value),
|
||||
Reinforcedies = element.Element("ShopReinforcedies")!.Elements("Reinforced").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;
|
||||
ReinforcedMaxCount = model.ReinforcedMaxCount;
|
||||
Reinforcedies = model.ShopReinforcedies.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopReinforcedies = null;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
ShopReinforcedies = ShopReinforcedies,
|
||||
DateOpening = DateOpening,
|
||||
ReinforcedMaxCount = ReinforcedMaxCount,
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Name", Name),
|
||||
new XElement("Address", Address),
|
||||
new XElement("DateOpening", DateOpening),
|
||||
new XElement("ReinforcedMaxCount", ReinforcedMaxCount),
|
||||
new XElement("ShopReinforcedies", Reinforcedies
|
||||
.Select(x => new XElement("Reinforced",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray()));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using PrecastConcretePlantContracts.SearchModels;
|
||||
using PrecastConcretePlantContracts.StoragesContracts;
|
||||
using PrecastConcretePlantContracts.ViewModels;
|
||||
using PrecastConcretePlantDataModels.Models;
|
||||
using PrecastConcretePlantListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -32,7 +33,10 @@ namespace PrecastConcretePlantListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellReinforced(IReinforcedModel model, int quantity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
|
@ -17,11 +17,7 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
|
||||
public DateTime DateOpening { get; private set; }
|
||||
|
||||
public Dictionary<int, (IReinforcedModel, int)> Reinforcedies
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new();
|
||||
public Dictionary<int, (IReinforcedModel, int)> ShopReinforcedies { get; private set; } = new();
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
@ -37,7 +33,7 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
Reinforcedies = new()
|
||||
ShopReinforcedies = new()
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
@ -49,15 +45,16 @@ namespace PrecastConcretePlantListImplement.Models
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
Reinforcedies = model.Reinforcedies;
|
||||
ShopReinforcedies = model.ShopReinforcedies;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
Reinforcedies = Reinforcedies,
|
||||
ShopReinforcedies = ShopReinforcedies,
|
||||
DateOpening = DateOpening,
|
||||
};
|
||||
public int ReinforcedMaxCount => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user