Compare commits

...

5 Commits

34 changed files with 1259 additions and 56 deletions

View File

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj" />
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
<ProjectReference Include="..\FishFactoryFileImplement\FishFactoryFileImplement.csproj" />
<ProjectReference Include="..\FishFactoryListImplement\FishFactoryListImplement.csproj" />
</ItemGroup>

View File

@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModel", "..\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "..\FishFactoryListImplement\FishFactoryListImplement.csproj", "{A507DACE-7D8D-4C0F-AB5D-764FE1A61EDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryFileImplement", "..\FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{4EB943AB-67A8-4386-8874-FA0E3E98159C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -61,6 +63,14 @@ Global
{A507DACE-7D8D-4C0F-AB5D-764FE1A61EDC}.Release|Any CPU.Build.0 = Release|Any CPU
{A507DACE-7D8D-4C0F-AB5D-764FE1A61EDC}.Release|x86.ActiveCfg = Release|x86
{A507DACE-7D8D-4C0F-AB5D-764FE1A61EDC}.Release|x86.Build.0 = Release|x86
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Debug|x86.ActiveCfg = Debug|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Debug|x86.Build.0 = Debug|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Release|Any CPU.Build.0 = Release|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Release|x86.ActiveCfg = Release|Any CPU
{4EB943AB-67A8-4386-8874-FA0E3E98159C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -239,10 +239,10 @@
private TextBox textBoxName;
private TextBox textBoxPrice;
private GroupBox groupBox1;
private Button buttonSave;
private Button buttonCancel;
private DataGridViewTextBoxColumn Number;
private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Count;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -106,6 +106,7 @@
Margin = new Padding(3, 4, 3, 4);
Name = "FormComponent";
Text = "Компонент";
Load += FormComponent_Load;
ResumeLayout(false);
PerformLayout();
}

View File

@ -34,13 +34,14 @@
компонентыToolStripMenuItem = new ToolStripMenuItem();
консервыToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
toolStripLabelReplenish2 = new ToolStripLabel();
toolStripLabelSale = new ToolStripLabel();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
dataGridView = new DataGridView();
toolStripLabelReplenish2 = new ToolStripLabel();
toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -48,10 +49,10 @@
// toolStrip1
//
toolStrip1.ImageScalingSize = new Size(20, 20);
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish2 });
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish2, toolStripLabelSale });
toolStrip1.Location = new Point(0, 0);
toolStrip1.Name = "toolStrip1";
toolStrip1.Size = new Size(1107, 27);
toolStrip1.Size = new Size(1206, 27);
toolStrip1.TabIndex = 0;
toolStrip1.Text = "toolStrip1";
//
@ -86,9 +87,25 @@
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
// toolStripLabelReplenish2
//
toolStripLabelReplenish2.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripLabelReplenish2.Name = "toolStripLabelReplenish2";
toolStripLabelReplenish2.Size = new Size(98, 24);
toolStripLabelReplenish2.Text = "Пополнение";
toolStripLabelReplenish2.Click += toolStripLabelReplenish_Click;
//
// toolStripLabelSale
//
toolStripLabelSale.Name = "toolStripLabelSale";
toolStripLabelSale.Size = new Size(145, 24);
toolStripLabelSale.Text = "Продажа консервы";
toolStripLabelSale.Click += toolStripLabelSale_Click;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(914, 75);
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonCreateOrder.Location = new Point(998, 75);
buttonCreateOrder.Margin = new Padding(3, 4, 3, 4);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(161, 32);
@ -99,7 +116,8 @@
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(914, 133);
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonTakeOrderInWork.Location = new Point(998, 133);
buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(161, 32);
@ -110,7 +128,8 @@
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(914, 190);
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonOrderReady.Location = new Point(998, 190);
buttonOrderReady.Margin = new Padding(3, 4, 3, 4);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(161, 32);
@ -121,7 +140,8 @@
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(914, 241);
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonIssuedOrder.Location = new Point(998, 241);
buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(161, 32);
@ -132,7 +152,8 @@
//
// buttonRef
//
buttonRef.Location = new Point(914, 296);
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(998, 296);
buttonRef.Margin = new Padding(3, 4, 3, 4);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(161, 32);
@ -151,22 +172,14 @@
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 24;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(872, 580);
dataGridView.Size = new Size(952, 580);
dataGridView.TabIndex = 6;
//
// toolStripLabelReplenish2
//
toolStripLabelReplenish2.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripLabelReplenish2.Name = "toolStripLabelReplenish2";
toolStripLabelReplenish2.Size = new Size(168, 24);
toolStripLabelReplenish2.Text = "Пополнение магазина";
toolStripLabelReplenish2.Click += toolStripLabelReplenish_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1107, 615);
ClientSize = new Size(1206, 615);
Controls.Add(dataGridView);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
@ -199,5 +212,6 @@
private ToolStripMenuItem консервыToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripLabel toolStripLabelReplenish2;
private ToolStripLabel toolStripLabelSale;
}
}

