Compare commits
No commits in common. "ee4962b0d579340c3809de2fcadb6749f408c17f" and "c44c5476554e98bf4fa3d1b48bac4e98bb66c848" have entirely different histories.
ee4962b0d5
...
c44c547655
1
.gitignore
vendored
1
.gitignore
vendored
@ -398,4 +398,3 @@ FodyWeavers.xsd
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
/Confectionery/ImplementationExtensions
|
||||
|
@ -7,13 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Confectionery", "Confection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{22A053DC-3DC2-4375-9563-BF647A1092A4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6C4950D1-D788-4D5A-8C15-0A376274F2DD}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6C4950D1-D788-4D5A-8C15-0A376274F2DD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryFileImplement", "ConfectioneryFileImplements\ConfectioneryFileImplement.csproj", "{48A8592F-EF58-4FC4-9C9E-B401836FF21E}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -41,10 +39,6 @@ Global
|
||||
{85992074-656D-4F79-AB23-60DE4F9ABF30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48A8592F-EF58-4FC4-9C9E-B401836FF21E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -31,7 +31,6 @@
|
||||
<ProjectReference Include="..\ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
<ProjectReference Include="..\ConfectioneryFileImplements\ConfectioneryFileImplement.csproj" />
|
||||
<ProjectReference Include="..\ConfectioneryListImplement\ConfectioneryListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
24
Confectionery/Confectionery/FormMain.Designer.cs
generated
24
Confectionery/Confectionery/FormMain.Designer.cs
generated
@ -33,14 +33,13 @@
|
||||
this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.списаниеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -50,8 +49,7 @@
|
||||
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.справочникиToolStripMenuItem,
|
||||
this.пополнениеМагазинаToolStripMenuItem,
|
||||
this.списаниеToolStripMenuItem});
|
||||
this.пополнениеМагазинаToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1238, 28);
|
||||
@ -89,13 +87,6 @@
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
//
|
||||
// пополнениеМагазинаToolStripMenuItem
|
||||
//
|
||||
this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
||||
this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24);
|
||||
this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.пополнениеМагазинаToolStripMenuItem_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
|
||||
@ -159,12 +150,12 @@
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
|
||||
//
|
||||
// списаниеToolStripMenuItem
|
||||
// пополнениеМагазинаToolStripMenuItem
|
||||
//
|
||||
this.списаниеToolStripMenuItem.Name = "списаниеToolStripMenuItem";
|
||||
this.списаниеToolStripMenuItem.Size = new System.Drawing.Size(91, 24);
|
||||
this.списаниеToolStripMenuItem.Text = "Списание";
|
||||
this.списаниеToolStripMenuItem.Click += new System.EventHandler(this.списаниеToolStripMenuItem_Click);
|
||||
this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
|
||||
this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24);
|
||||
this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.пополнениеМагазинаToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
@ -204,6 +195,5 @@
|
||||
private Button buttonRef;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
|
||||
private ToolStripMenuItem списаниеToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -170,14 +170,5 @@ namespace Confectionery
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void списаниеToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSell));
|
||||
if (service is FormSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
120
Confectionery/Confectionery/FormSell.Designer.cs
generated
120
Confectionery/Confectionery/FormSell.Designer.cs
generated
@ -1,120 +0,0 @@
|
||||
namespace Confectionery
|
||||
{
|
||||
partial class FormSell
|
||||
{
|
||||
/// <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.comboBoxPastry = new System.Windows.Forms.ComboBox();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxPastry
|
||||
//
|
||||
this.comboBoxPastry.FormattingEnabled = true;
|
||||
this.comboBoxPastry.Location = new System.Drawing.Point(129, 6);
|
||||
this.comboBoxPastry.Name = "comboBoxPastry";
|
||||
this.comboBoxPastry.Size = new System.Drawing.Size(219, 28);
|
||||
this.comboBoxPastry.TabIndex = 22;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(254, 92);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 21;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Location = new System.Drawing.Point(142, 92);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.TabIndex = 20;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(129, 46);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.Size = new System.Drawing.Size(219, 27);
|
||||
this.textBoxSum.TabIndex = 19;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(12, 49);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(93, 20);
|
||||
this.label3.TabIndex = 18;
|
||||
this.label3.Text = "Количество:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 9);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(71, 20);
|
||||
this.label2.TabIndex = 17;
|
||||
this.label2.Text = "Изделие:";
|
||||
//
|
||||
// FormSell
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(360, 129);
|
||||
this.Controls.Add(this.comboBoxPastry);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Name = "FormSell";
|
||||
this.Text = "Продажа";
|
||||
this.Load += new System.EventHandler(this.FormSell_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxPastry;
|
||||
private Button buttonCancel;
|
||||
private Button buttonCreate;
|
||||
private TextBox textBoxSum;
|
||||
private Label label3;
|
||||
private Label label2;
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Confectionery
|
||||
{
|
||||
public partial class FormSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPastryLogic _logicP;
|
||||
private readonly IShopLogic _logicS;
|
||||
private List<PastryViewModel>? _listPastry;
|
||||
public FormSell(ILogger<FormSell> logger, IPastryLogic logicP, IShopLogic logicS)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicP = logicP;
|
||||
_logicS = logicS;
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxPastry.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (String.IsNullOrEmpty(textBoxSum.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле количество!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
int count = Convert.ToInt32(textBoxSum.Text);
|
||||
bool operationResult = _logicS.Sell(Convert.ToInt32(comboBoxPastry.SelectedValue), count);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании списания. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания поставки!");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделий для поставки");
|
||||
_listPastry = _logicP.ReadList(null);
|
||||
if (_listPastry != null)
|
||||
{
|
||||
comboBoxPastry.DisplayMember = "PastryName";
|
||||
comboBoxPastry.ValueMember = "Id";
|
||||
comboBoxPastry.DataSource = _listPastry;
|
||||
comboBoxPastry.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
30
Confectionery/Confectionery/FormShop.Designer.cs
generated
30
Confectionery/Confectionery/FormShop.Designer.cs
generated
@ -40,8 +40,6 @@
|
||||
this.PastryId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.PastryName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.textBoxCapacity = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -79,7 +77,7 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(376, 313);
|
||||
this.buttonCancel.Location = new System.Drawing.Point(376, 276);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
@ -89,7 +87,7 @@
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(276, 313);
|
||||
this.buttonSave.Location = new System.Drawing.Point(276, 276);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
@ -122,7 +120,7 @@
|
||||
this.PastryId,
|
||||
this.PastryName,
|
||||
this.Count});
|
||||
this.dataGridView.Location = new System.Drawing.Point(120, 142);
|
||||
this.dataGridView.Location = new System.Drawing.Point(120, 105);
|
||||
this.dataGridView.MultiSelect = false;
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersVisible = false;
|
||||
@ -157,29 +155,11 @@
|
||||
this.Count.ReadOnly = true;
|
||||
this.Count.Width = 125;
|
||||
//
|
||||
// textBoxCapacity
|
||||
//
|
||||
this.textBoxCapacity.Location = new System.Drawing.Point(120, 105);
|
||||
this.textBoxCapacity.Name = "textBoxCapacity";
|
||||
this.textBoxCapacity.Size = new System.Drawing.Size(350, 27);
|
||||
this.textBoxCapacity.TabIndex = 16;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(11, 108);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(103, 20);
|
||||
this.label3.TabIndex = 15;
|
||||
this.label3.Text = "Вместимость:";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(478, 354);
|
||||
this.Controls.Add(this.textBoxCapacity);
|
||||
this.Controls.Add(this.label3);
|
||||
this.ClientSize = new System.Drawing.Size(478, 317);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.openingDateTimePicker);
|
||||
@ -212,7 +192,5 @@
|
||||
private DataGridViewTextBoxColumn PastryId;
|
||||
private DataGridViewTextBoxColumn PastryName;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private TextBox textBoxCapacity;
|
||||
private Label label3;
|
||||
}
|
||||
}
|
@ -43,11 +43,6 @@ namespace Confectionery
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxCapacity.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните вместимость", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
@ -57,7 +52,6 @@ namespace Confectionery
|
||||
ShopName = textBoxName.Text,
|
||||
ShopAdress = textBoxAdress.Text,
|
||||
OpeningDate = openingDateTimePicker.Value.Date,
|
||||
PastryCapacity = Convert.ToInt32(textBoxCapacity.Text),
|
||||
ShopPastries = _shopPastries
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
@ -89,7 +83,6 @@ namespace Confectionery
|
||||
textBoxName.Text = view.ShopName;
|
||||
textBoxAdress.Text = view.ShopAdress;
|
||||
openingDateTimePicker.Value = view.OpeningDate;
|
||||
textBoxCapacity.Text = view.PastryCapacity.ToString();
|
||||
_shopPastries = view.ShopPastries;
|
||||
foreach (var pc in view.ShopPastries)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryFileImplement.Implements;
|
||||
using ConfectioneryListImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
@ -53,7 +53,6 @@ namespace Confectionery
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormDelivery>();
|
||||
services.AddTransient<FormSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,13 +17,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -56,7 +54,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!");
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Выдан;
|
||||
model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
@ -80,8 +77,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
|
||||
}
|
||||
bool hasFreeSpace = _shopStorage.Supply(element.PastryId, element.Count);
|
||||
if (!hasFreeSpace) throw new InvalidOperationException("В магазинах недостаточно места, чтобы вместить данный заказ!");
|
||||
model.Status = OrderStatus.Готов;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
|
@ -106,10 +106,6 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет адресса иагазина", nameof(model.ShopAdress));
|
||||
}
|
||||
if (model.PastryCapacity <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Вместимоcть должна быть больше 0");
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
@ -156,15 +152,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||
ShopName = element.ShopName,
|
||||
ShopAdress = element.ShopAdress,
|
||||
OpeningDate = element.OpeningDate,
|
||||
ShopPastries = element.ShopPastries,
|
||||
PastryCapacity = element.PastryCapacity
|
||||
ShopPastries = element.ShopPastries
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Sell(int pastryId, int count)
|
||||
{
|
||||
return _shopStorage.Sell(pastryId, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ namespace ConfectioneryContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public string ShopAdress { get; set; } = string.Empty;
|
||||
public int PastryCapacity { get; set; }
|
||||
public DateTime OpeningDate { get; set; }
|
||||
public Dictionary<int, (IPastryModel, int)> ShopPastries
|
||||
{
|
||||
|
@ -18,6 +18,5 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool DeliverPastryToShop(ShopBindingModel shopModel, IPastryModel pastryModel, int count);
|
||||
bool Sell(int pastryId, int count);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -18,7 +17,5 @@ namespace ConfectioneryContracts.StoragesContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool Supply(int pastryId, int count);
|
||||
bool Sell(int pastryId, int count);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ namespace ConfectioneryContracts.ViewModels
|
||||
public string ShopAdress { get; set; } = String.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
[DisplayName("Макс. вместимость")]
|
||||
public int PastryCapacity { get; set; }
|
||||
public Dictionary<int, (IPastryModel, int)> ShopPastries
|
||||
{
|
||||
get;
|
||||
|
@ -10,7 +10,6 @@ namespace ConfectioneryDataModels.Models
|
||||
{
|
||||
string ShopName { get; }
|
||||
string ShopAdress { get; }
|
||||
int PastryCapacity { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (IPastryModel, int)> ShopPastries { get; }
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ConfectioneryContracts\ConfectioneryContracts.csproj" />
|
||||
<ProjectReference Include="..\ConfectioneryDataModels\ConfectioneryDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,58 +0,0 @@
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string IngredientFileName = "Ingredient.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string PastryFileName = "Pastry.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Ingredient> Ingredients { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Pastry> Pastries { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public void SaveIngredients() => SaveData(Ingredients, IngredientFileName, "Ingredients", x => x.GetXElement);
|
||||
public void SavePastries() => SaveData(Pastries, PastryFileName, "Pastries", 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()
|
||||
{
|
||||
Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!;
|
||||
Pastries = LoadData(PastryFileName, "Pastry", x => Pastry.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.Implements
|
||||
{
|
||||
public class IngredientStorage : IIngredientStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public IngredientStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<IngredientViewModel> GetFullList()
|
||||
{
|
||||
return source.Ingredients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<IngredientViewModel> GetFilteredList(IngredientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.IngredientName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Ingredients
|
||||
.Where(x => x.IngredientName.Contains(model.IngredientName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public IngredientViewModel? GetElement(IngredientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Ingredients
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.IngredientName) && x.IngredientName == model.IngredientName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public IngredientViewModel? Insert(IngredientBindingModel model)
|
||||
{
|
||||
model.Id = source.Ingredients.Count > 0 ? source.Ingredients.Max(x => x.Id) + 1 : 1;
|
||||
var newIngredient = Ingredient.Create(model);
|
||||
if (newIngredient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Ingredients.Add(newIngredient);
|
||||
source.SaveIngredients();
|
||||
return newIngredient.GetViewModel;
|
||||
}
|
||||
public IngredientViewModel? Update(IngredientBindingModel model)
|
||||
{
|
||||
var ingredient = source.Ingredients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (ingredient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ingredient.Update(model);
|
||||
source.SaveIngredients();
|
||||
return ingredient.GetViewModel;
|
||||
}
|
||||
public IngredientViewModel? Delete(IngredientBindingModel model)
|
||||
{
|
||||
var element = source.Ingredients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Ingredients.Remove(element);
|
||||
source.SaveIngredients();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders
|
||||
.Select(x => AccessPastryStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => AccessPastryStorage(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return AccessPastryStorage(source.Orders
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel);
|
||||
}
|
||||
|
||||
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 AccessPastryStorage(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return AccessPastryStorage(order.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return AccessPastryStorage(element.GetViewModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel AccessPastryStorage(OrderViewModel model)
|
||||
{
|
||||
string? pastryName = source.Pastries.FirstOrDefault(x => x.Id == model?.PastryId)?.PastryName;
|
||||
if (pastryName != null) model.PastryName = pastryName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.Implements
|
||||
{
|
||||
public class PastryStorage : IPastryStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public PastryStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<PastryViewModel> GetFullList()
|
||||
{
|
||||
return source.Pastries
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PastryViewModel> GetFilteredList(PastrySearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PastryName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Pastries
|
||||
.Where(x => x.PastryName.Contains(model.PastryName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PastryViewModel? GetElement(PastrySearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Pastries
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PastryName) && x.PastryName == model.PastryName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PastryViewModel? Insert(PastryBindingModel model)
|
||||
{
|
||||
model.Id = source.Pastries.Count > 0 ? source.Pastries.Max(x => x.Id) + 1 : 1;
|
||||
var newPastry = Pastry.Create(model);
|
||||
if (newPastry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Pastries.Add(newPastry);
|
||||
source.SavePastries();
|
||||
return newPastry.GetViewModel;
|
||||
}
|
||||
|
||||
public PastryViewModel? Update(PastryBindingModel model)
|
||||
{
|
||||
var pastry = source.Pastries.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (pastry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
pastry.Update(model);
|
||||
source.SavePastries();
|
||||
return pastry.GetViewModel;
|
||||
}
|
||||
|
||||
public PastryViewModel? Delete(PastryBindingModel model)
|
||||
{
|
||||
var element = source.Pastries.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Pastries.Remove(element);
|
||||
source.SavePastries();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConfectioneryFileImplement.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 pastry = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (pastry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
pastry.Update(model);
|
||||
source.SaveShops();
|
||||
return pastry.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 Supply(int pastryId, int count)
|
||||
{
|
||||
int freeSpace = source.Shops.Select(x => x.PastryCapacity - x.ShopPastries.Select(y => y.Value.Item2).Sum()).Sum();
|
||||
if (freeSpace < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (Shop shop in source.Shops){
|
||||
int freeShopSpace = shop.PastryCapacity - shop.ShopPastries.Select(y => y.Value.Item2).Sum();
|
||||
if (freeShopSpace > 0)
|
||||
{
|
||||
if (freeShopSpace >= count)
|
||||
{
|
||||
if (shop.Pastries.ContainsKey(pastryId))
|
||||
{
|
||||
shop.Pastries[pastryId] += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Pastries.Add(pastryId, count);
|
||||
}
|
||||
shop.setShopPastriesNull();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
count -= freeShopSpace;
|
||||
if (shop.Pastries.TryGetValue(pastryId, out var pastryCount))
|
||||
{
|
||||
shop.Pastries[pastryId] = pastryCount + freeShopSpace;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Pastries.Add(pastryId, freeShopSpace);
|
||||
}
|
||||
shop.setShopPastriesNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Sell(int pastryId, int count)
|
||||
{
|
||||
int pastryCount = source.Shops.Select(x => x.ShopPastries.Select(y => y.Value).Where(y => y.Item1.Id == pastryId).Sum(y => y.Item2)).Sum();
|
||||
if (pastryCount < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (Shop shop in source.Shops)
|
||||
{
|
||||
int shopPastryCount = shop.ShopPastries.Select(x => x.Value).Where(x => x.Item1.Id == pastryId).Sum(x => x.Item2);
|
||||
if (count - shopPastryCount >= 0)
|
||||
{
|
||||
count -= shopPastryCount;
|
||||
shop.Pastries.Remove(pastryId);
|
||||
shop.setShopPastriesNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Pastries[pastryId] -= count;
|
||||
count = 0;
|
||||
shop.setShopPastriesNull();
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public class Ingredient : IIngredientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string IngredientName { get; private set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
public static Ingredient? Create(IngredientBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Ingredient()
|
||||
{
|
||||
Id = model.Id,
|
||||
IngredientName = model.IngredientName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Ingredient? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Ingredient()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
IngredientName = element.Element("IngredientName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
public void Update(IngredientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IngredientName = model.IngredientName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public IngredientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
IngredientName = IngredientName,
|
||||
Cost = Cost
|
||||
};
|
||||
public XElement GetXElement => new("Ingredient",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("IngredientName", IngredientName),
|
||||
new XElement("Cost", Cost.ToString()));
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Enums;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int PastryId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
public DateTime DateCreate { get; private set; }
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
PastryId = model.PastryId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PastryId = Convert.ToInt32(element.Element("PastryId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus) Convert.ToInt32(element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = Convert.ToDateTime(String.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PastryId = PastryId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PastryId", PastryId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", ((int)Status).ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString()));
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public class Pastry : IPastryModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string PastryName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, int> Ingredients { get; private set; } = new();
|
||||
private Dictionary<int, (IIngredientModel, int)>? _pastryIngredients = null;
|
||||
public Dictionary<int, (IIngredientModel, int)> PastryIngredients
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pastryIngredients == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_pastryIngredients = Ingredients.ToDictionary(x => x.Key, y => ((source.Ingredients.FirstOrDefault(z => z.Id == y.Key) as IIngredientModel)!, y.Value));
|
||||
}
|
||||
return _pastryIngredients;
|
||||
}
|
||||
}
|
||||
public static Pastry? Create(PastryBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pastry()
|
||||
{
|
||||
Id = model.Id,
|
||||
PastryName = model.PastryName,
|
||||
Price = model.Price,
|
||||
Ingredients = model.PastryIngredients.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Pastry? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pastry()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PastryName = element.Element("PastryName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Ingredients = element.Element("PastryIngredients")!.Elements("PastryIngredient").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(PastryBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PastryName = model.PastryName;
|
||||
Price = model.Price;
|
||||
Ingredients = model.PastryIngredients.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_pastryIngredients = null;
|
||||
}
|
||||
public PastryViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PastryName = PastryName,
|
||||
Price = Price,
|
||||
PastryIngredients = PastryIngredients
|
||||
};
|
||||
public XElement GetXElement => new("Pastry",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PastryName", PastryName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("PastryIngredients", Ingredients.Select(x => new XElement("PastryIngredient",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ConfectioneryFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string ShopAdress { get; private set; } = string.Empty;
|
||||
public int PastryCapacity { get; private set; }
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, int> Pastries { get; private set; } = new();
|
||||
private Dictionary<int, (IPastryModel, int)>? _shopPastries = null;
|
||||
public Dictionary<int, (IPastryModel, int)> ShopPastries
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopPastries == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopPastries = Pastries.ToDictionary(x => x.Key, y => ((source.Pastries.FirstOrDefault(z => z.Id == y.Key) as IPastryModel)!, y.Value));
|
||||
}
|
||||
return _shopPastries;
|
||||
}
|
||||
}
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
ShopAdress = model.ShopAdress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Pastries = model.ShopPastries.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||
PastryCapacity = model.PastryCapacity
|
||||
};
|
||||
}
|
||||
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,
|
||||
ShopAdress = element.Element("ShopAdress")!.Value,
|
||||
PastryCapacity = Convert.ToInt32(element.Element("PastryCapacity")!.Value),
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
Pastries = element.Element("ShopPastries")!.Elements("ShopPastry").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;
|
||||
ShopAdress = model.ShopAdress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
Pastries = model.ShopPastries.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopPastries = null;
|
||||
PastryCapacity = model.PastryCapacity;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
ShopAdress = ShopAdress,
|
||||
ShopPastries = ShopPastries,
|
||||
OpeningDate = OpeningDate,
|
||||
PastryCapacity = PastryCapacity,
|
||||
};
|
||||
internal void setShopPastriesNull()
|
||||
{
|
||||
_shopPastries = null;
|
||||
}
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("ShopAdress", ShopAdress),
|
||||
new XElement("PastryCapacity", PastryCapacity.ToString()),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopPastries", Pastries.Select(x => new XElement("ShopPastry",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContracts;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels.Models;
|
||||
using ConfectioneryListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -108,15 +107,5 @@ namespace ConfectioneryListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Supply(int pastryId, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Sell(int pastryId, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ namespace ConfectioneryListImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string ShopAdress { get; private set; } = string.Empty;
|
||||
public int PastryCapacity { get; private set; }
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, (IPastryModel, int)> ShopPastries { get; private set; } = new Dictionary<int, (IPastryModel, int)>();
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
@ -30,8 +29,7 @@ namespace ConfectioneryListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
ShopAdress = model.ShopAdress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
ShopPastries = model.ShopPastries,
|
||||
PastryCapacity = model.PastryCapacity
|
||||
ShopPastries = model.ShopPastries
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
@ -44,7 +42,6 @@ namespace ConfectioneryListImplement.Models
|
||||
ShopAdress = model.ShopAdress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
ShopPastries = model.ShopPastries;
|
||||
PastryCapacity = model.PastryCapacity;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
@ -52,8 +49,7 @@ namespace ConfectioneryListImplement.Models
|
||||
ShopName = ShopName,
|
||||
ShopAdress = ShopAdress,
|
||||
ShopPastries = ShopPastries,
|
||||
OpeningDate = OpeningDate,
|
||||
PastryCapacity = PastryCapacity,
|
||||
OpeningDate = OpeningDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user