Karamushko M.K lab2_hard #9
Pizzeria
Pizzeria.sln
Pizzeria
FormMain.Designer.csFormMain.csFormPizzaComponent.Designer.csFormSellPizza.Designer.csFormSellPizza.csFormSellPizza.resxFormShop.Designer.csFormShop.csPizzeria.csprojProgram.cs
PizzeriaBusinessLogic
PizzeriaContracts
BindingModels
BusinessLogicsContracts
StoragesContracts
ViewModels
PizzeriaDataModels/Models
PizzeriaListImplement/Models
PizzeriaShopFileImplement
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaContracts", "Pizzer
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{B55806ED-5FDE-4A9F-B500-1DFBE8E50491}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{138A775B-55CA-4120-918F-6093C0B2B241}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{138A775B-55CA-4120-918F-6093C0B2B241}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaFileImplement", "PizzeriaShopFileImplement\PizzeriaFileImplement.csproj", "{44B31B6F-2852-454B-9E7D-E965C9A348ED}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{138A775B-55CA-4120-918F-6093C0B2B241}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{138A775B-55CA-4120-918F-6093C0B2B241}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{138A775B-55CA-4120-918F-6093C0B2B241}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
14
Pizzeria/Pizzeria/FormMain.Designer.cs
generated
14
Pizzeria/Pizzeria/FormMain.Designer.cs
generated
@ -42,6 +42,7 @@
|
||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.button6 = new System.Windows.Forms.Button();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -174,11 +175,23 @@
|
||||
this.button6.UseVisualStyleBackColor = true;
|
||||
this.button6.Click += new System.EventHandler(this.ButtonRestore_Click);
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonSell.Location = new System.Drawing.Point(987, 328);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(209, 29);
|
||||
this.buttonSell.TabIndex = 13;
|
||||
this.buttonSell.Text = "Продать";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1233, 439);
|
||||
this.Controls.Add(this.buttonSell);
|
||||
this.Controls.Add(this.button6);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Controls.Add(this.button3);
|
||||
@ -214,5 +227,6 @@
|
||||
private ToolStripMenuItem изделияToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button button6;
|
||||
private Button buttonSell;
|
||||
}
|
||||
}
|
@ -159,6 +159,15 @@ namespace Pizzeria
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ButtonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza));
|
||||
if (service is FormSellPizza form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRestore_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopPizza));
|
||||
|
113
Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs
generated
113
Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs
generated
@ -28,84 +28,83 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
|
||||
this.SuspendLayout();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
textBoxCount = new TextBox();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
comboBoxComponent = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(249, 101);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 11;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
buttonCancel.Location = new Point(249, 101);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 11;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(135, 101);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSave.TabIndex = 10;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
buttonSave.Location = new Point(135, 101);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 10;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(118, 59);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(225, 27);
|
||||
this.textBoxCount.TabIndex = 9;
|
||||
textBoxCount.Location = new Point(118, 59);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(225, 27);
|
||||
textBoxCount.TabIndex = 9;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(23, 66);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(93, 20);
|
||||
this.label2.TabIndex = 7;
|
||||
this.label2.Text = "Количество:";
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(23, 66);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(93, 20);
|
||||
label2.TabIndex = 7;
|
||||
label2.Text = "Количество:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(23, 33);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(91, 20);
|
||||
this.label1.TabIndex = 6;
|
||||
this.label1.Text = "Компонент:";
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(23, 33);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(91, 20);
|
||||
label1.TabIndex = 6;
|
||||
label1.Text = "Компонент:";
|
||||
//
|
||||
// comboBoxComponent
|
||||
//
|
||||
this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxComponent.FormattingEnabled = true;
|
||||
this.comboBoxComponent.Location = new System.Drawing.Point(120, 25);
|
||||
this.comboBoxComponent.Name = "comboBoxComponent";
|
||||
this.comboBoxComponent.Size = new System.Drawing.Size(224, 28);
|
||||
this.comboBoxComponent.TabIndex = 12;
|
||||
comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxComponent.FormattingEnabled = true;
|
||||
comboBoxComponent.Location = new Point(120, 25);
|
||||
comboBoxComponent.Name = "comboBoxComponent";
|
||||
comboBoxComponent.Size = new Size(224, 28);
|
||||
comboBoxComponent.TabIndex = 12;
|
||||
//
|
||||
// FormPizzaComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(370, 153);
|
||||
this.Controls.Add(this.comboBoxComponent);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FormPizzaComponent";
|
||||
this.Text = "Компонент пиццы";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(370, 153);
|
||||
Controls.Add(comboBoxComponent);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormPizzaComponent";
|
||||
Text = "Компонент пиццы";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
118
Pizzeria/Pizzeria/FormSellPizza.Designer.cs
generated
Normal file
118
Pizzeria/Pizzeria/FormSellPizza.Designer.cs
generated
Normal file
@ -0,0 +1,118 @@
|
||||
namespace Pizzeria
|
||||
{
|
||||
partial class FormSellPizza
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
comboBoxPizza = new ComboBox();
|
||||
buttonCancel = new Button();
|
||||
buttonSell = new Button();
|
||||
textBoxCount = new TextBox();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxPizza
|
||||
//
|
||||
comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxPizza.FormattingEnabled = true;
|
||||
comboBoxPizza.Location = new Point(113, 25);
|
||||
comboBoxPizza.Name = "comboBoxPizza";
|
||||
comboBoxPizza.Size = new Size(224, 28);
|
||||
comboBoxPizza.TabIndex = 18;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(242, 101);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 17;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
buttonSell.Location = new Point(128, 101);
|
||||
buttonSell.Name = "buttonSell";
|
||||
buttonSell.Size = new Size(94, 29);
|
||||
buttonSell.TabIndex = 16;
|
||||
buttonSell.Text = "Продать";
|
||||
buttonSell.UseVisualStyleBackColor = true;
|
||||
buttonSell.Click += buttonSell_Click;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(111, 59);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(225, 27);
|
||||
textBoxCount.TabIndex = 15;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(16, 66);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(93, 20);
|
||||
label2.TabIndex = 14;
|
||||
label2.Text = "Количество:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(16, 33);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(55, 20);
|
||||
label1.TabIndex = 13;
|
||||
label1.Text = "Пицца";
|
||||
//
|
||||
// FormSellPizza
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(352, 145);
|
||||
Controls.Add(comboBoxPizza);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSell);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Name = "FormSellPizza";
|
||||
Text = "Продажа";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxPizza;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSell;
|
||||
private TextBox textBoxCount;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
}
|
||||
}
|
93
Pizzeria/Pizzeria/FormSellPizza.cs
Normal file
93
Pizzeria/Pizzeria/FormSellPizza.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormSellPizza : Form
|
||||
{
|
||||
private readonly List<PizzaViewModel>? _list;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxPizza.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxPizza.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
public IPizzaModel? PizzaModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _list)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public FormSellPizza(ILogger<FormSellPizza> logger, IPizzaLogic pizzaLogic, IShopLogic shopLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_shopLogic = shopLogic;
|
||||
_logger = logger;
|
||||
_list = pizzaLogic.ReadList(null);
|
||||
if (_list != null)
|
||||
{
|
||||
comboBoxPizza.DisplayMember = "PizzaName";
|
||||
comboBoxPizza.ValueMember = "Id";
|
||||
comboBoxPizza.DataSource = _list;
|
||||
comboBoxPizza.SelectedItem = null;
|
||||
}
|
||||
_shopLogic = shopLogic;
|
||||
}
|
||||
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxPizza.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_shopLogic.sellPizza(PizzaModel, Convert.ToInt32(textBoxCount.Text));
|
||||
MessageBox.Show("Продано успешно!");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show("Ошибка продажи. Слишком большое количество");
|
||||
_logger.LogWarning(ex, "Ошибка продажи");
|
||||
return;
|
||||
} catch(Exception err)
|
||||
{
|
||||
MessageBox.Show("Ошибка продажи.");
|
||||
_logger.LogError(err, "Ошибка продажи");
|
||||
return;
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Pizzeria/Pizzeria/FormSellPizza.resx
Normal file
60
Pizzeria/Pizzeria/FormSellPizza.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
31
Pizzeria/Pizzeria/FormShop.Designer.cs
generated
31
Pizzeria/Pizzeria/FormShop.Designer.cs
generated
@ -41,6 +41,8 @@
|
||||
this.labelShop = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.textBoxCapacity = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -103,7 +105,7 @@
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(664, 296);
|
||||
this.dataGridView.Size = new System.Drawing.Size(870, 296);
|
||||
this.dataGridView.TabIndex = 21;
|
||||
//
|
||||
// ColumnID
|
||||
@ -147,7 +149,7 @@
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonSave.Location = new System.Drawing.Point(415, 383);
|
||||
this.buttonSave.Location = new System.Drawing.Point(621, 383);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(137, 30);
|
||||
@ -159,7 +161,7 @@
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonCancel.Location = new System.Drawing.Point(558, 383);
|
||||
this.buttonCancel.Location = new System.Drawing.Point(764, 383);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(118, 30);
|
||||
@ -168,11 +170,30 @@
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// textBoxCapacity
|
||||
//
|
||||
this.textBoxCapacity.Location = new System.Drawing.Point(696, 36);
|
||||
this.textBoxCapacity.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxCapacity.Name = "textBoxCapacity";
|
||||
this.textBoxCapacity.Size = new System.Drawing.Size(186, 27);
|
||||
this.textBoxCapacity.TabIndex = 29;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(696, 12);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(100, 20);
|
||||
this.label1.TabIndex = 30;
|
||||
this.label1.Text = "Вместимость";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(704, 426);
|
||||
this.ClientSize = new System.Drawing.Size(910, 426);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.textBoxCapacity);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.dateTimePicker);
|
||||
@ -206,5 +227,7 @@
|
||||
private Label labelShop;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private TextBox textBoxCapacity;
|
||||
private Label label1;
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ namespace Pizzeria
|
||||
textBoxName.Text = view.ShopName;
|
||||
textBoxAddres.Text = view.Addres.ToString();
|
||||
dateTimePicker.Text = view.OpenTime.ToString();
|
||||
textBoxCapacity.Text = view.Capacity.ToString();
|
||||
_shopPizzas = view.ShopPizzas ?? new Dictionary<int, (IPizzaModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
@ -90,6 +91,7 @@ namespace Pizzeria
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxName.Text,
|
||||
Addres = textBoxAddres.Text,
|
||||
Capacity = Convert.ToInt32(textBoxCapacity.Text),
|
||||
OpenTime = dateTimePicker.Value.Date,
|
||||
ShopPizzas = _shopPizzas
|
||||
};
|
||||
|
@ -18,7 +18,7 @@
|
||||
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaListImplement\PizzeriaListImplement.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaShopFileImplement\PizzeriaFileImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
using PizzeriaBusinessLogic;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaListImplement.Implements;
|
||||
using PizzeriaFileImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
@ -53,6 +53,7 @@ namespace Pizzeria
|
||||
services.AddTransient<FormShopPizza>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormPizzaComponent>();
|
||||
services.AddTransient<FormSellPizza>();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,10 +12,14 @@ namespace PizzeriaBusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IPizzaStorage _pizzaStorage;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IPizzaStorage pizzaStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_pizzaStorage = pizzaStorage;
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
@ -66,6 +70,17 @@ namespace PizzeriaBusinessLogic
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
|
||||
if (newStatus == OrderStatus.Готов)
|
||||
{
|
||||
var pizza = _pizzaStorage.GetElement(new PizzaSearchModel { Id = model.PizzaId });
|
||||
|
||||
if(!TryRestoreShops(pizza, model.Count))
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Incorrect count.");
|
||||
throw new ArgumentException("Количество изделий слишком велико");
|
||||
}
|
||||
}
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
@ -109,5 +124,38 @@ namespace PizzeriaBusinessLogic
|
||||
_logger.LogInformation("Sum:{ Sum}. Id: { Id}", model.Sum, model.Id);
|
||||
}
|
||||
|
||||
private bool TryRestoreShops(IPizzaModel pizza, int count)
|
||||
{
|
||||
int freePlaces = 0;
|
||||
|
||||
_shopLogic.ReadList(null).ForEach(x =>
|
||||
{
|
||||
int currentFreePlaces = x.Capacity;
|
||||
foreach (var pair in x.ShopPizzas)
|
||||
{
|
||||
currentFreePlaces -= pair.Value.Item2;
|
||||
}
|
||||
freePlaces += currentFreePlaces;
|
||||
});
|
||||
|
||||
if (freePlaces < count) return false;
|
||||
|
||||
_shopLogic.ReadList(null).ForEach(x =>
|
||||
{
|
||||
if (count <= 0) return;
|
||||
|
||||
int currentFreePlaces = x.Capacity;
|
||||
foreach (var elem in x.ShopPizzas)
|
||||
{
|
||||
currentFreePlaces -= elem.Value.Item2;
|
||||
}
|
||||
|
||||
_shopLogic.AddPizza(new ShopSearchModel { Id = x.Id }, pizza, Math.Min(currentFreePlaces, count));
|
||||
count -= currentFreePlaces;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -121,9 +121,17 @@ namespace PizzeriaBusinessLogic
|
||||
|
||||
if(model.ShopPizzas.TryGetValue(pizza.Id, out var pair))
|
||||
{
|
||||
if(model.Capacity - pair.Item2 < count)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия слишком велико");
|
||||
}
|
||||
model.ShopPizzas[pizza.Id] = (pair.Item1, pair.Item2 + count);
|
||||
} else
|
||||
{
|
||||
if (model.Capacity < count)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия слишком велико");
|
||||
}
|
||||
model.ShopPizzas.Add(pizza.Id, (pizza, count));
|
||||
}
|
||||
|
||||
@ -131,11 +139,25 @@ namespace PizzeriaBusinessLogic
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
OpenTime = model.OpenTime,
|
||||
Addres = model.Addres,
|
||||
Capacity = model.Capacity,
|
||||
ShopPizzas = model.ShopPizzas,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool sellPizza(IPizzaModel pizza, int count)
|
||||
{
|
||||
bool result = _shopStorage.TrySellPizza(pizza, count);
|
||||
|
||||
if(!result)
|
||||
{
|
||||
throw new ArgumentException("Количество продаваемого изделия слишком велико");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace PizzeriaContracts.BindingModels
|
||||
public string Addres { get; set; } = String.Empty;
|
||||
|
||||
public DateTime OpenTime { get; set; }
|
||||
public int Capacity { get; set; }
|
||||
|
||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ namespace PizzeriaContracts.BusinessLogicsContracts
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
bool AddPizza(ShopSearchModel shop, IPizzaModel pizza, int count);
|
||||
bool sellPizza(IPizzaModel pizza, int count);
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaContracts.StoragesContracts
|
||||
{
|
||||
@ -9,6 +10,7 @@ namespace PizzeriaContracts.StoragesContracts
|
||||
List<ShopViewModel> GetFullList();
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
bool TrySellPizza(IPizzaModel pizza, int count);
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
|
@ -13,7 +13,8 @@ namespace PizzeriaContracts.ViewModels
|
||||
public string Addres { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpenTime { get; set; }
|
||||
|
||||
[DisplayName("Вместимость")]
|
||||
public int Capacity { get; set; }
|
||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
get;
|
||||
|
@ -12,6 +12,7 @@ namespace PizzeriaDataModels
|
||||
string Addres { get; }
|
||||
DateTime OpenTime { get; }
|
||||
|
||||
int Capacity { get; }
|
||||
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ namespace PizzeriaListImplement.Models
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string Addres { get; private set; } = string.Empty;
|
||||
public DateTime OpenTime { get; private set; } = DateTime.Now;
|
||||
public int Capacity { get; private set; }
|
||||
|
||||
|
||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
@ -29,6 +31,7 @@ namespace PizzeriaListImplement.Models
|
||||
ShopName = model.ShopName,
|
||||
Addres = model.Addres,
|
||||
OpenTime = model.OpenTime,
|
||||
Capacity = model.Capacity,
|
||||
ShopPizzas = model.ShopPizzas
|
||||
};
|
||||
}
|
||||
@ -49,8 +52,10 @@ namespace PizzeriaListImplement.Models
|
||||
ShopName = ShopName,
|
||||
Addres = Addres,
|
||||
OpenTime = OpenTime,
|
||||
Capacity = Capacity,
|
||||
ShopPizzas = ShopPizzas
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
53
Pizzeria/PizzeriaShopFileImplement/DataFileSingleton.cs
Normal file
53
Pizzeria/PizzeriaShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using PizzeriaFileImplement.models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string PizzaFileName = "Pizza.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Pizza> Pizzas { 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 SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaFileImplement.models;
|
||||
|
||||
|
||||
namespace PizzeriaFileImplement.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaFileImplement.models;
|
||||
|
||||
|
||||
namespace PizzeriaFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => (model.Id.HasValue && x.Id == model.Id))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
return 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 newOrder.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Orders.Remove(element);
|
||||
source.SaveOrders();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaFileImplement.models;
|
||||
|
||||
|
||||
namespace PizzeriaFileImplement.Implements
|
||||
{
|
||||
public class PizzaStorage : IPizzaStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public PizzaStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<PizzaViewModel> GetFullList()
|
||||
{
|
||||
return source.Pizzas
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PizzaName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Pizzas
|
||||
.Where(x => x.PizzaName.Contains(model.PizzaName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public PizzaViewModel? GetElement(PizzaSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Pizzas
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.PizzaName) && x.PizzaName == model.PizzaName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public PizzaViewModel? Insert(PizzaBindingModel model)
|
||||
{
|
||||
model.Id = source.Pizzas.Count > 0 ? source.Pizzas.Max(x => x.Id) + 1 : 1;
|
||||
var newPizza = Pizza.Create(model);
|
||||
if (newPizza == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Pizzas.Add(newPizza);
|
||||
source.SavePizzas();
|
||||
return newPizza.GetViewModel;
|
||||
}
|
||||
public PizzaViewModel? Update(PizzaBindingModel model)
|
||||
{
|
||||
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (pizza == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
pizza.Update(model);
|
||||
source.SavePizzas();
|
||||
return pizza.GetViewModel;
|
||||
}
|
||||
public PizzaViewModel? Delete(PizzaBindingModel model)
|
||||
{
|
||||
var element = source.Pizzas.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Pizzas.Remove(element);
|
||||
source.SavePizzas();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
124
Pizzeria/PizzeriaShopFileImplement/Implements/ShopStorage.cs
Normal file
124
Pizzeria/PizzeriaShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using PizzeriaFileImplement.models;
|
||||
|
||||
namespace PizzeriaFileImplement.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 bool TrySellPizza(IPizzaModel pizza, int count)
|
||||
{
|
||||
int hasCount = 0;
|
||||
|
||||
source.Shops.ForEach(x =>
|
||||
{
|
||||
if (x.ShopPizzas.TryGetValue(pizza.Id, out var pair))
|
||||
{
|
||||
hasCount += pair.Item2;
|
||||
}
|
||||
});
|
||||
|
||||
if (hasCount < count) return false;
|
||||
|
||||
source.Shops.ForEach(x =>
|
||||
{
|
||||
if (x.ShopPizzas.TryGetValue(pizza.Id, out var pair))
|
||||
{
|
||||
if(count >= pair.Item2)
|
||||
{
|
||||
count -= pair.Item2;
|
||||
x.ShopPizzas[pizza.Id] = (pizza, 0);
|
||||
} else
|
||||
{
|
||||
x.ShopPizzas[pizza.Id] = (pizza, pair.Item2 - count);
|
||||
count = 0;
|
||||
}
|
||||
|
||||
x.Update(new ShopBindingModel
|
||||
{
|
||||
Id = x.Id,
|
||||
Addres = x.Addres,
|
||||
Capacity = x.Capacity,
|
||||
OpenTime = x.OpenTime,
|
||||
ShopName = x.ShopName,
|
||||
ShopPizzas = x.ShopPizzas
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
source.SaveShops();
|
||||
return true;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
59
Pizzeria/PizzeriaShopFileImplement/models/Component.cs
Normal file
59
Pizzeria/PizzeriaShopFileImplement/models/Component.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement.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()));
|
||||
}
|
||||
}
|
105
Pizzeria/PizzeriaShopFileImplement/models/Order.cs
Normal file
105
Pizzeria/PizzeriaShopFileImplement/models/Order.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement.models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int PizzaId { get; private set; }
|
||||
|
||||
public string PizzaName
|
||||
{
|
||||
get
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
return source.Pizzas.FirstOrDefault(x => x.Id == PizzaId).PizzaName;
|
||||
}
|
||||
}
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
PizzaId = model.PizzaId,
|
||||
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),
|
||||
PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToInt32(element.Element("Sum")!.Value),
|
||||
Status = Enum.Parse<OrderStatus>(element.Element("Status")!.Value),
|
||||
DateCreate = DateTime.Parse(element.Element("DateCreate")!.Value),
|
||||
DateImplement = !string.IsNullOrEmpty(element.Element("DateImplement")!.Value.ToString()) ?
|
||||
DateTime.Parse(element.Element("DateImplement")!.Value) : null,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PizzaId = model.PizzaId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PizzaId = PizzaId,
|
||||
PizzaName = PizzaName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PizzaId", PizzaId),
|
||||
new XElement("Count", Count),
|
||||
new XElement("Sum", Sum),
|
||||
new XElement("Status", Status),
|
||||
new XElement("DateCreate", DateCreate),
|
||||
new XElement("DateImplement", DateImplement));
|
||||
}
|
||||
}
|
89
Pizzeria/PizzeriaShopFileImplement/models/Pizza.cs
Normal file
89
Pizzeria/PizzeriaShopFileImplement/models/Pizza.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement.models
|
||||
{
|
||||
public class Pizza : IPizzaModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string PizzaName { 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)>? _pizzaComponents = null;
|
||||
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pizzaComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_pizzaComponents = Components.ToDictionary(x => x.Key, y =>
|
||||
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
|
||||
y.Value));
|
||||
}
|
||||
return _pizzaComponents;
|
||||
}
|
||||
}
|
||||
public static Pizza? Create(PizzaBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pizza()
|
||||
{
|
||||
Id = model.Id,
|
||||
PizzaName = model.PizzaName,
|
||||
Price = model.Price,
|
||||
Components = model.PizzaComponents.ToDictionary(x => x.Key, x
|
||||
=> x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Pizza? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pizza()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
PizzaName = element.Element("PizzaName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components = element.Element("PizzaComponents")!.Elements("PizzaComponent")
|
||||
.ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(PizzaBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PizzaName = model.PizzaName;
|
||||
Price = model.Price;
|
||||
Components = model.PizzaComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_pizzaComponents = null;
|
||||
}
|
||||
public PizzaViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PizzaName = PizzaName,
|
||||
Price = Price,
|
||||
PizzaComponents = PizzaComponents
|
||||
};
|
||||
public XElement GetXElement => new("Pizza",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("PizzaName", PizzaName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("PizzaComponents", Components.Select(x =>
|
||||
new XElement("PizzaComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
102
Pizzeria/PizzeriaShopFileImplement/models/Shop.cs
Normal file
102
Pizzeria/PizzeriaShopFileImplement/models/Shop.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement.models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public string Addres { get; set; } = string.Empty;
|
||||
public DateTime OpenTime { get; set; }
|
||||
public int Capacity { get; set; }
|
||||
public Dictionary<int, int> Pizzas { get; private set; } = new();
|
||||
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
|
||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopPizzas == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopPizzas = Pizzas.ToDictionary(x => x.Key, y =>
|
||||
((source.Pizzas.FirstOrDefault(z => z.Id == y.Key) as IPizzaModel)!,
|
||||
y.Value));
|
||||
}
|
||||
return _shopPizzas;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Addres = model.Addres,
|
||||
OpenTime = model.OpenTime,
|
||||
Capacity = model.Capacity,
|
||||
Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
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,
|
||||
Addres = element.Element("Addres")!.Value,
|
||||
OpenTime = DateTime.Parse(element.Element("OpenTime")!.Value),
|
||||
Capacity = Convert.ToInt32(element.Element("Capacity")!.Value),
|
||||
Pizzas = element.Element("ShopPizzas")!.Elements("ShopPizza")
|
||||
.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;
|
||||
Addres = model.Addres;
|
||||
OpenTime = model.OpenTime;
|
||||
Capacity = model.Capacity;
|
||||
Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopPizzas = null;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Addres = Addres,
|
||||
OpenTime = OpenTime,
|
||||
Capacity = Capacity,
|
||||
ShopPizzas = ShopPizzas
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Addres", Addres),
|
||||
new XElement("OpenTime", OpenTime),
|
||||
new XElement("Capacity", Capacity),
|
||||
new XElement("ShopPizzas", Pizzas.Select(x =>
|
||||
new XElement("ShopPizza",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user