View File

@ -28,6 +28,7 @@ namespace FishFactory.Forms
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Width = 80;
dataGridView.Columns["CannedId"].Visible = false;
dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
@ -76,6 +77,15 @@ namespace FishFactory.Forms
}
}
private void toolStripLabelSale_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSale));
if (service is FormShopSale form)
{
form.ShowDialog();
}
}
private void buttonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));

View File

@ -39,6 +39,8 @@
Count = new DataGridViewTextBoxColumn();
label3 = new Label();
openingDatePicker = new DateTimePicker();
textBoxCapacity = new TextBox();
label4 = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
@ -54,7 +56,7 @@
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 67);
label2.Location = new Point(12, 60);
label2.Name = "label2";
label2.Size = new Size(54, 20);
label2.TabIndex = 1;
@ -127,7 +129,7 @@
// label3
//
label3.AutoSize = true;
label3.Location = new Point(438, 23);
label3.Location = new Point(438, 63);
label3.Name = "label3";
label3.Size = new Size(113, 20);
label3.TabIndex = 7;
@ -135,16 +137,34 @@
//
// openingDatePicker
//
openingDatePicker.Location = new Point(557, 20);
openingDatePicker.Location = new Point(557, 60);
openingDatePicker.Name = "openingDatePicker";
openingDatePicker.Size = new Size(294, 27);
openingDatePicker.TabIndex = 8;
//
// textBoxCapacity
//
textBoxCapacity.Location = new Point(557, 20);
textBoxCapacity.Name = "textBoxCapacity";
textBoxCapacity.Size = new Size(294, 27);
textBoxCapacity.TabIndex = 9;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(438, 23);
label4.Name = "label4";
label4.Size = new Size(103, 20);
label4.TabIndex = 10;
label4.Text = "Вместимость:";
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(863, 568);
Controls.Add(label4);
Controls.Add(textBoxCapacity);
Controls.Add(openingDatePicker);
Controls.Add(label3);
Controls.Add(dataGridView);
@ -175,5 +195,7 @@
private DataGridViewTextBoxColumn Count;
private Label label3;
private DateTimePicker openingDatePicker;
private TextBox textBoxCapacity;
private Label label4;
}
}

View File

