This commit is contained in:
revengel66 2024-03-11 00:29:35 +04:00
parent 8eee668ae4
commit 693f0ab646
24 changed files with 2424 additions and 0 deletions

View File

@ -0,0 +1,145 @@
namespace Pizzeria
{
partial class FormCreateOrder
{
/// <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()
{
textBoxCount = new TextBox();
labelCount = new Label();
labelPizza = new Label();
buttonCancel = new Button();
buttonSave = new Button();
labelSum = new Label();
textBoxSum = new TextBox();
comboBoxPizza = new ComboBox();
SuspendLayout();
//
// textBoxCount
//
textBoxCount.Location = new Point(99, 41);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(233, 23);
textBoxCount.TabIndex = 13;
textBoxCount.TextChanged += textBoxCount_TextChanged;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(11, 44);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 12;
labelCount.Text = "Количество:";
//
// labelPizza
//
labelPizza.AutoSize = true;
labelPizza.Location = new Point(11, 15);
labelPizza.Name = "labelPizza";
labelPizza.Size = new Size(43, 15);
labelPizza.TabIndex = 11;
labelPizza.Text = "Пицца";
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(257, 109);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 15;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(176, 109);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 16;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// labelSum
//
labelSum.AutoSize = true;
labelSum.Location = new Point(11, 73);
labelSum.Name = "labelSum";
labelSum.Size = new Size(48, 15);
labelSum.TabIndex = 12;
labelSum.Text = "Сумма:";
//
// textBoxSum
//
textBoxSum.Location = new Point(99, 70);
textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(233, 23);
textBoxSum.TabIndex = 13;
//
// comboBoxPizza
//
comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxPizza.FormattingEnabled = true;
comboBoxPizza.Location = new Point(99, 12);
comboBoxPizza.Name = "comboBoxPizza";
comboBoxPizza.Size = new Size(233, 23);
comboBoxPizza.TabIndex = 17;
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(351, 150);
Controls.Add(comboBoxPizza);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxSum);
Controls.Add(labelSum);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(labelPizza);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxCount;
private Label labelCount;
private Label labelPizza;
private Button buttonCancel;
private Button buttonSave;
private Label labelSum;
private TextBox textBoxSum;
private ComboBox comboBoxPizza;
}
}

View File

@ -0,0 +1,124 @@

using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
using System.Windows.Forms;
namespace Pizzeria
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly IPizzaLogic _logicP;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IPizzaLogic logicP, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка пицц для заказа");
try
{
var _list = _logicP.ReadList(null);
if (_list != null)
{
comboBoxPizza.DisplayMember = "PizzaName";
comboBoxPizza.ValueMember = "Id";
comboBoxPizza.DataSource = _list;
comboBoxPizza.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при загрузке пиццы для заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxPizza.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxPizza.SelectedValue);
var Pizza = _logicP.ReadElement(new PizzaSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0),2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
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();
}
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void comboBoxPizza_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void buttonSave_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;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
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);
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

