Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f80eb3c08c | ||
|
|
205cc3df40 | ||
|
|
d4b269564b | ||
|
|
f1ff090bc1 | ||
|
|
d1b3d29ab0 | ||
|
|
55dcc5a9a7 | ||
|
|
1e9c5a2ae1 | ||
|
|
c851b67dc3 | ||
|
|
dbeb844986 | ||
|
|
abc25205ce | ||
|
|
ba499ea9bf | ||
|
|
c78f16557f |
44
Pizzeria/Pizzeria/FormMain.Designer.cs
generated
44
Pizzeria/Pizzeria/FormMain.Designer.cs
generated
@@ -40,6 +40,9 @@
|
||||
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.button6 = new System.Windows.Forms.Button();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@@ -134,7 +137,8 @@
|
||||
//
|
||||
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.компонентыToolStripMenuItem,
|
||||
this.изделияToolStripMenuItem});
|
||||
this.изделияToolStripMenuItem,
|
||||
this.магазиныToolStripMenuItem});
|
||||
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
|
||||
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||
@@ -142,22 +146,53 @@
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||
//
|
||||
// изделияToolStripMenuItem
|
||||
//
|
||||
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
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, 26);
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
//
|
||||
// button6
|
||||
//
|
||||
this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button6.Location = new System.Drawing.Point(987, 284);
|
||||
this.button6.Name = "button6";
|
||||
this.button6.Size = new System.Drawing.Size(209, 29);
|
||||
this.button6.TabIndex = 12;
|
||||
this.button6.Text = "Пополнить магазин";
|
||||
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);
|
||||
this.Controls.Add(this.button5);
|
||||
@@ -190,5 +225,8 @@
|
||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||
private ToolStripMenuItem изделияToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button button6;
|
||||
private Button buttonSell;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,14 @@ namespace Pizzeria
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||
if (service is FormShops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
@@ -151,5 +159,22 @@ 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));
|
||||
if (service is FormShopPizza form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace Pizzeria
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
if (_pizzaComponents.ContainsKey(form.Id))
|
||||
{
|
||||
_pizzaComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
|
||||
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>
|
||||
233
Pizzeria/Pizzeria/FormShop.Designer.cs
generated
Normal file
233
Pizzeria/Pizzeria/FormShop.Designer.cs
generated
Normal file
@@ -0,0 +1,233 @@
|
||||
namespace Pizzeria
|
||||
{
|
||||
partial class FormShop
|
||||
{
|
||||
/// <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.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxAddres = new System.Windows.Forms.TextBox();
|
||||
this.labelTime = new System.Windows.Forms.Label();
|
||||
this.labelAddress = new System.Windows.Forms.Label();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Цена = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
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();
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
this.dateTimePicker.Location = new System.Drawing.Point(439, 36);
|
||||
this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.dateTimePicker.Name = "dateTimePicker";
|
||||
this.dateTimePicker.Size = new System.Drawing.Size(236, 27);
|
||||
this.dateTimePicker.TabIndex = 26;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(12, 36);
|
||||
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(161, 27);
|
||||
this.textBoxName.TabIndex = 25;
|
||||
//
|
||||
// textBoxAddres
|
||||
//
|
||||
this.textBoxAddres.Location = new System.Drawing.Point(180, 36);
|
||||
this.textBoxAddres.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxAddres.Name = "textBoxAddres";
|
||||
this.textBoxAddres.Size = new System.Drawing.Size(252, 27);
|
||||
this.textBoxAddres.TabIndex = 24;
|
||||
//
|
||||
// labelTime
|
||||
//
|
||||
this.labelTime.AutoSize = true;
|
||||
this.labelTime.Location = new System.Drawing.Point(439, 12);
|
||||
this.labelTime.Name = "labelTime";
|
||||
this.labelTime.Size = new System.Drawing.Size(110, 20);
|
||||
this.labelTime.TabIndex = 23;
|
||||
this.labelTime.Text = "Дата открытия";
|
||||
//
|
||||
// labelAddress
|
||||
//
|
||||
this.labelAddress.AutoSize = true;
|
||||
this.labelAddress.Location = new System.Drawing.Point(180, 12);
|
||||
this.labelAddress.Name = "labelAddress";
|
||||
this.labelAddress.Size = new System.Drawing.Size(51, 20);
|
||||
this.labelAddress.TabIndex = 22;
|
||||
this.labelAddress.Text = "Адрес";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ColumnID,
|
||||
this.ColumnManufactureName,
|
||||
this.Цена,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Location = new System.Drawing.Point(12, 74);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(870, 296);
|
||||
this.dataGridView.TabIndex = 21;
|
||||
//
|
||||
// ColumnID
|
||||
//
|
||||
this.ColumnID.HeaderText = "ID";
|
||||
this.ColumnID.MinimumWidth = 8;
|
||||
this.ColumnID.Name = "ColumnID";
|
||||
this.ColumnID.Visible = false;
|
||||
this.ColumnID.Width = 150;
|
||||
//
|
||||
// ColumnManufactureName
|
||||
//
|
||||
this.ColumnManufactureName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.ColumnManufactureName.HeaderText = "Название пиццы";
|
||||
this.ColumnManufactureName.MinimumWidth = 8;
|
||||
this.ColumnManufactureName.Name = "ColumnManufactureName";
|
||||
//
|
||||
// Цена
|
||||
//
|
||||
this.Цена.HeaderText = "Цена";
|
||||
this.Цена.MinimumWidth = 6;
|
||||
this.Цена.Name = "Цена";
|
||||
this.Цена.Width = 125;
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
this.ColumnCount.HeaderText = "Количество";
|
||||
this.ColumnCount.MinimumWidth = 8;
|
||||
this.ColumnCount.Name = "ColumnCount";
|
||||
this.ColumnCount.Width = 150;
|
||||
//
|
||||
// labelShop
|
||||
//
|
||||
this.labelShop.AutoSize = true;
|
||||
this.labelShop.Location = new System.Drawing.Point(12, 12);
|
||||
this.labelShop.Name = "labelShop";
|
||||
this.labelShop.Size = new System.Drawing.Size(69, 20);
|
||||
this.labelShop.TabIndex = 20;
|
||||
this.labelShop.Text = "Магазин";
|
||||
//
|
||||
// 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(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);
|
||||
this.buttonSave.TabIndex = 28;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// 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(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);
|
||||
this.buttonCancel.TabIndex = 27;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
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(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);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.textBoxAddres);
|
||||
this.Controls.Add(this.labelTime);
|
||||
this.Controls.Add(this.labelAddress);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.labelShop);
|
||||
this.Name = "FormShop";
|
||||
this.Text = "FormShop";
|
||||
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePicker;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxAddres;
|
||||
private Label labelTime;
|
||||
private Label labelAddress;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridViewTextBoxColumn ColumnID;
|
||||
private DataGridViewTextBoxColumn ColumnManufactureName;
|
||||
private DataGridViewTextBoxColumn Цена;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private Label labelShop;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private TextBox textBoxCapacity;
|
||||
private Label label1;
|
||||
}
|
||||
}
|
||||
119
Pizzeria/Pizzeria/FormShop.cs
Normal file
119
Pizzeria/Pizzeria/FormShop.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaDataModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IPizzaModel, int)> _shopPizzas;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_shopPizzas = new Dictionary<int, (IPizzaModel, int)>();
|
||||
}
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонент магазина");
|
||||
try
|
||||
{
|
||||
if (_shopPizzas != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _shopPizzas)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.PizzaName , pc.Value.Item1.Price, pc.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxAddres.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxName.Text,
|
||||
Addres = textBoxAddres.Text,
|
||||
Capacity = Convert.ToInt32(textBoxCapacity.Text),
|
||||
OpenTime = dateTimePicker.Value.Date,
|
||||
ShopPizzas = _shopPizzas
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
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 ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Pizzeria/Pizzeria/FormShop.resx
Normal file
63
Pizzeria/Pizzeria/FormShop.resx
Normal file
@@ -0,0 +1,63 @@
|
||||
<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>
|
||||
<metadata name="Цена.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
||||
144
Pizzeria/Pizzeria/FormShopPizza.Designer.cs
generated
Normal file
144
Pizzeria/Pizzeria/FormShopPizza.Designer.cs
generated
Normal file
@@ -0,0 +1,144 @@
|
||||
namespace Pizzeria
|
||||
{
|
||||
partial class FormShopPizza
|
||||
{
|
||||
/// <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.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.comboBoxPizza = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxShop
|
||||
//
|
||||
this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxShop.FormattingEnabled = true;
|
||||
this.comboBoxShop.Location = new System.Drawing.Point(116, 24);
|
||||
this.comboBoxShop.Name = "comboBoxShop";
|
||||
this.comboBoxShop.Size = new System.Drawing.Size(224, 28);
|
||||
this.comboBoxShop.TabIndex = 16;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(246, 136);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 15;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(132, 136);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSave.TabIndex = 14;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(116, 92);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(225, 27);
|
||||
this.textBoxCount.TabIndex = 13;
|
||||
//
|
||||
// comboBoxPizza
|
||||
//
|
||||
this.comboBoxPizza.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxPizza.FormattingEnabled = true;
|
||||
this.comboBoxPizza.Location = new System.Drawing.Point(116, 58);
|
||||
this.comboBoxPizza.Name = "comboBoxPizza";
|
||||
this.comboBoxPizza.Size = new System.Drawing.Size(224, 28);
|
||||
this.comboBoxPizza.TabIndex = 17;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(23, 27);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(72, 20);
|
||||
this.label1.TabIndex = 18;
|
||||
this.label1.Text = "Магазин:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(23, 61);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(58, 20);
|
||||
this.label2.TabIndex = 19;
|
||||
this.label2.Text = "Пицца:";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(23, 95);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(93, 20);
|
||||
this.label3.TabIndex = 20;
|
||||
this.label3.Text = "Количество:";
|
||||
//
|
||||
// FormShopPizza
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(371, 194);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.comboBoxPizza);
|
||||
this.Controls.Add(this.comboBoxShop);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Name = "FormShopPizza";
|
||||
this.Text = "FormShopPizza";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxShop;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private TextBox textBoxCount;
|
||||
private ComboBox comboBoxPizza;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
}
|
||||
}
|
||||
109
Pizzeria/Pizzeria/FormShopPizza.cs
Normal file
109
Pizzeria/Pizzeria/FormShopPizza.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormShopPizza : Form
|
||||
{
|
||||
ILogger<FormShopPizza> _logger;
|
||||
IShopLogic _shopLogic;
|
||||
IPizzaLogic _pizzaLogic;
|
||||
List<PizzaViewModel> _listPizza;
|
||||
|
||||
public int ShopId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxShop.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxShop.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public FormShopPizza(ILogger<FormShopPizza> logger, IShopLogic shopLigic, IPizzaLogic pizzaLigic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = logger;
|
||||
_shopLogic = shopLigic;
|
||||
_pizzaLogic = pizzaLigic;
|
||||
|
||||
List<ShopViewModel> _listShop = shopLigic.ReadList(null);
|
||||
List<PizzaViewModel> _listPizza = pizzaLigic.ReadList(null);
|
||||
if (_listShop != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "ShopName";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = _listShop;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
}
|
||||
if (_listPizza != null)
|
||||
{
|
||||
comboBoxPizza.DisplayMember = "PizzaName";
|
||||
comboBoxPizza.ValueMember = "Id";
|
||||
comboBoxPizza.DataSource = _listPizza;
|
||||
comboBoxPizza.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxShop.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxPizza.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
|
||||
bool res = _shopLogic.AddPizza(
|
||||
new() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
|
||||
_pizzaLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxPizza.SelectedValue) }),
|
||||
count
|
||||
);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
||||
}
|
||||
|
||||
MessageBox.Show("Пополнение прошло успешно");
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
MessageBox.Show("Ошибка пополнения");
|
||||
_logger.LogError(err, "Ошибка пополнения");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Pizzeria/Pizzeria/FormShopPizza.resx
Normal file
60
Pizzeria/Pizzeria/FormShopPizza.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>
|
||||
123
Pizzeria/Pizzeria/FormShops.Designer.cs
generated
Normal file
123
Pizzeria/Pizzeria/FormShops.Designer.cs
generated
Normal file
@@ -0,0 +1,123 @@
|
||||
namespace Pizzeria
|
||||
{
|
||||
partial class FormShops
|
||||
{
|
||||
/// <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.button5 = new System.Windows.Forms.Button();
|
||||
this.button4 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// button5
|
||||
//
|
||||
this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button5.Location = new System.Drawing.Point(603, 118);
|
||||
this.button5.Name = "button5";
|
||||
this.button5.Size = new System.Drawing.Size(94, 29);
|
||||
this.button5.TabIndex = 15;
|
||||
this.button5.Text = "Удалить";
|
||||
this.button5.UseVisualStyleBackColor = true;
|
||||
this.button5.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||
//
|
||||
// button4
|
||||
//
|
||||
this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button4.Location = new System.Drawing.Point(603, 165);
|
||||
this.button4.Name = "button4";
|
||||
this.button4.Size = new System.Drawing.Size(94, 29);
|
||||
this.button4.TabIndex = 14;
|
||||
this.button4.Text = "Обновить";
|
||||
this.button4.UseVisualStyleBackColor = true;
|
||||
this.button4.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button2.Location = new System.Drawing.Point(603, 71);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(94, 29);
|
||||
this.button2.TabIndex = 13;
|
||||
this.button2.Text = "Изменить";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button1.Location = new System.Drawing.Point(603, 24);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(94, 29);
|
||||
this.button1.TabIndex = 12;
|
||||
this.button1.Text = "Добавить";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(-2, 1);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(579, 447);
|
||||
this.dataGridView.TabIndex = 11;
|
||||
//
|
||||
// FormShops
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(709, 450);
|
||||
this.Controls.Add(this.button5);
|
||||
this.Controls.Add(this.button4);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormShops";
|
||||
this.Text = "FormShops";
|
||||
this.Load += new System.EventHandler(this.FormShops_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button button5;
|
||||
private Button button4;
|
||||
private Button button2;
|
||||
private Button button1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
||||
101
Pizzeria/Pizzeria/FormShops.cs
Normal file
101
Pizzeria/Pizzeria/FormShops.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormShops : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormShops_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ShopPizzas"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
if (service is FormShop form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление магазина");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ShopBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRef_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Pizzeria/Pizzeria/FormShops.resx
Normal file
60
Pizzeria/Pizzeria/FormShops.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>
|
||||
@@ -22,7 +22,6 @@
|
||||
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaShopFileImplement\PizzeriaFileImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -37,9 +37,11 @@ namespace Pizzeria
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
@@ -47,7 +49,11 @@ namespace Pizzeria
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormPizza>();
|
||||
services.AddTransient<FormPizzas>();
|
||||
services.AddTransient<FormShop>();
|
||||
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.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
163
Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs
Normal file
163
Pizzeria/PizzeriaBusinessLogic/ShopLogic.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaBusinessLogic
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}. Id:{ Id}", model?.ShopName, model?.Id);
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{ Id}", model.ShopName, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Addres))
|
||||
{
|
||||
throw new ArgumentNullException("Нет адреса магазина", nameof(model.ShopName));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}. Addres:{Addres}. Id: {Id}", model.ShopName, model.Addres, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddPizza(ShopSearchModel shop, IPizzaModel pizza, int count)
|
||||
{
|
||||
if (shop == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shop));
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
ShopViewModel model = _shopStorage.GetElement(shop);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs
Normal file
21
Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaContracts.BindingModels
|
||||
{
|
||||
public class ShopBindingModel : 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, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
14
Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs
Normal file
14
Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.SearchModels
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ShopName { get; set; }
|
||||
}
|
||||
}
|
||||
18
Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs
Normal file
18
Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
24
Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs
Normal file
24
Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название магазина")]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
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;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
18
Pizzeria/PizzeriaDataModels/Models/IShopModel.cs
Normal file
18
Pizzeria/PizzeriaDataModels/Models/IShopModel.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaDataModels
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string ShopName { get; }
|
||||
string Addres { get; }
|
||||
DateTime OpenTime { get; }
|
||||
|
||||
int Capacity { get; }
|
||||
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
|
||||
}
|
||||
}
|
||||
152
Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs
Normal file
152
Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDatabaseImplement.models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Pizzas)
|
||||
.ThenInclude(x => x.Pizza)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Pizzas)
|
||||
.ThenInclude(x => x.Pizza)
|
||||
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) &&
|
||||
!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Shops
|
||||
.Include(x => x.Pizzas)
|
||||
.ThenInclude(x => x.Pizza)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) &&
|
||||
x.ShopName == model.ShopName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
|
||||
}
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
var newShop = Shop.Create(context, model);
|
||||
|
||||
if (context.Shops.Any(x => x.ShopName == newShop.ShopName))
|
||||
{
|
||||
throw new Exception("Магазин с таким названием уже существует");
|
||||
}
|
||||
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
shop.UpdatePizzas(context, model);
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
var element = context.Shops
|
||||
.Include(x => x.Pizzas)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Shops.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool TrySellPizza(IPizzaModel pizza, int count)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
foreach (var shopPizzas in context.ShopPizzas.Where(x => x.PizzaId == pizza.Id))
|
||||
{
|
||||
var min = Math.Min(count, shopPizzas.Count);
|
||||
shopPizzas.Count -= min;
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryRestoreShops(IPizzaModel pizza, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
248
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230423174224_AddShop.Designer.cs
generated
Normal file
248
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230423174224_AddShop.Designer.cs
generated
Normal file
@@ -0,0 +1,248 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PizzeriaDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PizzeriaDatabase))]
|
||||
[Migration("20230423174224_AddShop")]
|
||||
partial class AddShop
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("PizzaName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Pizzas");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.ToTable("PizzaComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Addres")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("OpenTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopPizzas");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Component", "Component")
|
||||
.WithMany("PizzaComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||
.WithMany()
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Shop", "Shop")
|
||||
.WithMany("Pizzas")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Pizza");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||
{
|
||||
b.Navigation("PizzaComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Pizzas");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddShop : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||
Addres = table.Column<string>(type: "text", nullable: false),
|
||||
OpenTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Capacity = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopPizzas",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
PizzaId = table.Column<int>(type: "integer", nullable: false),
|
||||
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopPizzas", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopPizzas_Pizzas_PizzaId",
|
||||
column: x => x.PizzaId,
|
||||
principalTable: "Pizzas",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopPizzas_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopPizzas_PizzaId",
|
||||
table: "ShopPizzas",
|
||||
column: "PizzaId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopPizzas_ShopId",
|
||||
table: "ShopPizzas",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopPizzas");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,59 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
b.ToTable("PizzaComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Addres")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("OpenTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopPizzas");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||
@@ -151,6 +204,25 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||
.WithMany()
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.models.Shop", "Shop")
|
||||
.WithMany("Pizzas")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Pizza");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||
{
|
||||
b.Navigation("PizzaComponents");
|
||||
@@ -162,6 +234,11 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Pizzas");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace PizzeriaDatabaseImplement
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Pizza> Pizzas { set; get; }
|
||||
public virtual DbSet<Shop> Shops { set; get; }
|
||||
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
||||
public virtual DbSet<ShopPizza> ShopPizzas { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -53,11 +53,7 @@ namespace PizzeriaDatabaseImplement.models
|
||||
{
|
||||
return;
|
||||
}
|
||||
PizzaId = model.PizzaId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
|
||||
102
Pizzeria/PizzeriaDatabaseImplement/models/Shop.cs
Normal file
102
Pizzeria/PizzeriaDatabaseImplement/models/Shop.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PizzeriaDatabaseImplement.models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Addres { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime OpenTime { get; set; }
|
||||
[Required]
|
||||
public int Capacity { get; set; }
|
||||
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopPizzas == null)
|
||||
{
|
||||
_shopPizzas = Pizzas.ToDictionary(x => x.PizzaId, x => (x.Pizza as IPizzaModel, x.Count));
|
||||
}
|
||||
return _shopPizzas;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ShopId")]
|
||||
public virtual List<ShopPizza> Pizzas { get; set; } = new();
|
||||
public static Shop Create(PizzeriaDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Addres = model.Addres,
|
||||
OpenTime = model.OpenTime,
|
||||
Capacity = model.Capacity,
|
||||
Pizzas = model.ShopPizzas.Select(x => new ShopPizza
|
||||
{
|
||||
Pizza = context.Pizzas.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Addres = model.Addres;
|
||||
OpenTime = model.OpenTime;
|
||||
Capacity = model.Capacity;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Addres = Addres,
|
||||
OpenTime = OpenTime,
|
||||
Capacity = Capacity,
|
||||
ShopPizzas = ShopPizzas
|
||||
};
|
||||
public void UpdatePizzas(PizzeriaDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var shopPizzas = context.ShopPizzas.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (shopPizzas != null && shopPizzas.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ShopPizzas.RemoveRange(shopPizzas.Where(rec
|
||||
=> !model.ShopPizzas.ContainsKey(rec.PizzaId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updatePizza in shopPizzas)
|
||||
{
|
||||
updatePizza.Count =
|
||||
model.ShopPizzas[updatePizza.PizzaId].Item2;
|
||||
model.ShopPizzas.Remove(updatePizza.PizzaId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ShopPizzas)
|
||||
{
|
||||
context.ShopPizzas.Add(new ShopPizza
|
||||
{
|
||||
Shop = shop,
|
||||
Pizza = context.Pizzas.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_shopPizzas = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Pizzeria/PizzeriaDatabaseImplement/models/ShopPizza.cs
Normal file
17
Pizzeria/PizzeriaDatabaseImplement/models/ShopPizza.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PizzeriaDatabaseImplement.models
|
||||
{
|
||||
public class ShopPizza
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PizzaId { get; set; }
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
public virtual Pizza Pizza { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@ namespace PizzeriaListImplement
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Pizza> Pizzas { get; set; }
|
||||
public List<Shop> Shops { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Pizzas = new List<Pizza>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
||||
122
Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs
Normal file
122
Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StoragesContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
using PizzeriaListImplement.Models;
|
||||
|
||||
namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
result.Add(shop.GetViewModel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
var result = new List<ShopViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (shop.ShopName.Contains(model.ShopName))
|
||||
{
|
||||
result.Add(shop.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
|
||||
{
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (model.Id <= shop.Id)
|
||||
{
|
||||
model.Id = shop.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var newShop = Shop.Create(model);
|
||||
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_source.Shops.Add(newShop);
|
||||
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
foreach (var shop in _source.Shops)
|
||||
{
|
||||
if (shop.Id == model.Id)
|
||||
{
|
||||
shop.Update(model);
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Shops.Count; ++i)
|
||||
{
|
||||
if (_source.Shops[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Shops[i];
|
||||
_source.Shops.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool TrySellPizza(IPizzaModel pizza, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Pizzeria/PizzeriaListImplement/Models/Shop.cs
Normal file
61
Pizzeria/PizzeriaListImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels;
|
||||
|
||||
namespace PizzeriaListImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
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
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IPizzaModel, int)>();
|
||||
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,
|
||||
ShopPizzas = model.ShopPizzas
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Addres = model.Addres;
|
||||
OpenTime = OpenTime;
|
||||
ShopPizzas = model.ShopPizzas;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Addres = Addres,
|
||||
OpenTime = OpenTime,
|
||||
Capacity = Capacity,
|
||||
ShopPizzas = ShopPizzas
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ namespace PizzeriaFileImplement
|
||||
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)
|
||||
@@ -22,13 +24,13 @@ namespace PizzeriaFileImplement
|
||||
}
|
||||
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)!)!;
|
||||
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)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user