@ -13,7 +13,6 @@ namespace FishFactory.Forms
private int? _id;
public int Id { set { _id = value; } }
private Dictionary<int, (ICannedModel, int)> _shopCanneds;
private DateTime? _openingDate = null;
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
@ -38,6 +37,7 @@ namespace FishFactory.Forms
{
textBoxShopName.Text = view.ShopName;
textBoxAdress.Text = view.Adress;
textBoxCapacity.Text = view.CapacityCanned.ToString();
openingDatePicker.Value = view.OpeningDate;
_shopCanneds = view.ShopCanneds ?? new Dictionary<int, (ICannedModel, int)>();
LoadData();
@ -61,7 +61,7 @@ namespace FishFactory.Forms
dataGridView.Rows.Clear();
foreach (var sr in _shopCanneds)
{
dataGridView.Rows.Add(new object[] { sr.Value.Item1.CannedName, sr.Value.Item2});
dataGridView.Rows.Add(new object[] { sr.Value.Item1.CannedName, sr.Value.Item2 });
}
}
}
@ -84,6 +84,11 @@ namespace FishFactory.Forms
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCapacity.Text))
{
MessageBox.Show("Заполните вместимость магазина", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
@ -92,6 +97,7 @@ namespace FishFactory.Forms
Id = _id ?? 0,
ShopName = textBoxShopName.Text,
Adress = textBoxAdress.Text,
CapacityCanned = Convert.ToInt32(textBoxCapacity.Text),
OpeningDate = openingDatePicker.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);

View File

@ -123,10 +123,4 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="CannedName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

119
FishFactory/FormShopSale.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace FishFactory.Forms
{
partial class FormShopSale
{
/// <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()
{
buttonSell = new Button();
buttonCancel = new Button();
label1 = new Label();
label2 = new Label();
comboBoxCanned = new ComboBox();
textBoxCount = new TextBox();
SuspendLayout();
//
// buttonSell
//
buttonSell.Location = new Point(237, 109);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(118, 33);
buttonSell.TabIndex = 0;
buttonSell.Text = "Продать";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += buttonSell_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(378, 109);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(118, 33);
buttonCancel.TabIndex = 1;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(20, 23);
label1.Name = "label1";
label1.Size = new Size(79, 20);
label1.TabIndex = 2;
label1.Text = "Консерва:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(20, 66);
label2.Name = "label2";
label2.Size = new Size(93, 20);
label2.TabIndex = 3;
label2.Text = "Количество:";
//
// comboBoxCanned
//
comboBoxCanned.FormattingEnabled = true;
comboBoxCanned.Location = new Point(128, 20);
comboBoxCanned.Name = "comboBoxCanned";
comboBoxCanned.Size = new Size(325, 28);
comboBoxCanned.TabIndex = 4;
//
// textBoxCount
//
textBoxCount.Location = new Point(128, 63);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(325, 27);
textBoxCount.TabIndex = 5;
//
// FormShopSale
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(516, 151);
Controls.Add(textBoxCount);
Controls.Add(comboBoxCanned);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(buttonCancel);
Controls.Add(buttonSell);
Name = "FormShopSale";
Text = "Продажа консерв";
Load += FormShopSale_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSell;
private Button buttonCancel;
private Label label1;
private Label label2;
private ComboBox comboBoxCanned;
private TextBox textBoxCount;
}
}

View File

@ -0,0 +1,78 @@
using Microsoft.Extensions.Logging;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.SearchModels;
namespace FishFactory.Forms
{
public partial class FormShopSale : Form
{
private readonly ILogger _logger;
private readonly ICannedLogic _logicC;
private readonly IShopLogic _logicS;
private List<CannedViewModel> _cannedList = new List<CannedViewModel>();
public FormShopSale(ILogger<FormShopSale> logger, ICannedLogic logicC, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicC = logicC;
_logicS = logicS;
}
private void FormShopSale_Load(object sender, EventArgs e)
{
_cannedList = _logicC.ReadList(null);
if (_cannedList != null)
{
comboBoxCanned.DisplayMember = "CannedName";
comboBoxCanned.ValueMember = "Id";
comboBoxCanned.DataSource = _cannedList;
comboBoxCanned.SelectedItem = null;
_logger.LogInformation("Загрузка консерв для продажи");
}
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (comboBoxCanned.SelectedValue == null)
{
MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool sale = _logicS.Sale(new ReplenishSearchModel
{
CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (sale)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else
{
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания покупки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View 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>

View File

@ -47,13 +47,14 @@
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(525, 673);
dataGridView.Size = new Size(682, 673);
dataGridView.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.AccessibleRole = AccessibleRole.None;
buttonAdd.Location = new Point(565, 76);
buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Location = new Point(712, 76);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(130, 35);
buttonAdd.TabIndex = 1;
@ -64,7 +65,8 @@
// buttonUpd
//
buttonUpd.AccessibleRole = AccessibleRole.None;
buttonUpd.Location = new Point(565, 130);
buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Location = new Point(712, 130);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(130, 35);
buttonUpd.TabIndex = 2;
@ -75,7 +77,8 @@
// buttonDel
//
buttonDel.AccessibleRole = AccessibleRole.None;
buttonDel.Location = new Point(565, 186);
buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Location = new Point(712, 186);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(130, 35);
buttonDel.TabIndex = 3;
@ -86,7 +89,8 @@
// buttonRef
//
buttonRef.AccessibleRole = AccessibleRole.None;
buttonRef.Location = new Point(565, 243);
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(712, 243);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(130, 35);
buttonRef.TabIndex = 4;
@ -98,7 +102,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(722, 674);
ClientSize = new Size(869, 674);
Controls.Add(buttonRef);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);

View File

@ -31,6 +31,7 @@ namespace FishFactory.Forms
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopCanneds"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
//dataGridView.Columns["CapacityCanned"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка магазинов");
}

View File

@ -2,14 +2,14 @@ using FishFactory.Forms;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryBusinessLogic.BusinessLogic;
using FishFactoryContracts.StoragesContracts;
using FishFactoryListImplement.Implements;
using FishFactoryFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace FishFactory
{
internal static class Program
public static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
@ -53,6 +53,7 @@ namespace FishFactory
services.AddTransient<FormShops>();
services.AddTransient<FormShop>();
services.AddTransient<FormShopReplenish>();
services.AddTransient<FormShopSale>();
}
}
}

View File

@ -5,11 +5,6 @@ using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryBusinessLogic.BusinessLogic
{
@ -21,11 +16,13 @@ namespace FishFactoryBusinessLogic.BusinessLogic
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
@ -101,6 +98,19 @@ namespace FishFactoryBusinessLogic.BusinessLogic
if (model.Status == OrderStatus.Выдан)
{
var replenish = new ReplenishBindingModel
{
ShopId = 0,
CannedId = model.CannedId,
Count = model.Count,
};
if (!_shopStorage.ReplenishShops(replenish))
{
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
return false;
}
model.DateImplement = DateTime.Now;
}

View File

@ -115,13 +115,29 @@ namespace FishFactoryBusinessLogic.BusinessLogic
});
if (canned == null)
{
throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найденн");
throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найден");
}
shop.ShopCanneds.Add(model.CannedId, (canned, model.Count));
}
return true;
}
public bool Sale(ReplenishSearchModel model)
{
if (!model.CannedId.HasValue || !model.Count.HasValue)
{
return false;
}
_logger.LogInformation("Check canned count in all shops");
if (_shopStorage.Sale(model))
{
_logger.LogInformation("Selling success");
return true;
}
_logger.LogInformation("Selling failed");
return false;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -8,6 +8,7 @@ namespace FishFactoryContracts.BindingModels
public string ShopName { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
public int CapacityCanned { get; set; }
public Dictionary<int, (ICannedModel, int)> ShopCanneds { get; set; } = new();
}
}

View File

@ -11,6 +11,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool Sale(ReplenishSearchModel model);
bool Replenish(ReplenishBindingModel model);
}
}