188
Pizzeria/Pizzeria/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,188 @@
namespace Pizzeria
{
partial class FormMain
{
/// <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()
{
menuStrip = new MenuStrip();
справочкиниToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
ButtonIssuedOrder = new Button();
ButtonOrderReady = new Button();
ButtonnTakeOrderInWork = new Button();
ButtonCreateOrder = new Button();
buttonRef_Click = new Button();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { справочкиниToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(999, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "Справочники:";
//
// справочкиниToolStripMenuItem
//
справочкиниToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
справочкиниToolStripMenuItem.Name = "справочкиниToolStripMenuItem";
справочкиниToolStripMenuItem.Size = new Size(97, 20);
справочкиниToolStripMenuItem.Text = "Справочники:";
//
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(148, 22);
компонентыToolStripMenuItem.Text = "Ингредиенты";
компонентыToolStripMenuItem.Click += ИнгредиентыToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
изделияToolStripMenuItem.Size = new Size(148, 22);
изделияToolStripMenuItem.Text = "Пиццы";
изделияToolStripMenuItem.Click += ПиццыToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(0, 27);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(773, 362);
dataGridView.TabIndex = 0;
//
// ButtonIssuedOrder
//
ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonIssuedOrder.Location = new Point(799, 185);
ButtonIssuedOrder.Margin = new Padding(3, 2, 3, 2);
ButtonIssuedOrder.Name = "ButtonIssuedOrder";
ButtonIssuedOrder.Size = new Size(179, 32);
ButtonIssuedOrder.TabIndex = 8;
ButtonIssuedOrder.Text = "Заказ выдан";
ButtonIssuedOrder.UseVisualStyleBackColor = true;
ButtonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// ButtonOrderReady
//
ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonOrderReady.Location = new Point(799, 139);
ButtonOrderReady.Margin = new Padding(3, 2, 3, 2);
ButtonOrderReady.Name = "ButtonOrderReady";
ButtonOrderReady.Size = new Size(179, 32);
ButtonOrderReady.TabIndex = 7;
ButtonOrderReady.Text = "Заказ готов";
ButtonOrderReady.UseVisualStyleBackColor = true;
ButtonOrderReady.Click += ButtonOrderReady_Click;
//
// ButtonnTakeOrderInWork
//
ButtonnTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonnTakeOrderInWork.Location = new Point(799, 93);
ButtonnTakeOrderInWork.Margin = new Padding(3, 2, 3, 2);
ButtonnTakeOrderInWork.Name = "ButtonnTakeOrderInWork";
ButtonnTakeOrderInWork.Size = new Size(179, 32);
ButtonnTakeOrderInWork.TabIndex = 6;
ButtonnTakeOrderInWork.Text = "Отдать на выполнение";
ButtonnTakeOrderInWork.UseVisualStyleBackColor = true;
ButtonnTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// ButtonCreateOrder
//
ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonCreateOrder.Location = new Point(799, 47);
ButtonCreateOrder.Margin = new Padding(3, 2, 3, 2);
ButtonCreateOrder.Name = "ButtonCreateOrder";
ButtonCreateOrder.Size = new Size(179, 32);
ButtonCreateOrder.TabIndex = 5;
ButtonCreateOrder.Text = "Создать заказ";
ButtonCreateOrder.UseVisualStyleBackColor = true;
ButtonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonRef_Click
//
buttonRef_Click.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef_Click.Location = new Point(799, 231);
buttonRef_Click.Margin = new Padding(3, 2, 3, 2);
buttonRef_Click.Name = "buttonRef_Click";
buttonRef_Click.Size = new Size(179, 32);
buttonRef_Click.TabIndex = 8;
buttonRef_Click.Text = "Обновить список";
buttonRef_Click.UseVisualStyleBackColor = true;
buttonRef_Click.Click += ButtonRef_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(999, 390);
Controls.Add(buttonRef_Click);
Controls.Add(ButtonIssuedOrder);
Controls.Add(ButtonOrderReady);
Controls.Add(ButtonnTakeOrderInWork);
Controls.Add(ButtonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMain";
Text = "Пиццерия";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip;
private ToolStripMenuItem справочкиниToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
private DataGridView dataGridView;
private Button ButtonIssuedOrder;
private Button ButtonOrderReady;
private Button ButtonnTakeOrderInWork;
private Button ButtonCreateOrder;
private Button buttonRef_Click;
}
}

View File

@ -0,0 +1,138 @@
using Microsoft.Extensions.Logging;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
namespace Pizzeria
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["PizzaId"].Visible = false;
dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ИнгредиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ПиццыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPizzas));
if (service is FormPizzas form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{ Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

240
Pizzeria/Pizzeria/FormPizza.Designer.cs generated Normal file
View File

@ -0,0 +1,240 @@
namespace Pizzeria
{
partial class FormPizza
{
/// <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()
{
textBoxPrice = new TextBox();
textBoxName = new TextBox();
labelPrice = new Label();
labelName = new Label();
ButtonUpd = new Button();
ButtonDel = new Button();
ButtonRef = new Button();
ButtonAdd = new Button();
dataGridView = new DataGridView();
ColumnId = new DataGridViewTextBoxColumn();
ColumnComponent = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
buttonCancel = new Button();
buttonSave = new Button();
groupBoxComponents = new GroupBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBoxComponents.SuspendLayout();
SuspendLayout();
//
// textBoxPrice
//
textBoxPrice.Enabled = false;
textBoxPrice.Location = new Point(99, 41);
textBoxPrice.Name = "textBoxPrice";
textBoxPrice.Size = new Size(233, 23);
textBoxPrice.TabIndex = 5;
//
// textBoxName
//
textBoxName.Location = new Point(99, 12);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(233, 23);
textBoxName.TabIndex = 6;
//
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(11, 44);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(70, 15);
labelPrice.TabIndex = 4;
labelPrice.Text = "Стоимость:";
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(11, 15);
labelName.Name = "labelName";
labelName.Size = new Size(62, 15);
labelName.TabIndex = 3;
labelName.Text = "Название:";
//
// ButtonUpd
//
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonUpd.Location = new Point(467, 135);
ButtonUpd.Margin = new Padding(3, 2, 3, 2);
ButtonUpd.Name = "ButtonUpd";
ButtonUpd.Size = new Size(82, 22);
ButtonUpd.TabIndex = 10;
ButtonUpd.Text = "Обновить";
ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
//
// ButtonDel
//
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonDel.Location = new Point(467, 100);
ButtonDel.Margin = new Padding(3, 2, 3, 2);
ButtonDel.Name = "ButtonDel";
ButtonDel.Size = new Size(82, 22);
ButtonDel.TabIndex = 9;
ButtonDel.Text = "Удалить";
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonRef
//
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonRef.Location = new Point(467, 62);
ButtonRef.Margin = new Padding(3, 2, 3, 2);
ButtonRef.Name = "ButtonRef";
ButtonRef.Size = new Size(82, 22);
ButtonRef.TabIndex = 8;
ButtonRef.Text = "Изменить";
ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonRef_Click;
//
// ButtonAdd
//
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonAdd.Location = new Point(467, 27);
ButtonAdd.Margin = new Padding(3, 2, 3, 2);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(82, 22);
ButtonAdd.TabIndex = 7;
ButtonAdd.Text = "Добавить";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount });
dataGridView.Location = new Point(6, 22);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(429, 262);
dataGridView.TabIndex = 11;
//
// ColumnId
//
ColumnId.HeaderText = "Id";
ColumnId.Name = "ColumnId";
ColumnId.Visible = false;
//
// ColumnComponent
//
ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnComponent.HeaderText = "Ингредиент";
ColumnComponent.Name = "ColumnComponent";
//
// ColumnCount
//
ColumnCount.HeaderText = "Количество";
ColumnCount.Name = "ColumnCount";
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(486, 386);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 12;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(405, 386);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 13;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// groupBoxComponents
//
groupBoxComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBoxComponents.Controls.Add(ButtonUpd);
groupBoxComponents.Controls.Add(ButtonDel);
groupBoxComponents.Controls.Add(ButtonRef);
groupBoxComponents.Controls.Add(dataGridView);
groupBoxComponents.Controls.Add(ButtonAdd);
groupBoxComponents.Location = new Point(12, 81);
groupBoxComponents.Name = "groupBoxComponents";
groupBoxComponents.Size = new Size(579, 287);
groupBoxComponents.TabIndex = 14;
groupBoxComponents.TabStop = false;
groupBoxComponents.Text = "Ингредиенты";
//
// FormPizza
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(612, 430);
Controls.Add(groupBoxComponents);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxPrice);
Controls.Add(textBoxName);
Controls.Add(labelPrice);
Controls.Add(labelName);
Name = "FormPizza";
Text = "Пицца";
Load += FormPizza_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
groupBoxComponents.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxPrice;
private TextBox textBoxName;
private Label labelPrice;
private Label labelName;
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
private Button ButtonAdd;
private DataGridView dataGridView;
private Button buttonCancel;
private Button buttonSave;
private GroupBox groupBoxComponents;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnComponent;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,204 @@
using Microsoft.Extensions.Logging;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.SearchModels;
using PizzeriaDataModels.Models;
namespace Pizzeria
{
public partial class FormPizza : Form
{
private readonly ILogger _logger;
private readonly IPizzaLogic _logic;
private int? _id;
private Dictionary<int, (IComponentModel, int)> _PizzaComponents;
public int Id { set { _id = value; } }
public FormPizza(ILogger<FormPizza> logger, IPizzaLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_PizzaComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void FormPizza_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка пиццы");
try
{
var view = _logic.ReadElement(new PizzaSearchModel
{
Id =_id.Value
});
if (view != null)
{
textBoxName.Text = view.PizzaName;
textBoxPrice.Text = view.Price.ToString();
_PizzaComponents = view.PizzaComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки пиццы");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private double CalcPrice()
{
double price = 0;
foreach (var elem in _PizzaComponents)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
private void LoadData()
{
_logger.LogInformation("Загрузка ингредиент пиццы");
try
{
if (_PizzaComponents != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _PizzaComponents)
{
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
}
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(FormPizzaComponent));
if (service is FormPizzaComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового ингредиента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_PizzaComponents.ContainsKey(form.Id))
{
_PizzaComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_PizzaComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление ингредиента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent));
if (service is FormPizzaComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _PizzaComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Изменение ингредиента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _PizzaComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_PizzaComponents == null || _PizzaComponents.Count == 0)
{
MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение пиццы");
try
{
var model = new PizzaBindingModel
{
Id = _id ?? 0,
PizzaName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
PizzaComponents = _PizzaComponents
};
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);
}
}
}
}

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnComponent.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

128
Pizzeria/Pizzeria/FormPizzas.Designer.cs generated Normal file
View File

@ -0,0 +1,128 @@
namespace Pizzeria
{
partial class FormPizzas
{
/// <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()
{
ButtonUpd = new Button();
ButtonDel = new Button();
ButtonRef = new Button();
ButtonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// ButtonUpd
//
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonUpd.Location = new Point(584, 138);
ButtonUpd.Margin = new Padding(3, 2, 3, 2);
ButtonUpd.Name = "ButtonUpd";
ButtonUpd.Size = new Size(82, 22);
ButtonUpd.TabIndex = 9;
ButtonUpd.Text = "Обновить";
ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonRef_Click;
//
// ButtonDel
//
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonDel.Location = new Point(584, 103);
ButtonDel.Margin = new Padding(3, 2, 3, 2);
ButtonDel.Name = "ButtonDel";
ButtonDel.Size = new Size(82, 22);
ButtonDel.TabIndex = 8;
ButtonDel.Text = "Удалить";
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonRef
//
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonRef.Location = new Point(584, 65);
ButtonRef.Margin = new Padding(3, 2, 3, 2);
ButtonRef.Name = "ButtonRef";
ButtonRef.Size = new Size(82, 22);
ButtonRef.TabIndex = 7;
ButtonRef.Text = "Изменить";
ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonUpd_Click;
//
// ButtonAdd
//
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
ButtonAdd.Location = new Point(584, 30);
ButtonAdd.Margin = new Padding(3, 2, 3, 2);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(82, 22);
ButtonAdd.TabIndex = 6;
ButtonAdd.Text = "Добавить";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(550, 264);
dataGridView.TabIndex = 5;
//
// FormPizzas
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(702, 264);
Controls.Add(ButtonUpd);
Controls.Add(ButtonDel);
Controls.Add(ButtonRef);
Controls.Add(ButtonAdd);
Controls.Add(dataGridView);
Name = "FormPizzas";
Text = "Пиццы";
Load += FormPizzas_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button ButtonUpd;
private Button ButtonDel;
private Button ButtonRef;
private Button ButtonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,107 @@
using Microsoft.Extensions.Logging;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
namespace Pizzeria
{
public partial class FormPizzas : Form
{
private readonly ILogger _logger;
private readonly IPizzaLogic _logic;
public FormPizzas(ILogger<FormPizzas> logger, IPizzaLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormPizzas_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["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PizzaComponents"].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(FormPizza));
if (service is FormPizza form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
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 PizzaBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления ингредиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
if (service is FormPizza form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,121 @@
namespace Pizzeria
{
partial class FormPizzaComponent
{
/// <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()
{
buttonCancel = new Button();
buttonSave = new Button();
textBoxCount = new TextBox();
labelCount = new Label();
labelComponent = new Label();
comboBoxComponent = new ComboBox();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(259, 87);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(178, 87);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 9;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(101, 41);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(233, 23);
textBoxCount.TabIndex = 6;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(13, 44);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 5;
labelCount.Text = "Количество:";
//
// labelComponent
//
labelComponent.AutoSize = true;
labelComponent.Location = new Point(13, 15);
labelComponent.Name = "labelComponent";
labelComponent.Size = new Size(75, 15);
labelComponent.TabIndex = 4;
labelComponent.Text = "Ингредиент:";
//
// comboBoxComponent
//
comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxComponent.FormattingEnabled = true;
comboBoxComponent.Location = new Point(101, 12);
comboBoxComponent.Name = "comboBoxComponent";
comboBoxComponent.Size = new Size(233, 23);
comboBoxComponent.TabIndex = 10;
//
// FormPizzaComponent
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(355, 125);
Controls.Add(comboBoxComponent);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(labelComponent);
Name = "FormPizzaComponent";
Text = "Ингредиент пиццы";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxCount;
private Label labelCount;
private Label labelComponent;
private ComboBox comboBoxComponent;
}
}

View File

@ -0,0 +1,83 @@
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
namespace Pizzeria
{
public partial class FormPizzaComponent : Form
{
private readonly List<ComponentViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxComponent.SelectedValue);
}
set
{
comboBoxComponent.SelectedValue = value;
}
}
public IComponentModel? ComponentModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); }
}
public FormPizzaComponent(IComponentLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.ValueMember = "Id";
comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null;
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,106 @@
using Microsoft.Extensions.Logging;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.StorageContracts;
using PizzeriaContracts.ViewModels;
namespace PizzeriaBusinessLogic.BusinessLogic
{
public class PizzaLogic : IPizzaLogic
{
private readonly ILogger _logger;
private readonly IPizzaStorage _PizzaStorage;
public PizzaLogic(ILogger<PizzaLogic> logger, IPizzaStorage PizzaStorage)
{
_logger = logger;
_PizzaStorage = PizzaStorage;
}
public List<PizzaViewModel>? ReadList(PizzaSearchModel? model)
{
_logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id);
var list = model == null ? _PizzaStorage.GetFullList() :
_PizzaStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PizzaViewModel? ReadElement(PizzaSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id} ", model.PizzaName, model.Id);
var element = _PizzaStorage.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(PizzaBindingModel model)
{
CheckModel(model);
if (_PizzaStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PizzaBindingModel model)
{
CheckModel(model);
if (_PizzaStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PizzaBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_PizzaStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PizzaBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PizzaName))
{
throw new ArgumentNullException("Нет названия продукта", nameof(model.PizzaName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{ Price}. Id: { Id}", model.PizzaName, model.Price, model.Id);
var element = _PizzaStorage.GetElement(new PizzaSearchModel { PizzaName = model.PizzaName });
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Продукт с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,12 @@
using PizzeriaDataModels.Models;
namespace PizzeriaContracts.BindingModels
{
public class PizzaBindingModel : IPizzaModel
{
public int Id { get; set; }
public string PizzaName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> PizzaComponents {get;set;} = new();
}
}

View File

@ -0,0 +1,15 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.ViewModels;
namespace PizzeriaContracts.BusinessLogicsContracts
{
public interface IPizzaLogic
{
List<PizzaViewModel>? ReadList(PizzaSearchModel? model);
PizzaViewModel? ReadElement(PizzaSearchModel model);
bool Create(PizzaBindingModel model);
bool Update(PizzaBindingModel model);
bool Delete(PizzaBindingModel model);
}
}

View File

@ -0,0 +1,8 @@
namespace PizzeriaContracts.SearchModels
{
public class PizzaSearchModel
{
public int? Id { get; set; }
public string? PizzaName { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.ViewModels;
namespace PizzeriaContracts.StorageContracts
{
public interface IPizzaStorage
{
List<PizzaViewModel> GetFullList();
List<PizzaViewModel> GetFilteredList(PizzaSearchModel model);
PizzaViewModel? GetElement(PizzaSearchModel model);
PizzaViewModel? Insert(PizzaBindingModel model);
PizzaViewModel? Update(PizzaBindingModel model);
PizzaViewModel? Delete(PizzaBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using PizzeriaDataModels.Models;
using System.ComponentModel;
namespace PizzeriaContracts.ViewModels
{
public class PizzaViewModel : IPizzaModel
{
public int Id { get; set; }
[DisplayName("Название пиццы")]
public string PizzaName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> PizzaComponents {get;set;} = new();
}
}

View File

@ -0,0 +1,9 @@
namespace PizzeriaDataModels.Models
{
public interface IPizzaModel : IId
{
string PizzaName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> PizzaComponents { get; }
}
}

View File

@ -0,0 +1,100 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.StorageContracts;
using PizzeriaContracts.ViewModels;
using PizzeriaListImplement.Models;
namespace PizzeriaListImplement.Implements
{
public class PizzaStorage : IPizzaStorage
{
private readonly DataListSingleton _source;
public PizzaStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<PizzaViewModel> GetFullList()
{
var result = new List<PizzaViewModel>();
foreach (var Pizza in _source.Pizzas)
{
result.Add(Pizza.GetViewModel);
}
return result;
}
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
{
var result = new List<PizzaViewModel>();
if (string.IsNullOrEmpty(model.PizzaName))
{
return result;
}
foreach (var Pizza in _source.Pizzas)
{
if (Pizza.PizzaName.Contains(model.PizzaName))
{
result.Add(Pizza.GetViewModel);
}
}
return result;
}
public PizzaViewModel? GetElement(PizzaSearchModel model)
{
if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue)
{
return null;
}
foreach (var Pizza in _source.Pizzas)
{
if ((!string.IsNullOrEmpty(model.PizzaName) && Pizza.PizzaName == model.PizzaName) || (model.Id.HasValue && Pizza.Id == model.Id))
{
return Pizza.GetViewModel;
}
}
return null;
}
public PizzaViewModel? Insert(PizzaBindingModel model)
{
model.Id = 1;
foreach (var Pizza in _source.Pizzas)
{
if (model.Id <= Pizza.Id)
{
model.Id = Pizza.Id + 1;
}
}
var newPizza = Pizza.Create(model);
if (newPizza == null)
{
return null;
}
_source.Pizzas.Add(newPizza);
return newPizza.GetViewModel;
}
public PizzaViewModel? Update(PizzaBindingModel model)
{
foreach (var Pizza in _source.Pizzas)
{
if (Pizza.Id == model.Id)
{
Pizza.Update(model);
return Pizza.GetViewModel;
}
}
return null;
}
public PizzaViewModel? Delete(PizzaBindingModel model)
{
for (int i = 0; i < _source.Pizzas.Count; ++i)
{
if (_source.Pizzas[i].Id == model.Id)
{
var element = _source.Pizzas[i];
_source.Pizzas.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,49 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
namespace PizzeriaListImplement.Models
{
public class Pizza : IPizzaModel
{
public int Id { get; private set; }
public string PizzaName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> PizzaComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Pizza? Create(PizzaBindingModel? model)
{
if (model == null)
{
return null;
}
return new Pizza()
{
Id = model.Id,
PizzaName = model.PizzaName,
Price = model.Price,
PizzaComponents = model.PizzaComponents
};
}
public void Update(PizzaBindingModel? model)
{
if (model == null)
{
return;
}
PizzaName = model.PizzaName;
Price = model.Price;
PizzaComponents = model.PizzaComponents;
}
public PizzaViewModel GetViewModel => new()
{
Id = Id,
PizzaName = PizzaName,
Price = Price,
PizzaComponents = PizzaComponents
};
}
}