Добавление форм и работы с базой данных

This commit is contained in:
Максим Яковлев 2024-04-21 13:27:17 +04:00
parent 0a8fd1126d
commit a13b0170ff
60 changed files with 5643 additions and 6 deletions

View File

@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{E62F051D-30D6-4F1C-B02E-C814B7D03F86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -33,6 +35,10 @@ Global
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}.Release|Any CPU.Build.0 = Release|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

117
SushiBar/SushiBar/FormBuyer.Designer.cs generated Normal file
View File

@ -0,0 +1,117 @@
namespace SushiBarView
{
partial class FormBuyer
{
/// <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()
{
label1 = new Label();
label2 = new Label();
textBoxName = new TextBox();
dateTimePicker = new DateTimePicker();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 20);
label1.Name = "label1";
label1.Size = new Size(34, 15);
label1.TabIndex = 0;
label1.Text = "Имя:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 51);
label2.Name = "label2";
label2.Size = new Size(93, 15);
label2.TabIndex = 1;
label2.Text = "Дата рождения:";
//
// textBoxName
//
textBoxName.Location = new Point(116, 12);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(208, 23);
textBoxName.TabIndex = 2;
//
// dateTimePicker
//
dateTimePicker.Location = new Point(116, 45);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(208, 23);
dateTimePicker.TabIndex = 3;
//
// buttonCancel
//
buttonCancel.Location = new Point(287, 84);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(77, 30);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonSave
//
buttonSave.Location = new Point(204, 84);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(83, 30);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormBuyer
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(375, 130);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(dateTimePicker);
Controls.Add(textBoxName);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormBuyer";
Text = "Покупатель";
Load += FormBuyer_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private TextBox textBoxName;
private DateTimePicker dateTimePicker;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,86 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormBuyer : Form
{
private readonly IBuyerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormBuyer(IBuyerLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormBuyer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _logic.ReadElement(new BuyerSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.BuyerName;
dateTimePicker.Value = (DateTime)view.BuyerBirthDate;
}
}
catch (Exception 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;
}
try
{
var model = new BuyerBindingModel
{
Id = _id ?? 0,
BuyerName = textBoxName.Text,
BuyerBirthDate = dateTimePicker.Value
};
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)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

107
SushiBar/SushiBar/FormBuyers.Designer.cs generated Normal file
View File

@ -0,0 +1,107 @@
namespace SushiBarView
{
partial class FormBuyers
{
/// <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()
{
dataGridView = new DataGridView();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.ShowCellToolTips = false;
dataGridView.ShowEditingIcon = false;
dataGridView.Size = new Size(525, 450);
dataGridView.TabIndex = 1;
//
// buttonDel
//
buttonDel.Location = new Point(564, 116);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(118, 35);
buttonDel.TabIndex = 7;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(564, 65);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(118, 35);
buttonUpd.TabIndex = 6;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(564, 15);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 35);
buttonAdd.TabIndex = 5;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// FormBuyers
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(716, 450);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormBuyers";
Text = "Покупатели";
Load += FormBuyers_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,100 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormBuyers : Form
{
private readonly IBuyerLogic _logic;
public FormBuyers(IBuyerLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormBuyers_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["BuyerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBuyer));
if (service is FormBuyer 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(FormBuyer));
if (service is FormBuyer 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);
try
{
if (!_logic.Delete(new BuyerBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Доп информация в логах");
}
LoadData();
}
catch (Exception 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>

184
SushiBar/SushiBar/FormCook.Designer.cs generated Normal file
View File

@ -0,0 +1,184 @@
namespace SushiBarView
{
partial class FormCook
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label5 = new Label();
label6 = new Label();
textBoxName = new TextBox();
textBoxSurname = new TextBox();
textBoxExperience = new TextBox();
textBoxPhoneNumber = new TextBox();
textBoxPassport = new TextBox();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(9, 9);
label1.Name = "label1";
label1.Size = new Size(31, 15);
label1.TabIndex = 0;
label1.Text = "Имя";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(9, 43);
label2.Name = "label2";
label2.Size = new Size(58, 15);
label2.TabIndex = 1;
label2.Text = "Фамилия";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(9, 81);
label3.Name = "label3";
label3.Size = new Size(81, 15);
label3.TabIndex = 2;
label3.Text = "Опыт работы";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(9, 119);
label5.Name = "label5";
label5.Size = new Size(101, 15);
label5.TabIndex = 3;
label5.Text = "Номер телефона";
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(9, 157);
label6.Name = "label6";
label6.Size = new Size(99, 15);
label6.TabIndex = 4;
label6.Text = "Номер паспорта";
//
// textBoxName
//
textBoxName.Location = new Point(116, 6);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(181, 23);
textBoxName.TabIndex = 5;
//
// textBoxSurname
//
textBoxSurname.Location = new Point(116, 40);
textBoxSurname.Name = "textBoxSurname";
textBoxSurname.Size = new Size(181, 23);
textBoxSurname.TabIndex = 6;
//
// textBoxExperience
//
textBoxExperience.Location = new Point(116, 78);
textBoxExperience.Name = "textBoxExperience";
textBoxExperience.Size = new Size(181, 23);
textBoxExperience.TabIndex = 7;
//
// textBoxPhoneNumber
//
textBoxPhoneNumber.Location = new Point(116, 116);
textBoxPhoneNumber.Name = "textBoxPhoneNumber";
textBoxPhoneNumber.Size = new Size(181, 23);
textBoxPhoneNumber.TabIndex = 8;
//
// textBoxPassport
//
textBoxPassport.Location = new Point(116, 154);
textBoxPassport.Name = "textBoxPassport";
textBoxPassport.Size = new Size(181, 23);
textBoxPassport.TabIndex = 9;
//
// buttonCancel
//
buttonCancel.Location = new Point(232, 197);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(77, 30);
buttonCancel.TabIndex = 11;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(149, 197);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(83, 30);
buttonSave.TabIndex = 10;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormCook
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(326, 242);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxPassport);
Controls.Add(textBoxPhoneNumber);
Controls.Add(textBoxExperience);
Controls.Add(textBoxSurname);
Controls.Add(textBoxName);
Controls.Add(label6);
Controls.Add(label5);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormCook";
Text = "Повар";
Load += FormCook_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label5;
private Label label6;
private TextBox textBoxName;
private TextBox textBoxSurname;
private TextBox textBoxExperience;
private TextBox textBoxPhoneNumber;
private TextBox textBoxPassport;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,90 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormCook : Form
{
private ICookLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormCook(ICookLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormCook_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _logic.ReadElement(new CookSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.CookName;
textBoxSurname.Text = view.CookSurname;
textBoxExperience.Text = view.Experience.ToString();
textBoxPhoneNumber.Text = view.PhoneNumber;
textBoxPassport.Text = view.Passport;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text) || string.IsNullOrEmpty(textBoxSurname.Text) || string.IsNullOrEmpty(textBoxPassport.Text) || string.IsNullOrEmpty(textBoxExperience.Text) || string.IsNullOrEmpty(textBoxPhoneNumber.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new CookBindingModel
{
Id = _id ?? 0,
CookName = textBoxName.Text,
CookSurname = textBoxSurname.Text,
Experience = Convert.ToInt32(textBoxExperience.Text),
PhoneNumber = textBoxPhoneNumber.Text,
Passport = textBoxPassport.Text
};
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)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

108
SushiBar/SushiBar/FormCooks.Designer.cs generated Normal file
View File

@ -0,0 +1,108 @@
namespace SushiBarView
{
partial class FormCooks
{
/// <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()
{
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDel
//
buttonDel.Location = new Point(574, 116);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(118, 35);
buttonDel.TabIndex = 11;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(574, 65);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(118, 35);
buttonUpd.TabIndex = 10;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(574, 15);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 35);
buttonAdd.TabIndex = 9;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.ShowCellToolTips = false;
dataGridView.ShowEditingIcon = false;
dataGridView.Size = new Size(525, 450);
dataGridView.TabIndex = 8;
//
// FormCooks
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(737, 450);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormCooks";
Text = "Повара";
Load += FormCooks_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,101 @@
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormCooks : Form
{
private readonly ICookLogic _logic;
public FormCooks(ICookLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormCooks_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["CookName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCook));
if (service is FormCook 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(FormCook));
if (service is FormCook 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);
try
{
if (!_logic.Delete(new CookBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Доп информация в логах");
}
LoadData();
}
catch (Exception 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>

View File

@ -0,0 +1,267 @@
namespace SushiBarView
{
partial class FormCreateTask
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
comboBoxPlace = new ComboBox();
comboBoxCook = new ComboBox();
comboBoxBuyer = new ComboBox();
groupBox1 = new GroupBox();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
ColumnFoodName = new DataGridViewTextBoxColumn();
ColumnDesc = new DataGridViewTextBoxColumn();
ColumnPrice = new DataGridViewTextBoxColumn();
buttonCancel = new Button();
buttonSave = new Button();
textBoxPrice = new TextBox();
label4 = new Label();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(16, 9);
label1.Name = "label1";
label1.Size = new Size(47, 15);
label1.TabIndex = 0;
label1.Text = "Столик";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(16, 42);
label2.Name = "label2";
label2.Size = new Size(42, 15);
label2.TabIndex = 1;
label2.Text = "Повар";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(16, 76);
label3.Name = "label3";
label3.Size = new Size(72, 15);
label3.TabIndex = 2;
label3.Text = "Покупатель";
//
// comboBoxPlace
//
comboBoxPlace.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxPlace.FormattingEnabled = true;
comboBoxPlace.Location = new Point(100, 6);
comboBoxPlace.Name = "comboBoxPlace";
comboBoxPlace.Size = new Size(249, 23);
comboBoxPlace.TabIndex = 4;
//
// comboBoxCook
//
comboBoxCook.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxCook.FormattingEnabled = true;
comboBoxCook.Location = new Point(100, 39);
comboBoxCook.Name = "comboBoxCook";
comboBoxCook.Size = new Size(249, 23);
comboBoxCook.TabIndex = 5;
//
// comboBoxBuyer
//
comboBoxBuyer.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxBuyer.FormattingEnabled = true;
comboBoxBuyer.Location = new Point(100, 73);
comboBoxBuyer.Name = "comboBoxBuyer";
comboBoxBuyer.Size = new Size(249, 23);
comboBoxBuyer.TabIndex = 6;
//
// groupBox1
//
groupBox1.Controls.Add(buttonDel);
groupBox1.Controls.Add(buttonUpd);
groupBox1.Controls.Add(buttonAdd);
groupBox1.Controls.Add(dataGridView);
groupBox1.Location = new Point(12, 102);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(620, 336);
groupBox1.TabIndex = 7;
groupBox1.TabStop = false;
groupBox1.Text = "Блюда";
//
// buttonDel
//
buttonDel.Location = new Point(480, 123);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(118, 35);
buttonDel.TabIndex = 10;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(480, 72);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(118, 35);
buttonUpd.TabIndex = 9;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(480, 22);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 35);
buttonAdd.TabIndex = 8;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnFoodName, ColumnDesc, ColumnPrice });
dataGridView.Location = new Point(6, 22);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(451, 308);
dataGridView.TabIndex = 0;
//
// ColumnFoodName
//
ColumnFoodName.HeaderText = "Название";
ColumnFoodName.Name = "ColumnFoodName";
ColumnFoodName.ReadOnly = true;
//
// ColumnDesc
//
ColumnDesc.HeaderText = "Описание";
ColumnDesc.Name = "ColumnDesc";
ColumnDesc.ReadOnly = true;
//
// ColumnPrice
//
ColumnPrice.HeaderText = "Цена";
ColumnPrice.Name = "ColumnPrice";
ColumnPrice.ReadOnly = true;
//
// buttonCancel
//
buttonCancel.Location = new Point(540, 444);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(118, 35);
buttonCancel.TabIndex = 12;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(416, 444);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(118, 35);
buttonSave.TabIndex = 11;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// textBoxPrice
//
textBoxPrice.Enabled = false;
textBoxPrice.Location = new Point(247, 451);
textBoxPrice.Name = "textBoxPrice";
textBoxPrice.Size = new Size(141, 23);
textBoxPrice.TabIndex = 14;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(171, 454);
label4.Name = "label4";
label4.Size = new Size(70, 15);
label4.TabIndex = 13;
label4.Text = "Стоимость:";
//
// FormCreateTask
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(670, 490);
Controls.Add(textBoxPrice);
Controls.Add(label4);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBox1);
Controls.Add(comboBoxBuyer);
Controls.Add(comboBoxCook);
Controls.Add(comboBoxPlace);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormCreateTask";
Text = "Заказ";
Load += FormCreateTask_Load;
groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private ComboBox comboBoxPlace;
private ComboBox comboBoxCook;
private ComboBox comboBoxBuyer;
private GroupBox groupBox1;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxPrice;
private Label label4;
private DataGridViewTextBoxColumn ColumnFoodName;
private DataGridViewTextBoxColumn ColumnDesc;
private DataGridViewTextBoxColumn ColumnPrice;
}
}

View File

@ -0,0 +1,221 @@
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormCreateTask : Form
{
private readonly IPlaceLogic _logicP;
private readonly ICookLogic _logicC;
private readonly IBuyerLogic _logicB;
private readonly ITaskLogic _logicT;
private int? _id;
private Dictionary<int, (IMenuModel, int)> _taskMenu;
public int Id { set { _id = value; } }
public FormCreateTask(IPlaceLogic plogic, ICookLogic clogic, IBuyerLogic blogic, ITaskLogic tlogic)
{
InitializeComponent();
_logicP = plogic;
_logicC = clogic;
_logicB = blogic;
_logicT = tlogic;
_taskMenu = new Dictionary<int, (IMenuModel, int)>();
}
private void FormCreateTask_Load(object sender, EventArgs e)
{
var _listP = _logicP.ReadList(null);
var _listC = _logicC.ReadList(null);
var _listB = _logicB.ReadList(null);
if (_listP != null)
{
comboBoxPlace.DisplayMember = "PlaceNumber";
comboBoxPlace.ValueMember = "Id";
comboBoxPlace.DataSource = _listP;
comboBoxPlace.SelectedItem = null;
}
if (_listC != null)
{
comboBoxCook.DisplayMember = "CookName";
comboBoxCook.ValueMember = "Id";
comboBoxCook.DataSource = _listC;
comboBoxCook.SelectedItem = null;
}
if (_listB != null)
{
comboBoxBuyer.DisplayMember = "BuyerName";
comboBoxBuyer.ValueMember = "Id";
comboBoxBuyer.DataSource = _listB;
comboBoxBuyer.SelectedItem = null;
}
if (_id.HasValue)
{
try
{
var view = _logicT.ReadElement(new TaskSearchModel { Id = _id.Value });
if (view != null)
{
textBoxPrice.Text = CalcPrice().ToString();
_taskMenu = view.TaskMenus ?? new Dictionary<int, (IMenuModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
try
{
textBoxPrice.Text = CalcPrice().ToString();
if (_taskMenu != null)
{
dataGridView.Rows.Clear();
foreach (var rc in _taskMenu)
{
dataGridView.Rows.Add(new object[] { rc.Value.Item1.FoodName, rc.Value.Item1.Description, rc.Value.Item1.Price * rc.Value.Item2 });
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTaskMenu));
if (service is FormTaskMenu form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.MenuModel == null)
{
return;
}
if (_taskMenu.ContainsKey(form.Id))
{
_taskMenu[form.Id] = (form.MenuModel, form.Count);
}
else
{
_taskMenu.Add(form.Id, (form.MenuModel, form.Count));
}
LoadData();
}
}
}
private void buttonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTaskMenu));
if (service is FormTaskMenu form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _taskMenu[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.MenuModel == null)
{
return;
}
_taskMenu[form.Id] = (form.MenuModel, form.Count);
LoadData();
}
}
}
}
private void buttonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_taskMenu?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (_taskMenu == null || _taskMenu.Count == 0)
{
MessageBox.Show("Заполните блюда", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new TaskBindingModel
{
Id = _id ?? 0,
TaskDate = DateTime.Now,
Status = SushiBarDataModels.Enum.TaskStatus.Принят,
FullPrice = CalcPrice(),
CookId = comboBoxCook.SelectedIndex+1,
BuyerId = comboBoxBuyer.SelectedIndex+1,
PlaceId = comboBoxPlace.SelectedIndex + 1,
TaskMenus = _taskMenu
};
var operationResult = _id.HasValue ? _logicT.Update(model) : _logicT.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Доп информация в логах");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private double CalcPrice()
{
double price = 0;
foreach (var elem in _taskMenu)
{
price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2);
}
return price;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

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="ColumnFoodName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnDesc.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnPrice.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

201
SushiBar/SushiBar/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,201 @@
namespace SushiBarView
{
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()
{
menuStrip1 = new MenuStrip();
объектыToolStripMenuItem = new ToolStripMenuItem();
buyerToolStripMenuItem = new ToolStripMenuItem();
cookToolStripMenuItem = new ToolStripMenuItem();
menuToolStripMenuItem = new ToolStripMenuItem();
placeToolStripMenuItem = new ToolStripMenuItem();
buttonIssuedTask = new Button();
buttonTaskReady = new Button();
buttonTakeTaskInWork = new Button();
buttonCreateTask = new Button();
dataGridView = new DataGridView();
buttonTest = new Button();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { объектыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
menuStrip1.Size = new Size(1387, 30);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// объектыToolStripMenuItem
//
объектыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { buyerToolStripMenuItem, cookToolStripMenuItem, menuToolStripMenuItem, placeToolStripMenuItem });
объектыToolStripMenuItem.Name = "объектыToolStripMenuItem";
объектыToolStripMenuItem.Size = new Size(82, 24);
объектыToolStripMenuItem.Text = "Объекты";
//
// buyerToolStripMenuItem
//
buyerToolStripMenuItem.Name = "buyerToolStripMenuItem";
buyerToolStripMenuItem.Size = new Size(159, 24);
buyerToolStripMenuItem.Text = "Покупатель";
buyerToolStripMenuItem.Click += buyerToolStripMenuItem_Click;
//
// cookToolStripMenuItem
//
cookToolStripMenuItem.Name = "cookToolStripMenuItem";
cookToolStripMenuItem.Size = new Size(159, 24);
cookToolStripMenuItem.Text = "Повар";
cookToolStripMenuItem.Click += cookToolStripMenuItem_Click;
//
// menuToolStripMenuItem
//
menuToolStripMenuItem.Name = "menuToolStripMenuItem";
menuToolStripMenuItem.Size = new Size(159, 24);
menuToolStripMenuItem.Text = "Меню";
menuToolStripMenuItem.Click += menuToolStripMenuItem_Click;
//
// placeToolStripMenuItem
//
placeToolStripMenuItem.Name = "placeToolStripMenuItem";
placeToolStripMenuItem.Size = new Size(159, 24);
placeToolStripMenuItem.Text = "Столик";
placeToolStripMenuItem.Click += placeToolStripMenuItem_Click;
//
// buttonIssuedTask
//
buttonIssuedTask.Location = new Point(1106, 275);
buttonIssuedTask.Margin = new Padding(3, 4, 3, 4);
buttonIssuedTask.Name = "buttonIssuedTask";
buttonIssuedTask.Size = new Size(226, 37);
buttonIssuedTask.TabIndex = 11;
buttonIssuedTask.Text = "Заказ выдан";
buttonIssuedTask.UseVisualStyleBackColor = true;
buttonIssuedTask.Click += buttonIssuedTask_Click;
//
// buttonTaskReady
//
buttonTaskReady.Location = new Point(1106, 205);
buttonTaskReady.Margin = new Padding(3, 4, 3, 4);
buttonTaskReady.Name = "buttonTaskReady";
buttonTaskReady.Size = new Size(226, 37);
buttonTaskReady.TabIndex = 10;
buttonTaskReady.Text = "Заказ готов";
buttonTaskReady.UseVisualStyleBackColor = true;
buttonTaskReady.Click += buttonTaskReady_Click;
//
// buttonTakeTaskInWork
//
buttonTakeTaskInWork.Location = new Point(1106, 133);
buttonTakeTaskInWork.Margin = new Padding(3, 4, 3, 4);
buttonTakeTaskInWork.Name = "buttonTakeTaskInWork";
buttonTakeTaskInWork.Size = new Size(226, 37);
buttonTakeTaskInWork.TabIndex = 9;
buttonTakeTaskInWork.Text = "Отдать на выполнение";
buttonTakeTaskInWork.UseVisualStyleBackColor = true;
buttonTakeTaskInWork.Click += buttonTakeTaskInWork_Click;
//
// buttonCreateTask
//
buttonCreateTask.Location = new Point(1106, 61);
buttonCreateTask.Margin = new Padding(3, 4, 3, 4);
buttonCreateTask.Name = "buttonCreateTask";
buttonCreateTask.Size = new Size(226, 37);
buttonCreateTask.TabIndex = 8;
buttonCreateTask.Text = "Создать заказ";
buttonCreateTask.UseVisualStyleBackColor = true;
buttonCreateTask.Click += buttonCreateTask_Click;
//
// dataGridView
//
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 30);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(1049, 570);
dataGridView.TabIndex = 7;
//
// buttonTest
//
buttonTest.Location = new Point(1106, 349);
buttonTest.Margin = new Padding(3, 4, 3, 4);
buttonTest.Name = "buttonTest";
buttonTest.Size = new Size(226, 37);
buttonTest.TabIndex = 12;
buttonTest.Text = "ТЕСТ";
buttonTest.UseVisualStyleBackColor = true;
buttonTest.Click += buttonTest_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1387, 600);
Controls.Add(buttonTest);
Controls.Add(buttonIssuedTask);
Controls.Add(buttonTaskReady);
Controls.Add(buttonTakeTaskInWork);
Controls.Add(buttonCreateTask);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 4, 3, 4);
Name = "FormMain";
Text = "Главное окно";
Load += FormMain_Load;
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem объектыToolStripMenuItem;
private ToolStripMenuItem buyerToolStripMenuItem;
private ToolStripMenuItem cookToolStripMenuItem;
private ToolStripMenuItem menuToolStripMenuItem;
private ToolStripMenuItem placeToolStripMenuItem;
private Button buttonIssuedTask;
private Button buttonTaskReady;
private Button buttonTakeTaskInWork;
private Button buttonCreateTask;
private DataGridView dataGridView;
private Button buttonTest;
}
}

View File

@ -0,0 +1,192 @@
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormMain : Form
{
private readonly ITaskLogic _logic;
private readonly ICookLogic _CLogic;
public FormMain(ITaskLogic logic, ICookLogic cLogic)
{
InitializeComponent();
_logic = logic;
_CLogic = cLogic;
}
private void buyerToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBuyers));
if (service is FormBuyers form)
{
form.ShowDialog();
}
}
private void cookToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCooks));
if (service is FormCooks form)
{
form.ShowDialog();
}
}
private void placeToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPlaces));
if (service is FormPlaces form)
{
form.ShowDialog();
}
}
private void menuToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMenus));
if (service is FormMenus form)
{
form.ShowDialog();
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
var _list = _logic.ReadList(null);
if (_list != null)
{
dataGridView.DataSource = _list;
dataGridView.Columns["PlaceId"].Visible = false;
dataGridView.Columns["CookId"].Visible = false;
dataGridView.Columns["BuyerId"].Visible = false;
dataGridView.Columns["TaskMenus"].Visible = false;
}
}
private void buttonCreateTask_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateTask));
if (service is FormCreateTask form)
{
form.ShowDialog();
LoadData();
}
}
private void buttonTakeTaskInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.TakeTaskInWork(new TaskBindingModel
{
Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonTaskReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.FinishTask(new TaskBindingModel
{
Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Доп информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonIssuedTask_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.DeliveryTask(new TaskBindingModel
{
Id = id,
Status = Enum.Parse<SushiBarDataModels.Enum.TaskStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Доп информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonTest_Click(object sender, EventArgs e)
{
CookBindingModel model = new CookBindingModel()
{
Id = 2,
CookName = "Иван",
CookSurname = "dssfsdfs",
Experience = 2,
PhoneNumber = "+79054324312",
Passport = "123124"
};
DateTime start = DateTime.Now;
_CLogic.Delete(model);
DateTime stop = DateTime.Now;
MessageBox.Show((start - stop).ToString(), "Test", MessageBoxButtons.OK);
}
}
}
//public string CookSurname { get; set; } = string.Empty;
//public int Experience { get; set; }
//public string PhoneNumber { get; set; } = string.Empty;
//public string Passport { get; set; } = string.Empty;

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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

140
SushiBar/SushiBar/FormMenu.Designer.cs generated Normal file
View File

@ -0,0 +1,140 @@
namespace SushiBarView
{
partial class FormMenu
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
textBoxFoodName = new TextBox();
textBoxPrice = new TextBox();
textBoxDeskr = new TextBox();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 9);
label1.Name = "label1";
label1.Size = new Size(59, 15);
label1.TabIndex = 0;
label1.Text = "Название";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 67);
label2.Name = "label2";
label2.Size = new Size(35, 15);
label2.TabIndex = 1;
label2.Text = "Цена";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(12, 39);
label3.Name = "label3";
label3.Size = new Size(62, 15);
label3.TabIndex = 1;
label3.Text = "Описание";
//
// textBoxFoodName
//
textBoxFoodName.Location = new Point(90, 6);
textBoxFoodName.Name = "textBoxFoodName";
textBoxFoodName.Size = new Size(218, 23);
textBoxFoodName.TabIndex = 2;
//
// textBoxPrice
//
textBoxPrice.Location = new Point(90, 64);
textBoxPrice.Name = "textBoxPrice";
textBoxPrice.Size = new Size(218, 23);
textBoxPrice.TabIndex = 3;
//
// textBoxDeskr
//
textBoxDeskr.Location = new Point(90, 36);
textBoxDeskr.Name = "textBoxDeskr";
textBoxDeskr.Size = new Size(218, 23);
textBoxDeskr.TabIndex = 4;
//
// buttonCancel
//
buttonCancel.Location = new Point(236, 93);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(77, 30);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(153, 93);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(83, 30);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormMenu
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(325, 130);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxDeskr);
Controls.Add(textBoxPrice);
Controls.Add(textBoxFoodName);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormMenu";
Text = "Блюдо";
Load += FormMenu_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private TextBox textBoxFoodName;
private TextBox textBoxPrice;
private TextBox textBoxDeskr;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,88 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormMenu : Form
{
private readonly IMenuLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormMenu(IMenuLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormMenu_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _logic.ReadElement(new MenuSearchModel { Id = _id.Value });
if (view != null)
{
textBoxFoodName.Text = view.FoodName;
textBoxDeskr.Text = view.Description;
textBoxPrice.Text = view.Price.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxFoodName.Text) || string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new MenuBindingModel
{
Id = _id ?? 0,
FoodName = textBoxFoodName.Text,
Description = textBoxDeskr.Text,
Price = Convert.ToDouble(textBoxPrice.Text)
};
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)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

106
SushiBar/SushiBar/FormMenus.Designer.cs generated Normal file
View File

@ -0,0 +1,106 @@
namespace SushiBarView
{
partial class FormMenus
{
/// <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()
{
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDel
//
buttonDel.Location = new Point(547, 113);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(118, 35);
buttonDel.TabIndex = 7;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(547, 62);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(118, 35);
buttonUpd.TabIndex = 6;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(547, 12);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 35);
buttonAdd.TabIndex = 5;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(493, 450);
dataGridView.TabIndex = 4;
//
// FormMenus
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(710, 450);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormMenus";
Text = "Меню";
Load += FormMenus_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,101 @@
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormMenus : Form
{
private readonly IMenuLogic _logic;
public FormMenus(IMenuLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormMenus_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["Description"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMenu));
if (service is FormMenu 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(FormMenu));
if (service is FormMenu 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);
try
{
if (!_logic.Delete(new MenuBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Доп информация в логах");
}
LoadData();
}
catch (Exception 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>

118
SushiBar/SushiBar/FormPlace.Designer.cs generated Normal file
View File

@ -0,0 +1,118 @@
namespace SushiBarView
{
partial class FormPlace
{
/// <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()
{
label1 = new Label();
label2 = new Label();
textBoxNumber = new TextBox();
textBoxCount = new TextBox();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 18);
label1.Name = "label1";
label1.Size = new Size(92, 15);
label1.TabIndex = 0;
label1.Text = "Номер столика";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 48);
label2.Name = "label2";
label2.Size = new Size(75, 15);
label2.TabIndex = 1;
label2.Text = "Кол-во мест";
//
// textBoxNumber
//
textBoxNumber.Location = new Point(110, 15);
textBoxNumber.Name = "textBoxNumber";
textBoxNumber.Size = new Size(169, 23);
textBoxNumber.TabIndex = 2;
//
// textBoxCount
//
textBoxCount.Location = new Point(110, 48);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(169, 23);
textBoxCount.TabIndex = 3;
//
// buttonCancel
//
buttonCancel.Location = new Point(202, 88);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(77, 30);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(119, 88);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(83, 30);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormPlace
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(291, 133);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(textBoxNumber);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormPlace";
Text = "Столик";
Load += FormPlace_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private TextBox textBoxNumber;
private TextBox textBoxCount;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,85 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormPlace : Form
{
private readonly IPlaceLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormPlace(IPlaceLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormPlace_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _logic.ReadElement(new PlaceSearchModel { Id = _id.Value });
if (view != null)
{
textBoxNumber.Text = view.PlaceNumber.ToString();
textBoxCount.Text = view.CountPlaces.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxNumber.Text) || string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new PlaceBindingModel
{
Id = _id ?? 0,
PlaceNumber = Convert.ToInt32(textBoxNumber.Text),
CountPlaces = Convert.ToInt32(textBoxCount.Text)
};
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)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

108
SushiBar/SushiBar/FormPlaces.Designer.cs generated Normal file
View File

@ -0,0 +1,108 @@
namespace SushiBarView
{
partial class FormPlaces
{
/// <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()
{
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDel
//
buttonDel.Location = new Point(361, 118);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(118, 35);
buttonDel.TabIndex = 8;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(361, 67);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(118, 35);
buttonUpd.TabIndex = 7;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(361, 17);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 35);
buttonAdd.TabIndex = 6;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = Color.White;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(331, 450);
dataGridView.TabIndex = 5;
//
// FormPlaces
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(506, 450);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormPlaces";
Text = "Столики";
Load += FormPlaces_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,101 @@
using SushiBar;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormPlaces : Form
{
private readonly IPlaceLogic _logic;
public FormPlaces(IPlaceLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormPlaces_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["PlaceNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["CountPlaces"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPlace));
if (service is FormPlace 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(FormPlace));
if (service is FormPlace 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);
try
{
if (!_logic.Delete(new PlaceBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Доп информация в логах");
}
LoadData();
}
catch (Exception 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>

119
SushiBar/SushiBar/FormTaskMenu.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace SushiBarView
{
partial class FormTaskMenu
{
/// <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()
{
label1 = new Label();
label2 = new Label();
buttonCancel = new Button();
buttonSave = new Button();
textBoxCount = new TextBox();
comboBoxMenu = new ComboBox();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 9);
label1.Name = "label1";
label1.Size = new Size(44, 15);
label1.TabIndex = 0;
label1.Text = "Блюдо";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(13, 38);
label2.Name = "label2";
label2.Size = new Size(46, 15);
label2.TabIndex = 1;
label2.Text = "Кол-во";
//
// buttonCancel
//
buttonCancel.Location = new Point(236, 64);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(90, 26);
buttonCancel.TabIndex = 12;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(140, 64);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(90, 26);
buttonSave.TabIndex = 11;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(77, 35);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(249, 23);
textBoxCount.TabIndex = 9;
//
// comboBoxMenu
//
comboBoxMenu.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxMenu.FormattingEnabled = true;
comboBoxMenu.Location = new Point(77, 6);
comboBoxMenu.Name = "comboBoxMenu";
comboBoxMenu.Size = new Size(249, 23);
comboBoxMenu.TabIndex = 8;
//
// FormTaskMenu
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(362, 97);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(comboBoxMenu);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormTaskMenu";
Text = "Заказ - Блюдо";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxCount;
private ComboBox comboBoxMenu;
}
}

View File

@ -0,0 +1,79 @@
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBarView
{
public partial class FormTaskMenu : Form
{
private readonly List<MenuViewModel?> _list;
public int Id { get { return Convert.ToInt32(comboBoxMenu.SelectedValue); } set { comboBoxMenu.SelectedValue = value; } }
public IMenuModel? MenuModel
{
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 FormTaskMenu(IMenuLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxMenu.DisplayMember = "FoodName";
comboBoxMenu.ValueMember = "Id";
comboBoxMenu.DataSource = _list;
comboBoxMenu.SelectedItem = null;
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxMenu.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

@ -1,7 +1,17 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BusinessLogicContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements;
using SushiBarView;
namespace SushiBar
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -11,7 +21,37 @@ namespace SushiBar
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<IBuyerStorage, BuyerStorage>();
services.AddTransient<ICookStorage, CookStorage>();
services.AddTransient<IMenuStorage, MenuStorage>();
services.AddTransient<IPlaceStorage, PlaceStorage>();
services.AddTransient<ITaskStorage, TaskStorage>();
services.AddTransient<IBuyerLogic, BuyerLogic>();
services.AddTransient<ICookLogic, CookLogic>();
services.AddTransient<IMenuLogic, MenuLogic>();
services.AddTransient<IPlaceLogic, PlaceLogic>();
services.AddTransient<ITaskLogic, TaskLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormBuyers>();
services.AddTransient<FormBuyer>();
services.AddTransient<FormCooks>();
services.AddTransient<FormCook>();
services.AddTransient<FormPlace>();
services.AddTransient<FormPlaces>();
services.AddTransient<FormMenus>();
services.AddTransient<FormMenu>();
services.AddTransient<FormCreateTask>();
services.AddTransient<FormTaskMenu>();
}
}
}

View File

@ -8,4 +8,21 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -74,6 +74,37 @@ namespace SushiBarBusinessLogic.BusinessLogics
return true;
}
public bool DeliveryTask(TaskBindingModel model)
{
return StatusUpdate(model, SushiBarDataModels.Enum.TaskStatus.Выдан);
}
public bool FinishTask(TaskBindingModel model)
{
return StatusUpdate(model, SushiBarDataModels.Enum.TaskStatus.Готов);
}
public bool TakeTaskInWork(TaskBindingModel model)
{
return StatusUpdate(model, SushiBarDataModels.Enum.TaskStatus.Выполняется);
}
private bool StatusUpdate(TaskBindingModel model, SushiBarDataModels.Enum.TaskStatus newStatus)
{
if (model.Status + 1 != newStatus)
{
return false;
}
model.Status = newStatus;
if (_taskStorage.Update(model) == null)
{
model.Status--;
return false;
}
return true;
}
private void CheckModel(TaskBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -23,7 +23,7 @@ namespace SushiBarContracts.BindingModels
public int BuyerId { get; set; }
public int MenuId { get; set; }
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new();
}
}

View File

@ -17,5 +17,8 @@ namespace SushiBarContracts.BusinessLogicContracts
bool Create(TaskBindingModel model);
bool Update(TaskBindingModel model);
bool Delete(TaskBindingModel model);
bool TakeTaskInWork(TaskBindingModel model);
bool FinishTask(TaskBindingModel model);
bool DeliveryTask(TaskBindingModel model);
}
}

View File

@ -15,7 +15,7 @@ namespace SushiBarContracts.ViewModels
[DisplayName("Имя покупателя")]
public string BuyerName { get; set; } = string.Empty;
[DisplayName("Статус")]
[DisplayName("День рождения")]
public DateTime? BuyerBirthDate { get; set; }
}
}

View File

@ -18,10 +18,13 @@ namespace SushiBarContracts.ViewModels
[DisplayName("Фамилия повара")]
public string CookSurname { get; set; } = string.Empty;
[DisplayName("Опыт работы")]
public int Experience { get; set; }
[DisplayName("Номер телефона")]
public string PhoneNumber { get; set; } = string.Empty;
[DisplayName("Номер паспорта")]
public string Passport { get; set; } = string.Empty;
}

View File

@ -1,6 +1,7 @@
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,8 +12,10 @@ namespace SushiBarContracts.ViewModels
{
public int Id { get; set; }
[DisplayName("Номер столика")]
public int PlaceNumber { get; set; }
[DisplayName("Кол-во мест")]
public int CountPlaces { get; set; }
}
}

View File

@ -14,7 +14,7 @@ namespace SushiBarContracts.ViewModels
public int Id { get; set; }
[DisplayName("Дата заказа")]
public DateTime TaskDate { get; set; }
public DateTime TaskDate { get; set; } = DateTime.Now;
[DisplayName("Статус заказа")]
public SushiBarDataModels.Enum.TaskStatus Status { get; set; }
@ -28,6 +28,6 @@ namespace SushiBarContracts.ViewModels
public int BuyerId { get; set; }
public int MenuId { get; set; }
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new();
}
}

View File

@ -11,6 +11,6 @@ namespace SushiBarDataModels.Models
int CookId { get; }
int BuyerId { get; }
int MenuId { get; }
Dictionary<int, (IMenuModel, int)> TaskMenus { get; }
}
}

View File

@ -0,0 +1,78 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class BuyerStorage : IBuyerStorage
{
public List<BuyerViewModel> GetFilteredList(BuyerSearchModel model)
{
if (string.IsNullOrEmpty(model.BuyerName))
{
return new();
}
using var context = new SushiBarDatabase();
return context.Buyers.Where(x => x.BuyerName.Contains(model.BuyerName)).Select(x => x.GetViewModel).ToList();
}
public List<BuyerViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Buyers.Select(x=>x.GetViewModel).ToList();
}
public BuyerViewModel? Delete(BuyerBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.Buyers.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Buyers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public BuyerViewModel? GetElement(BuyerSearchModel model)
{
using var context = new SushiBarDatabase();
return context.Buyers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuyerName)) && x.BuyerName == model.BuyerName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public BuyerViewModel? Insert(BuyerBindingModel model)
{
var newBuyer = Buyer.Create(model);
if (newBuyer == null)
{
return null;
}
using var context = new SushiBarDatabase();
context.Buyers.Add(newBuyer);
context.SaveChanges();
return newBuyer.GetViewModel;
}
public BuyerViewModel? Update(BuyerBindingModel model)
{
using var context = new SushiBarDatabase();
var component = context.Buyers.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,78 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class CookStorage : ICookStorage
{
public CookViewModel? Delete(CookBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.Cooks.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Cooks.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public CookViewModel? GetElement(CookSearchModel model)
{
using var context = new SushiBarDatabase();
return context.Cooks.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CookName)) && x.CookName == model.CookName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<CookViewModel> GetFilteredList(CookSearchModel model)
{
if (string.IsNullOrEmpty(model.CookName))
{
return new();
}
using var context = new SushiBarDatabase();
return context.Cooks.Where(x => x.CookName.Contains(model.CookName)).Select(x => x.GetViewModel).ToList();
}
public List<CookViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Cooks.Select(x => x.GetViewModel).ToList();
}
public CookViewModel? Insert(CookBindingModel model)
{
var newCook = Cook.Create(model);
if (newCook == null)
{
return null;
}
using var context = new SushiBarDatabase();
context.Cooks.Add(newCook);
context.SaveChanges();
return newCook.GetViewModel;
}
public CookViewModel? Update(CookBindingModel model)
{
using var context = new SushiBarDatabase();
var component = context.Cooks.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,78 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class MenuStorage : IMenuStorage
{
public MenuViewModel? Delete(MenuBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.Menus.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Menus.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public MenuViewModel? GetElement(MenuSearchModel model)
{
using var context = new SushiBarDatabase();
return context.Menus.FirstOrDefault(x => (!string.IsNullOrEmpty(model.FoodName)) && x.FoodName == model.FoodName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<MenuViewModel> GetFilteredList(MenuSearchModel model)
{
if (string.IsNullOrEmpty(model.FoodName))
{
return new();
}
using var context = new SushiBarDatabase();
return context.Menus.Where(x => x.FoodName.Contains(model.FoodName)).Select(x => x.GetViewModel).ToList();
}
public List<MenuViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Menus.Select(x => x.GetViewModel).ToList();
}
public MenuViewModel? Insert(MenuBindingModel model)
{
var newMenu = Menu.Create(model);
if (newMenu == null)
{
return null;
}
using var context = new SushiBarDatabase();
context.Menus.Add(newMenu);
context.SaveChanges();
return newMenu.GetViewModel;
}
public MenuViewModel? Update(MenuBindingModel model)
{
using var context = new SushiBarDatabase();
var component = context.Menus.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,78 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class PlaceStorage : IPlaceStorage
{
public PlaceViewModel? Delete(PlaceBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.Places.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Places.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public PlaceViewModel? GetElement(PlaceSearchModel model)
{
using var context = new SushiBarDatabase();
return context.Places.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PlaceNumber.ToString())) && x.PlaceNumber.ToString() == model.PlaceNumber.ToString() || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<PlaceViewModel> GetFilteredList(PlaceSearchModel model)
{
if (string.IsNullOrEmpty(model.PlaceNumber.ToString()))
{
return new();
}
using var context = new SushiBarDatabase();
return context.Places.Where(x => x.PlaceNumber.ToString().Contains(model.PlaceNumber.ToString())).Select(x => x.GetViewModel).ToList();
}
public List<PlaceViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Places.Select(x => x.GetViewModel).ToList();
}
public PlaceViewModel? Insert(PlaceBindingModel model)
{
var newPlace = Place.Create(model);
if (newPlace == null)
{
return null;
}
using var context = new SushiBarDatabase();
context.Places.Add(newPlace);
context.SaveChanges();
return newPlace.GetViewModel;
}
public PlaceViewModel? Update(PlaceBindingModel model)
{
using var context = new SushiBarDatabase();
var component = context.Places.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,88 @@
using Microsoft.EntityFrameworkCore;
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class TaskStorage : ITaskStorage
{
public TaskViewModel? Delete(TaskBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.Tasks.Include(x => x.Menus).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Tasks.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public TaskViewModel? GetElement(TaskSearchModel model)
{
using var context = new SushiBarDatabase();
return context.Tasks.Include(x => x.Menus).ThenInclude(x => x.Menu).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<TaskViewModel> GetFilteredList(TaskSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new SushiBarDatabase();
return context.Tasks.Include(x => x.Menus).ThenInclude(x => x.Menu).Where(x => x.Id == model.Id).ToList().Select(x => x.GetViewModel).ToList();
}
public List<TaskViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Tasks.Include(x => x.Menus).ThenInclude(x => x.Menu).ToList().Select(x => x.GetViewModel).ToList();
}
public TaskViewModel? Insert(TaskBindingModel model)
{
using var context = new SushiBarDatabase();
var newTask = Models.Task.Create(context, model);
if (newTask == null)
{
return null;
}
context.Tasks.Add(newTask);
context.SaveChanges();
return newTask.GetViewModel;
}
public TaskViewModel? Update(TaskBindingModel model)
{
using var context = new SushiBarDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var task = context.Tasks.FirstOrDefault(x => x.Id == model.Id);
if (task == null)
{
return null;
}
task.Update(model);
context.SaveChanges();
//task.UpdateMenus(context, model);
transaction.Commit();
return task.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,211 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SushiBarDatabaseImplement;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
[Migration("20240326181255_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime?>("BuyerBirthDate")
.HasColumnType("datetime2");
b.Property<string>("BuyerName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Buyers");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Cook", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CookName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("CookSurname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Experience")
.HasColumnType("int");
b.Property<string>("Passport")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Cooks");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Menu", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FoodName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Menus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Place", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CountPlaces")
.HasColumnType("int");
b.Property<int>("PlaceNumber")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Places");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Task", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId")
.HasColumnType("int");
b.Property<int>("CookId")
.HasColumnType("int");
b.Property<double>("FullPrice")
.HasColumnType("float");
b.Property<int>("PlaceId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<DateTime>("TaskDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Tasks");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.TaskMenu", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MenuId")
.HasColumnType("int");
b.Property<int>("TaskId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MenuId");
b.HasIndex("TaskId");
b.ToTable("TaskMenus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.TaskMenu", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Menu", "Menu")
.WithMany("TaskMenus")
.HasForeignKey("MenuId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Task", "Task")
.WithMany("Menus")
.HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Menu");
b.Navigation("Task");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Menu", b =>
{
b.Navigation("TaskMenus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Task", b =>
{
b.Navigation("Menus");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,152 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Buyers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BuyerName = table.Column<string>(type: "nvarchar(max)", nullable: false),
BuyerBirthDate = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Buyers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Cooks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CookName = table.Column<string>(type: "nvarchar(max)", nullable: false),
CookSurname = table.Column<string>(type: "nvarchar(max)", nullable: false),
Experience = table.Column<int>(type: "int", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
Passport = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cooks", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Menus",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FoodName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Menus", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Places",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlaceNumber = table.Column<int>(type: "int", nullable: false),
CountPlaces = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Places", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Tasks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TaskDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
FullPrice = table.Column<double>(type: "float", nullable: false),
PlaceId = table.Column<int>(type: "int", nullable: false),
CookId = table.Column<int>(type: "int", nullable: false),
BuyerId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tasks", x => x.Id);
});
migrationBuilder.CreateTable(
name: "TaskMenus",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TaskId = table.Column<int>(type: "int", nullable: false),
MenuId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TaskMenus", x => x.Id);
table.ForeignKey(
name: "FK_TaskMenus_Menus_MenuId",
column: x => x.MenuId,
principalTable: "Menus",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TaskMenus_Tasks_TaskId",
column: x => x.TaskId,
principalTable: "Tasks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_TaskMenus_MenuId",
table: "TaskMenus",
column: "MenuId");
migrationBuilder.CreateIndex(
name: "IX_TaskMenus_TaskId",
table: "TaskMenus",
column: "TaskId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Buyers");
migrationBuilder.DropTable(
name: "Cooks");
migrationBuilder.DropTable(
name: "Places");
migrationBuilder.DropTable(
name: "TaskMenus");
migrationBuilder.DropTable(
name: "Menus");
migrationBuilder.DropTable(
name: "Tasks");
}
}
}

View File

@ -0,0 +1,208 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SushiBarDatabaseImplement;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
partial class SushiBarDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Buyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime?>("BuyerBirthDate")
.HasColumnType("datetime2");
b.Property<string>("BuyerName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Buyers");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Cook", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CookName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("CookSurname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Experience")
.HasColumnType("int");
b.Property<string>("Passport")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Cooks");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Menu", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FoodName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Menus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Place", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CountPlaces")
.HasColumnType("int");
b.Property<int>("PlaceNumber")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Places");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Task", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId")
.HasColumnType("int");
b.Property<int>("CookId")
.HasColumnType("int");
b.Property<double>("FullPrice")
.HasColumnType("float");
b.Property<int>("PlaceId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<DateTime>("TaskDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Tasks");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.TaskMenu", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MenuId")
.HasColumnType("int");
b.Property<int>("TaskId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MenuId");
b.HasIndex("TaskId");
b.ToTable("TaskMenus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.TaskMenu", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Menu", "Menu")
.WithMany("TaskMenus")
.HasForeignKey("MenuId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Task", "Task")
.WithMany("Menus")
.HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Menu");
b.Navigation("Task");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Menu", b =>
{
b.Navigation("TaskMenus");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Task", b =>
{
b.Navigation("Menus");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,49 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class Buyer : IBuyerModel
{
public int Id { get; set; }
[Required]
public string BuyerName { get; set; } = string.Empty;
public DateTime? BuyerBirthDate { get; set; }
public static Buyer? Create(BuyerBindingModel model)
{
if (model == null) return null;
return new Buyer()
{
Id = model.Id,
BuyerName = model.BuyerName,
BuyerBirthDate = model.BuyerBirthDate
};
}
public void Update(BuyerBindingModel model)
{
if(model == null) return;
BuyerName = model.BuyerName;
BuyerBirthDate = model.BuyerBirthDate;
}
public BuyerViewModel GetViewModel => new()
{
Id = Id,
BuyerName = BuyerName,
BuyerBirthDate = BuyerBirthDate
};
}
}

View File

@ -0,0 +1,65 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class Cook : ICookModel
{
public int Id { get; set; }
[Required]
public string CookName { get; set; } = string.Empty;
[Required]
public string CookSurname { get; set; } = string.Empty;
public int Experience { get; set; }
[Required]
public string PhoneNumber { get; set; } = string.Empty;
[Required]
public string Passport { get; set; } = string.Empty;
public static Cook? Create(CookBindingModel model)
{
if (model == null) return null;
return new Cook()
{
Id = model.Id,
CookName = model.CookName,
CookSurname = model.CookSurname,
Experience = model.Experience,
PhoneNumber = model.PhoneNumber,
Passport = model.Passport
};
}
public void Update(CookBindingModel model)
{
if (model == null) return;
CookName = model.CookName;
CookSurname = model.CookSurname;
Experience = model.Experience;
PhoneNumber = model.PhoneNumber;
Passport = model.Passport;
}
public CookViewModel GetViewModel => new()
{
Id = Id,
CookName = CookName,
CookSurname = CookSurname,
Experience = Experience,
PhoneNumber = PhoneNumber,
Passport = Passport
};
}
}

View File

@ -0,0 +1,57 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class Menu : IMenuModel
{
public int Id { get; set; }
[Required]
public string FoodName { get; set; } = string.Empty;
[Required]
public string Description { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[ForeignKey("MenuId")]
public virtual List<TaskMenu> TaskMenus { get; set; } = new();
public static Menu? Create(MenuBindingModel model)
{
if (model == null) return null;
return new Menu()
{
Id = model.Id,
FoodName = model.FoodName,
Description = model.Description,
Price = model.Price
};
}
public void Update(MenuBindingModel model)
{
if (model == null) return;
Id = model.Id;
FoodName = model.FoodName;
Description = model.Description;
Price = model.Price;
}
public MenuViewModel GetViewModel => new()
{
Id = Id,
FoodName = FoodName,
Description = Description,
Price = Price
};
}
}

View File

@ -0,0 +1,50 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class Place : IPlaceModel
{
[Required]
public int Id { get; set; }
[Required]
public int PlaceNumber { get; set; }
[Required]
public int CountPlaces { get; set; }
public static Place? Create(PlaceBindingModel model)
{
if (model == null)
{
return null;
}
return new Place()
{
Id = model.Id,
PlaceNumber = model.PlaceNumber,
CountPlaces = model.CountPlaces
};
}
public void Update(PlaceBindingModel model)
{
if (model == null) return;
PlaceNumber = model.PlaceNumber;
CountPlaces = model.CountPlaces;
}
public PlaceViewModel GetViewModel => new()
{
Id = Id,
PlaceNumber = PlaceNumber,
CountPlaces = CountPlaces
};
}
}

View File

@ -0,0 +1,116 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class Task : ITaskModel
{
public int Id { get; set; }
[Required]
public DateTime TaskDate { get; set; }
[Required]
public SushiBarDataModels.Enum.TaskStatus Status { get; set; }
[Required]
public double FullPrice { get; set; }
public int PlaceId { get; set; }
public int CookId { get; set; }
public int BuyerId { get; set; }
private Dictionary<int, (IMenuModel, int)>? _taskMenu = null;
[NotMapped]
public Dictionary<int, (IMenuModel, int)> TaskMenus
{
get
{
if(_taskMenu == null)
{
_taskMenu = Menus.ToDictionary(recTM => recTM.MenuId, recTM => (recTM.Menu as IMenuModel, recTM.Count));
}
return _taskMenu;
}
}
[ForeignKey("TaskId")]
public virtual List<TaskMenu> Menus { get; set; } = new();
public static Task Create(SushiBarDatabase context, TaskBindingModel model)
{
return new Task()
{
Id = model.Id,
TaskDate = model.TaskDate,
Status = model.Status,
FullPrice = model.FullPrice,
PlaceId = model.PlaceId,
CookId = model.CookId,
BuyerId = model.BuyerId,
Menus = model.TaskMenus.Select(x => new TaskMenu
{
Menu = context.Menus.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList(),
};
}
public void Update(TaskBindingModel model)
{
Status = model.Status;
}
public TaskViewModel GetViewModel => new()
{
Id = Id,
TaskDate = TaskDate,
Status = Status,
FullPrice = FullPrice,
PlaceId = PlaceId,
CookId = CookId,
BuyerId = BuyerId,
TaskMenus = TaskMenus
};
public void UpdateMenus(SushiBarDatabase context, TaskBindingModel model)
{
var taskMenus = context.TaskMenus.Where(rec => rec.TaskId == model.Id).ToList();
if(taskMenus != null && taskMenus.Count > 0)
{
context.TaskMenus.RemoveRange(taskMenus.Where(rec => !model.TaskMenus.ContainsKey(rec.MenuId)));
context.SaveChanges();
foreach(var updateMenu in taskMenus)
{
updateMenu.Count = model.TaskMenus[updateMenu.MenuId].Item2;
model.TaskMenus.Remove(updateMenu.MenuId);
}
context.SaveChanges();
}
var task = context.Tasks.First(x => x.Id == Id);
foreach(var rc in model.TaskMenus)
{
context.TaskMenus.Add(new TaskMenu
{
Task = task,
Menu = context.Menus.First(x => x.Id == rc.Key),
Count = rc.Value.Item2
});
context.SaveChanges();
}
_taskMenu = null;
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Models
{
public class TaskMenu
{
public int Id { get; set; }
public int TaskId { get; set; }
public int MenuId { get; set; }
public int Count { get; set; }
public virtual Task Task { get; set; } = new();
public virtual Menu Menu { get; set; } = new();
}
}

View File

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using SushiBarDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement
{
public class SushiBarDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Buyer> Buyers { get; set; }
public virtual DbSet<Cook> Cooks { get; set; }
public virtual DbSet<Menu> Menus { get; set; }
public virtual DbSet<Place> Places { get; set; }
public virtual DbSet<Models.Task> Tasks { get; set; }
public virtual DbSet<TaskMenu> TaskMenus { get; set; }
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
</Project>