View File

@ -0,0 +1,8 @@
namespace FishFactoryContracts.SearchModels
{
public class ReplenishSearchModel
{
public int? CannedId { get; set; }
public int? Count { get; set; }
}
}

View File

@ -1,11 +1,6 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryContracts.StoragesContracts
{
@ -17,5 +12,7 @@ namespace FishFactoryContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool Sale(ReplenishSearchModel model);
bool ReplenishShops(ReplenishBindingModel model);
}
}

View File

@ -1,10 +1,5 @@
using FishFactoryDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryContracts.ViewModels
{
@ -15,6 +10,9 @@ namespace FishFactoryContracts.ViewModels
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес")]
public string Adress { get; set; } = string.Empty;
[DisplayName("Вместимость")]
public int CapacityCanned { get; set; }
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (ICannedModel, int)> ShopCanneds { get; set; } = new();

View File

@ -0,0 +1,54 @@

using FishFactoryFileImplement.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement
{
internal class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string CannedFileName = "Canned.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Canned> Canneds { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveCanneds() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FishFactoryContracts\FishFactoryContracts.csproj" />
<ProjectReference Include="..\FishFactoryDataModels\FishFactoryDataModel.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,72 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryFileImplement.Models;
namespace FishFactoryFileImplement.Implements
{
public class CannedStorage : ICannedStorage
{
private readonly DataFileSingleton _source;
public CannedStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<CannedViewModel> GetFullList()
{
return _source.Canneds.Select(x => x.GetViewModel).ToList();
}
public List<CannedViewModel> GetFilteredList(CannedSearchModel model)
{
if (string.IsNullOrEmpty(model.CannedName))
{
return new();
}
return _source.Canneds.Where(x => x.CannedName.Contains(model.CannedName)).Select(x => x.GetViewModel).ToList();
}
public CannedViewModel? GetElement(CannedSearchModel model)
{
if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue)
{
return null;
}
return _source.Canneds.FirstOrDefault
(x => (!string.IsNullOrEmpty(model.CannedName) && x.CannedName == model.CannedName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public CannedViewModel? Insert(CannedBindingModel model)
{
model.Id = _source.Canneds.Count > 0 ? _source.Canneds.Max(x => x.Id) + 1 : 1;
var newCanned = Canned.Create(model);
if (newCanned == null)
{
return null;
}
_source.Canneds.Add(newCanned);
_source.SaveCanneds();
return newCanned.GetViewModel;
}
public CannedViewModel? Update(CannedBindingModel model)
{
var canned = _source.Canneds.FirstOrDefault(x => x.Id == model.Id);
if (canned == null)
{
return null;
}
canned.Update(model);
_source.SaveCanneds();
return canned.GetViewModel;
}
public CannedViewModel? Delete(CannedBindingModel model)
{
var element = _source.Canneds.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Canneds.Remove(element);
_source.SaveCanneds();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,72 @@
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using FishFactoryFileImplement.Models;
namespace FishFactoryFileImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataFileSingleton _source;
public ComponentStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
return _source.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return _source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
return _source.Components.FirstOrDefault
(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
_source.Components.Add(newComponent);
_source.SaveComponents();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
var component = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
_source.SaveComponents();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
var element = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Components.Remove(element);
_source.SaveComponents();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,84 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryFileImplement.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton _source;
public OrderStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return _source.Orders.Select(x => AttachCannedName(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Orders.Where(x => x.Id == model.Id).Select(x => AttachCannedName(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return AttachCannedName(_source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
_source.Orders.Add(newOrder);
_source.SaveOrders();
return AttachCannedName(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
_source.SaveOrders();
return AttachCannedName(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
_source.Orders.Remove(order);
_source.SaveOrders();
return AttachCannedName(order);
}
private OrderViewModel AttachCannedName(Order order)
{
var viewModel = order.GetViewModel;
var canned = _source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
if (canned != null)
{
viewModel.CannedName = canned.CannedName;
}
return viewModel;
}
}
}

View File

@ -0,0 +1,143 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryFileImplement.Models;
namespace FishFactoryFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton _source;
public ShopStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return _source.Shops.Select(x => x.GetViewModel).ToList();
}
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 ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return _source.Shops.FirstOrDefault
(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
_source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var canned = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (canned == null)
{
return null;
}
canned.Update(model);
_source.SaveShops();
return canned.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Shops.Remove(element);
_source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool Sale(ReplenishSearchModel model)
{
if (model == null || !model.CannedId.HasValue || !model.Count.HasValue)
return false;
int totalCount = _source.Shops.Select(x => x.Canneds.ContainsKey(model.CannedId.Value) ? x.Canneds[model.CannedId.Value] : 0).Sum();
if (totalCount < model.Count)
{
return false;
}
var shops = _source.Shops.Where(x => x.Canneds.ContainsKey(model.CannedId.Value)).OrderByDescending(x => x.Canneds[model.CannedId.Value]).ToList();
foreach ( var shop in shops )
{
int remains = model.Count.Value - shop.Canneds[model.CannedId.Value];
if (remains > 0)
{
shop.Canneds.Remove(model.CannedId.Value);
model.Count = remains;
}
else
{
if (remains == 0)
{
shop.Canneds.Remove(model.CannedId.Value);
}
else
{
shop.Canneds[model.CannedId.Value] = -remains;
}
shop.CannedsUpdate();
_source.SaveShops();
return true;
}
}
_source.SaveShops();
return false;
}
public bool ReplenishShops(ReplenishBindingModel model)
{
int totalFreePlace = _source.Shops.Select(x => x.CapacityCanned - x.ShopCanneds.Select(x => x.Value.Item2).Sum()).Sum();
if (model == null || totalFreePlace < model.Count)
{
return false;
}
foreach (var shop in _source.Shops)
{
int freePlace = shop.CapacityCanned - shop.ShopCanneds.Select(x => x.Value.Item2).Sum();
if (freePlace <= 0)
{
continue;
}
freePlace = Math.Min(freePlace, model.Count);
model.Count -= freePlace;
if (shop.Canneds.ContainsKey(model.CannedId))
{
shop.Canneds[model.CannedId] += freePlace;
}
else
{
shop.Canneds.Add(model.CannedId, freePlace);
}
shop.CannedsUpdate();
if (model.Count == 0)
{
_source.SaveShops();
return true;
}
}
return false;
}
}
}

View File

@ -0,0 +1,88 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
using FishFactoryFileImplement;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
internal class Canned : ICannedModel
{
public int Id { get; private set; }
public string CannedName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _cannedComponents = null;
public Dictionary<int, (IComponentModel, int)> CannedComponents
{
get
{
if (_cannedComponents == null)
{
var source = DataFileSingleton.GetInstance();
_cannedComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _cannedComponents;
}
}
public static Canned? Create(CannedBindingModel? model)
{
if (model == null)
{
return null;
}
return new Canned()
{
Id = model.Id,
CannedName = model.CannedName,
Price = model.Price,
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Canned? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Canned()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CannedName = element.Element("CannedName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("CannedComponents")!.Elements("CannedComponent").ToDictionary
(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))};
}
public void Update(CannedBindingModel? model)
{
if (model == null)
{
return;
}
CannedName = model.CannedName;
Price = model.Price;
Components = model.CannedComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_cannedComponents = null;
}
public CannedViewModel GetViewModel => new()
{
Id = Id,
CannedName = CannedName,
Price = Price,
CannedComponents = CannedComponents
};
public XElement GetXElement => new("Canned",
new XAttribute("Id", Id),
new XElement("CannedName", CannedName),
new XElement("Price", Price.ToString()),
new XElement("CannedComponents", Components.Select(x =>
new XElement("CannedComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,62 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,85 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Enums;
using FishFactoryDataModel.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int CannedId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CannedId = Convert.ToInt32(element.Element("CannedId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value),
};
}
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
CannedId = model.CannedId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
CannedId = model.CannedId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
CannedId = CannedId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("CannedId", CannedId),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString())
);
}
}

View File

@ -0,0 +1,102 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
internal class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public int CapacityCanned { get; private set; }
public Dictionary<int, int> Canneds { get; private set; } = new();
private Dictionary<int, (ICannedModel, int)>? _shopCanneds = null;
public Dictionary<int, (ICannedModel, int)> ShopCanneds
{
get
{
if (_shopCanneds == null)
{
var source = DataFileSingleton.GetInstance();
_shopCanneds = Canneds.ToDictionary(x => x.Key,
y => ((source.Canneds.FirstOrDefault(z => z.Id == y.Key) as ICannedModel)!, y.Value));
}
return _shopCanneds;
}
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Adress = element.Element("Adress")!.Value,
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
CapacityCanned = Convert.ToInt32(element.Element("CapacityCanned")!.Value),
Canneds = element.Element("ShopCanneds")!.Elements("ShopCanned")!.ToDictionary
(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))};
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
CapacityCanned = model.CapacityCanned,
Canneds = model.ShopCanneds.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
CapacityCanned = model.CapacityCanned;
_shopCanneds = null;
}
public void CannedsUpdate()
{
_shopCanneds = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
CapacityCanned = CapacityCanned,
ShopCanneds = ShopCanneds
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Adress", Adress),
new XElement("OpeningDate", OpeningDate.ToString()),
new XElement("CapacityCanned", CapacityCanned.ToString()),
new XElement("ShopCanneds", Canneds.Select(
x => new XElement("ShopCanned", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())
);
}
}

View File

@ -3,6 +3,7 @@ using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryListImplement.Models;
using System.Reflection;
namespace FishFactoryListImplement.Implements
{
@ -96,5 +97,14 @@ namespace FishFactoryListImplement.Implements
}
return null;
}
public bool Sale(ReplenishSearchModel model)
{
throw new NotImplementedException();
}
public bool ReplenishShops(ReplenishBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,6 +1,7 @@
using FishFactoryContracts.BindingModels;
using FishFactoryDataModel.Models;
using FishFactoryContracts.ViewModels;
using System.Reflection;
namespace FishFactoryListImplement.Models
{
@ -10,6 +11,7 @@ namespace FishFactoryListImplement.Models
public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public int CapacityCanned { get; private set; }
public Dictionary<int, (ICannedModel, int)> ShopCanneds
{
get;
@ -28,6 +30,7 @@ namespace FishFactoryListImplement.Models
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
CapacityCanned = model.CapacityCanned,
ShopCanneds = model.ShopCanneds
};
}
@ -40,6 +43,7 @@ namespace FishFactoryListImplement.Models
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
CapacityCanned = model.CapacityCanned;
}
public ShopViewModel GetViewModel => new()
@ -48,6 +52,7 @@ namespace FishFactoryListImplement.Models
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
CapacityCanned = CapacityCanned,
ShopCanneds = ShopCanneds
};
}