PIbd-23 Dyakonov R R Hard Lab work 2 #6
@ -33,6 +33,8 @@
|
||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||
изделияToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
поставкиToolStripMenuItem = new ToolStripMenuItem();
|
||||
продажиToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
@ -57,7 +59,7 @@
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажиToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
@ -83,6 +85,21 @@
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
|
||||
//
|
||||
// поставкиToolStripMenuItem
|
||||
//
|
||||
поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
|
||||
поставкиToolStripMenuItem.Size = new Size(180, 22);
|
||||
поставкиToolStripMenuItem.Text = "Поставки";
|
||||
поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click;
|
||||
// продажиToolStripMenuItem
|
||||
//
|
||||
продажиToolStripMenuItem.Name = "продажиToolStripMenuItem";
|
||||
продажиToolStripMenuItem.Size = new Size(180, 22);
|
||||
продажиToolStripMenuItem.Text = "Продажи";
|
||||
продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click;
|
||||
//
|
||||
//
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
@ -207,6 +224,8 @@
|
||||
private Button buttonIssuedOrder;
|
||||
private Button buttonRefresh;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripMenuItem поставкиToolStripMenuItem;
|
||||
private ToolStripMenuItem продажиToolStripMenuItem;
|
||||
private Button shopReplenishment;
|
||||
}
|
||||
}
|
@ -87,6 +87,24 @@ namespace SoftwareInstallationView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void поставкиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment));
|
||||
if (service is FormShopReplenishment form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void продажиToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellPackage));
|
||||
if (service is FormSellPackage form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
|
119
SoftwareInstallation/SoftwareInstallation/FormSellPackage.Designer.cs
generated
Normal file
119
SoftwareInstallation/SoftwareInstallation/FormSellPackage.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace SoftwareInstallationView
|
||||
{
|
||||
partial class FormSellPackage
|
||||
{
|
||||
/// <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.PackageLabel = new System.Windows.Forms.Label();
|
||||
this.QuantityLabel = new System.Windows.Forms.Label();
|
||||
this.PackageС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();
|
||||
//
|
||||
// PackageLabel
|
||||
//
|
||||
this.PackageLabel.AutoSize = true;
|
||||
this.PackageLabel.Location = new System.Drawing.Point(12, 18);
|
||||
this.PackageLabel.Name = "PackageLabel";
|
||||
this.PackageLabel.Size = new System.Drawing.Size(56, 15);
|
||||
this.PackageLabel.TabIndex = 0;
|
||||
this.PackageLabel.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 = "Количество:";
|
||||
//
|
||||
// PackageСomboBox
|
||||
//
|
||||
this.PackageСomboBox.FormattingEnabled = true;
|
||||
this.PackageСomboBox.Location = new System.Drawing.Point(88, 15);
|
||||
this.PackageСomboBox.Name = "PackageСomboBox";
|
||||
this.PackageСomboBox.Size = new System.Drawing.Size(184, 23);
|
||||
this.PackageС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);
|
||||
//
|
||||
// FromSellPackage
|
||||
//
|
||||
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.PackageСomboBox);
|
||||
this.Controls.Add(this.QuantityLabel);
|
||||
this.Controls.Add(this.PackageLabel);
|
||||
this.Name = "FromSellPackage";
|
||||
this.Text = "Продать Изделие";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label PackageLabel;
|
||||
private Label QuantityLabel;
|
||||
private ComboBox PackageСomboBox;
|
||||
private TextBox QuantityTextBox;
|
||||
private Button SaveButton;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
103
SoftwareInstallation/SoftwareInstallation/FormSellPackage.cs
Normal file
103
SoftwareInstallation/SoftwareInstallation/FormSellPackage.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SoftwareInstallationContracts.BusinessLogicContracts;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SoftwareInstallationView
|
||||
{
|
||||
public partial class FormSellPackage : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPackageLogic _logicPackage;
|
||||
private readonly IShopLogic _logicStore;
|
||||
public FormSellPackage(ILogger<FormSellPackage> logger, IPackageLogic logicPackage, IShopLogic logicStore)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicPackage = logicPackage;
|
||||
_logicStore = logicStore;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormSellPackage_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Loading packages for sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicPackage.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
PackageСomboBox.DisplayMember = "PackageName";
|
||||
PackageСomboBox.ValueMember = "Id";
|
||||
PackageСomboBox.DataSource = list;
|
||||
PackageС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 (PackageСomboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Package sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var operationResult = _logicStore.SellPackage(_logicPackage.ReadElement(new PackageSearchModel()
|
||||
{
|
||||
Id = Convert.ToInt32(PackageС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, "Package sale error.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
SoftwareInstallation/SoftwareInstallation/FormSellPackage.resx
Normal file
120
SoftwareInstallation/SoftwareInstallation/FormSellPackage.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?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.
|
||||
-->
|
||||
<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 @@
|
||||
SaveButton = new Button();
|
||||
ButtonCancel = new Button();
|
||||
nameTextBox = new TextBox();
|
||||
labelNumeric = new Label();
|
||||
numericUpDown = new NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// shopNameLabel
|
||||
@ -152,11 +155,29 @@
|
||||
nameTextBox.Size = new Size(198, 27);
|
||||
nameTextBox.TabIndex = 10;
|
||||
//
|
||||
// labelNumeric
|
||||
//
|
||||
labelNumeric.AutoSize = true;
|
||||
labelNumeric.Location = new Point(416, 12);
|
||||
labelNumeric.Name = "labelNumeric";
|
||||
labelNumeric.Size = new Size(161, 20);
|
||||
labelNumeric.TabIndex = 11;
|
||||
labelNumeric.Text = "Макс. кол-во товара: ";
|
||||
//
|
||||
// numericUpDown
|
||||
//
|
||||
numericUpDown.Location = new Point(576, 9);
|
||||
numericUpDown.Name = "numericUpDown";
|
||||
numericUpDown.Size = new Size(150, 27);
|
||||
numericUpDown.TabIndex = 12;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 600);
|
||||
Controls.Add(numericUpDown);
|
||||
Controls.Add(labelNumeric);
|
||||
Controls.Add(nameTextBox);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(SaveButton);
|
||||
@ -171,6 +192,7 @@
|
||||
Text = "Магазин";
|
||||
Load += FormShop_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -189,5 +211,7 @@
|
||||
private DataGridViewTextBoxColumn PackagePrice;
|
||||
private DataGridViewTextBoxColumn PackageCount;
|
||||
private TextBox nameTextBox;
|
||||
private Label labelNumeric;
|
||||
private NumericUpDown numericUpDown;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.BusinessLogicContracts;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using System;
|
||||
@ -20,32 +21,18 @@ namespace SoftwareInstallationView
|
||||
private readonly List<ShopViewModel>? _listShops;
|
||||
private readonly IShopLogic _logic;
|
||||
private readonly ILogger _logger;
|
||||
public int Id { get; set; }
|
||||
private int? _id;
|
||||
private Dictionary<int, (IPackageModel, int)> _listStores;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_listShops = logic.ReadList(null);
|
||||
_listShops = new();
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private IShopModel? GetShop(int id)
|
||||
{
|
||||
if (_listShops == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _listShops)
|
||||
{
|
||||
if (elem.Id == id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nameTextBox.Text))
|
||||
@ -60,31 +47,19 @@ namespace SoftwareInstallationView
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение изделия");
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
|
||||
try
|
||||
{
|
||||
DateTime.TryParse(openingDatePicker.Text, out var dateTime);
|
||||
ShopBindingModel model = new()
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = nameTextBox.Text,
|
||||
ShopAddress = addressTextBox.Text,
|
||||
OpeningDate = dateTime
|
||||
OpeningDate = openingDatePicker.Value.Date,
|
||||
PackageMaxCount = (int)numericUpDown.Value
|
||||
};
|
||||
var vmodel = GetShop(Id);
|
||||
bool operationResult = false;
|
||||
|
||||
if (vmodel != null)
|
||||
{
|
||||
model.Id = vmodel.Id;
|
||||
model.Packages = vmodel.Packages;
|
||||
operationResult = _logic.Update(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
operationResult = _logic.Create(model);
|
||||
}
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
@ -96,7 +71,7 @@ namespace SoftwareInstallationView
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||
_logger.LogError(ex, "Ошибка сохранения магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
@ -109,31 +84,52 @@ namespace SoftwareInstallationView
|
||||
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
nameTextBox.Text = view.ShopName;
|
||||
addressTextBox.Text = view.ShopAddress;
|
||||
openingDatePicker.Text = view.OpeningDate.ToString();
|
||||
numericUpDown.Value = view.PackageMaxCount;
|
||||
_listStores = view.ShopPackages ?? new Dictionary<int, (IPackageModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadData(bool extendDate = true)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделий магазина");
|
||||
try
|
||||
{
|
||||
var model = GetShop(extendDate ? Id : Convert.ToInt32(nameTextBox.Text));
|
||||
if (model != null)
|
||||
if (_listStores != null)
|
||||
{
|
||||
nameTextBox.Text = model.ShopName;
|
||||
addressTextBox.Text = model.ShopAddress;
|
||||
openingDatePicker.Text = Convert.ToString(model.OpeningDate);
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var el in model.Packages.Values)
|
||||
foreach (var elem in _listStores)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { el.Item1.PackageName, el.Item1.Price, el.Item2 });
|
||||
dataGridView.Rows.Add(new object[] { elem.Value.Item1.PackageName, elem.Value.Item1.Price, elem.Value.Item2 });
|
||||
}
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace SoftwareInstallationView
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Packages"].Visible = false;
|
||||
dataGridView.Columns["ShopPackages"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
|
@ -55,6 +55,7 @@ namespace SoftwareInstallation
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShopReplenishment>();
|
||||
services.AddTransient<FormSellPackage>();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,11 +17,15 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IPackageStorage _packageStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IPackageStorage packageStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_packageStorage = packageStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -48,7 +52,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new() { Id = model.Id });
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
@ -65,7 +69,25 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
||||
var package = _packageStorage.GetElement(new() { Id = viewModel.PackageId });
|
||||
|
||||
if (package == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(package));
|
||||
}
|
||||
|
||||
if (!_shopLogic.AddPackage(package, viewModel.Count))
|
||||
{
|
||||
throw new Exception($"AddPackage operation failed. Store is full.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
|
||||
CheckModel(model, false);
|
||||
|
||||
model.Sum = viewModel.Sum;
|
||||
model.Count = viewModel.Count;
|
||||
|
@ -43,16 +43,20 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.Packages.TryGetValue(package.Id, out var pair))
|
||||
if (element.PackageMaxCount - element.ShopPackages.Select(x => x.Value.Item2).Sum() < quantity)
|
||||
{
|
||||
element.Packages[package.Id] = (package, quantity + pair.Item2);
|
||||
throw new ArgumentNullException("Магазин переполнен", nameof(quantity));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id);
|
||||
if (element.ShopPackages.TryGetValue(package.Id, out var pair))
|
||||
{
|
||||
element.ShopPackages[package.Id] = (package, quantity + pair.Item2);
|
||||
_logger.LogInformation("AddPackageInShop. Has been added {quantity} {package} in {ShopName}", quantity, package.PackageName, element.ShopName);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Packages[package.Id] = (package, quantity);
|
||||
element.ShopPackages[package.Id] = (package, quantity);
|
||||
_logger.LogInformation("AddPackageInShop. Has been added {quantity} new Package {package} in {ShopName}", quantity, package.PackageName, element.ShopName);
|
||||
}
|
||||
|
||||
@ -62,15 +66,63 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
ShopAddress = element.ShopAddress,
|
||||
ShopName = element.ShopName,
|
||||
OpeningDate = element.OpeningDate,
|
||||
Packages = element.Packages
|
||||
ShopPackages = element.ShopPackages,
|
||||
PackageMaxCount = element.PackageMaxCount
|
||||
});
|
||||
return true;
|
||||
}
|
||||
public bool AddPackage(IPackageModel package, int quantity)
|
||||
{
|
||||
if (package == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(package));
|
||||
}
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
||||
}
|
||||
|
||||
var freePlaces = _ShopStorage.GetFullList()
|
||||
.Select(x => x.PackageMaxCount - x.ShopPackages
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - quantity;
|
||||
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddPackage. Failed to add package to store. It's full.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var store in _ShopStorage.GetFullList())
|
||||
{
|
||||
var temp = Math.Min(quantity, store.PackageMaxCount - store.ShopPackages.Select(x => x.Value.Item2).Sum());
|
||||
|
||||
if (temp <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AddPackage(new() { Id = store.Id }, package, temp))
|
||||
{
|
||||
_logger.LogWarning("An error occurred while adding package to stores");
|
||||
return false;
|
||||
}
|
||||
|
||||
quantity -= temp;
|
||||
|
||||
if (quantity == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.Packages = new();
|
||||
model.ShopPackages = new();
|
||||
|
||||
if (_ShopStorage.Insert(model) == null)
|
||||
{
|
||||
@ -81,6 +133,11 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellPackage(IPackageModel package, int quantity)
|
||||
{
|
||||
return _ShopStorage.SellPackage(package, quantity);
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
@ -165,6 +222,11 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
|
||||
if (model.PackageMaxCount < 0)
|
||||
{
|
||||
throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.PackageMaxCount));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop. ShopName:{0}.ShopAddress:{1}. Id: {2}", model.ShopName, model.ShopAddress, model.Id);
|
||||
var element = _ShopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
|
@ -12,7 +12,8 @@ namespace SoftwareInstallationContracts.BindingModels
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public string ShopAddress { get; set; } = string.Empty;
|
||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (IPackageModel, int)> Packages { get; set; } = new();
|
||||
public Dictionary<int, (IPackageModel, int)> ShopPackages { get; set; } = new();
|
||||
public int Id { get; set; }
|
||||
public int PackageMaxCount { get; set; }
|
||||
}
|
||||
}
|
@ -18,5 +18,7 @@ namespace SoftwareInstallationContracts.BusinessLogicContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool AddPackage(ShopSearchModel model, IPackageModel package, int quantity);
|
||||
bool AddPackage(IPackageModel package, int quantity);
|
||||
bool SellPackage(IPackageModel package, int quantity);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,5 +18,6 @@ namespace SoftwareInstallationContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellPackage(IPackageModel model, int quantity);
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace SoftwareInstallationContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public Dictionary<int, (IPackageModel, int)> Packages { get; set; } = new();
|
||||
public Dictionary<int, (IPackageModel, int)> ShopPackages { get; set; } = new();
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название магазина")]
|
||||
@ -19,5 +19,7 @@ namespace SoftwareInstallationContracts.ViewModels
|
||||
public string ShopAddress { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int PackageMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace SoftwareInstallationDataModels.Models
|
||||
public string ShopName { get; }
|
||||
public string ShopAddress { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (IPackageModel, int)> Packages { get; }
|
||||
Dictionary<int, (IPackageModel, int)> ShopPackages { get; }
|
||||
public int PackageMaxCount { get; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace SoftwareInstallationFileImplement
|
||||
{
|
||||
@ -14,9 +15,11 @@ namespace SoftwareInstallationFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string PackageFileName = "Package.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Package> Packages { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -26,13 +29,15 @@ namespace SoftwareInstallationFileImplement
|
||||
return instance;
|
||||
}
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement);
|
||||
public void SavePackages() => SaveData(Packages, PackageFileName, "ShopPackages", 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)!)!;
|
||||
Packages = LoadData(PackageFileName, "Package", x => Package.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,115 @@
|
||||
using SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.StoragesContracts;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using SoftwareInstallationFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace SoftwareInstallationFileImplement.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.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName ==
|
||||
model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops.Where(x =>
|
||||
x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public 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 SellPackage(IPackageModel model, int quantity)
|
||||
{
|
||||
if (source.Shops.Select(x => x.ShopPackages.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var Shop in source.Shops.Where(x => x.ShopPackages.ContainsKey(model.Id)))
|
||||
{
|
||||
int QuantityInCurrentShop = Shop.ShopPackages[model.Id].Item2;
|
||||
if (QuantityInCurrentShop <= quantity)
|
||||
{
|
||||
Shop.ShopPackages.Remove(model.Id);
|
||||
quantity -= QuantityInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
Shop.ShopPackages[model.Id] = (Shop.ShopPackages[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 SoftwareInstallationContracts.BindingModels;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SoftwareInstallationFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string ShopAddress { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, int> Packages { get; private set; } = new();
|
||||
|
||||
public Dictionary<int, (IPackageModel, int)> _Packages = null;
|
||||
public Dictionary<int, (IPackageModel, int)> ShopPackages
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Packages == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_Packages = Packages.ToDictionary(x => x.Key, y => ((source.Packages.FirstOrDefault(z => z.Id == y.Key) as IPackageModel)!, y.Value));
|
||||
}
|
||||
return _Packages;
|
||||
}
|
||||
}
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int PackageMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
ShopAddress = model.ShopAddress,
|
||||
PackageMaxCount = model.PackageMaxCount,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Packages = model.ShopPackages.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ShopName = element.Element("ShopName")!.Value,
|
||||
ShopAddress = element.Element("ShopAddress")!.Value,
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
PackageMaxCount = Convert.ToInt32(element.Element("PackageMaxCount")!.Value),
|
||||
Packages = element.Element("ShopPackages")!.Elements("Package").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
ShopAddress = model.ShopAddress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
PackageMaxCount = model.PackageMaxCount;
|
||||
Packages = model.ShopPackages.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_Packages = null;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
ShopAddress = ShopAddress,
|
||||
ShopPackages = ShopPackages,
|
||||
OpeningDate = OpeningDate,
|
||||
PackageMaxCount = PackageMaxCount,
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("ShopAddress", ShopAddress),
|
||||
new XElement("OpeningDate", OpeningDate),
|
||||
new XElement("PackageMaxCount", PackageMaxCount),
|
||||
new XElement("ShopPackages", Packages
|
||||
.Select(x => new XElement("Package",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray()));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using SoftwareInstallationContracts.SearchModels;
|
||||
using SoftwareInstallationContracts.StoragesContracts;
|
||||
using SoftwareInstallationContracts.ViewModels;
|
||||
using SoftwareInstallationDataModels.Models;
|
||||
using SoftwareInstallationListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -107,6 +108,11 @@ namespace SoftwareInstallationListImplement.Implements
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellPackage(IPackageModel model, int quantity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
foreach (var shop in _source.Shops)
|
||||
|
@ -16,7 +16,7 @@ namespace SoftwareInstallationListImplement.Models
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, (IPackageModel, int)> Packages { get; private set; } = new();
|
||||
public Dictionary<int, (IPackageModel, int)> ShopPackages { get; private set; } = new();
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
@ -32,7 +32,7 @@ namespace SoftwareInstallationListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
ShopAddress = model.ShopAddress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Packages = new()
|
||||
ShopPackages = new()
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ namespace SoftwareInstallationListImplement.Models
|
||||
ShopName = model.ShopName;
|
||||
ShopAddress = model.ShopAddress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
Packages = model.Packages;
|
||||
ShopPackages = model.ShopPackages;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
@ -54,7 +54,9 @@ namespace SoftwareInstallationListImplement.Models
|
||||
ShopName = ShopName,
|
||||
ShopAddress = ShopAddress,
|
||||
OpeningDate = OpeningDate,
|
||||
Packages = Packages
|
||||
ShopPackages = ShopPackages
|
||||
};
|
||||
|
||||
public int PackageMaxCount => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user