Compare commits
34 Commits
main
...
LabWork03_
Author | SHA1 | Date | |
---|---|---|---|
0310304ff0 | |||
a52ff0cd2e | |||
5fd94d55b9 | |||
e191d9a0cf | |||
cb2cd56fd8 | |||
9a711e04ce | |||
18de1f0149 | |||
e59ed7e076 | |||
242d9ab771 | |||
fad8c6d061 | |||
992bc106c7 | |||
02fbbaf391 | |||
808e702f0b | |||
ff05be5be1 | |||
8469bc6a42 | |||
b64d65bb18 | |||
a023b4f508 | |||
5e9a55f818 | |||
0cb0e4c667 | |||
5d03ab2080 | |||
ebc772cb55 | |||
3155cd0b0d | |||
d9db072c47 | |||
d627ca6623 | |||
e692d5d442 | |||
538b903af4 | |||
cdf691d078 | |||
2093186453 | |||
fa639ce8b4 | |||
52ba95b50e | |||
80eb3374b1 | |||
dea2ccc826 | |||
f5db27a124 | |||
5bf198916e |
@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32825.248
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{086CB019-AA3B-425A-87B0-26662D1F201F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{086CB019-AA3B-425A-87B0-26662D1F201F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{404B251B-7B48-4648-99B4-7E99EDB05A6C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{C58840E6-D68D-476E-AB3A-EB13F1740FC8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopFileImplement", "FlowerShopFileImplement\FlowerShopFileImplement.csproj", "{87156689-2FDA-4065-90CC-749B2FE3C0D6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDatabaseImplement", "FlowerShopDatabaseImplement\FlowerShopDatabaseImplement.csproj", "{77B5E3FA-7A48-41AD-BB77-6EBF273550AC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +27,30 @@ Global
|
||||
{086CB019-AA3B-425A-87B0-26662D1F201F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{086CB019-AA3B-425A-87B0-26662D1F201F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{086CB019-AA3B-425A-87B0-26662D1F201F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FDC31847-CB24-4EBD-8CE5-852ED404CEAE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{404B251B-7B48-4648-99B4-7E99EDB05A6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D8084C04-7B2B-4C8D-A63A-71A3EE1BC065}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C58840E6-D68D-476E-AB3A-EB13F1740FC8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{87156689-2FDA-4065-90CC-749B2FE3C0D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{87156689-2FDA-4065-90CC-749B2FE3C0D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{87156689-2FDA-4065-90CC-749B2FE3C0D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{87156689-2FDA-4065-90CC-749B2FE3C0D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{77B5E3FA-7A48-41AD-BB77-6EBF273550AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{77B5E3FA-7A48-41AD-BB77-6EBF273550AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{77B5E3FA-7A48-41AD-BB77-6EBF273550AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{77B5E3FA-7A48-41AD-BB77-6EBF273550AC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -8,4 +8,22 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopDatabaseImplement\FlowerShopDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopFileImplement\FlowerShopFileImplement.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopListImplement\FlowerShopListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
39
FlowerShop/FlowerShop/Form1.Designer.cs
generated
39
FlowerShop/FlowerShop/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?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>
|
235
FlowerShop/FlowerShop/FormBouquet.Designer.cs
generated
Normal file
235
FlowerShop/FlowerShop/FormBouquet.Designer.cs
generated
Normal file
@ -0,0 +1,235 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormBouquet
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelPrice = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||
this.groupBoxComponent = new System.Windows.Forms.GroupBox();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.groupBoxComponent.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(13, 11);
|
||||
this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
this.labelPrice.AutoSize = true;
|
||||
this.labelPrice.Location = new System.Drawing.Point(13, 40);
|
||||
this.labelPrice.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelPrice.Name = "labelPrice";
|
||||
this.labelPrice.Size = new System.Drawing.Size(73, 15);
|
||||
this.labelPrice.TabIndex = 1;
|
||||
this.labelPrice.Text = "Стоимость: ";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(83, 10);
|
||||
this.textBoxName.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(239, 23);
|
||||
this.textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
this.textBoxPrice.Location = new System.Drawing.Point(83, 37);
|
||||
this.textBoxPrice.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxPrice.Name = "textBoxPrice";
|
||||
this.textBoxPrice.Size = new System.Drawing.Size(106, 23);
|
||||
this.textBoxPrice.TabIndex = 3;
|
||||
//
|
||||
// groupBoxComponent
|
||||
//
|
||||
this.groupBoxComponent.Controls.Add(this.buttonUpdate);
|
||||
this.groupBoxComponent.Controls.Add(this.buttonDelete);
|
||||
this.groupBoxComponent.Controls.Add(this.buttonChange);
|
||||
this.groupBoxComponent.Controls.Add(this.buttonAdd);
|
||||
this.groupBoxComponent.Controls.Add(this.dataGridView);
|
||||
this.groupBoxComponent.Location = new System.Drawing.Point(10, 65);
|
||||
this.groupBoxComponent.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxComponent.Name = "groupBoxComponent";
|
||||
this.groupBoxComponent.Padding = new System.Windows.Forms.Padding(2);
|
||||
this.groupBoxComponent.Size = new System.Drawing.Size(534, 198);
|
||||
this.groupBoxComponent.TabIndex = 4;
|
||||
this.groupBoxComponent.TabStop = false;
|
||||
this.groupBoxComponent.Text = "Компоненты";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(433, 122);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(78, 30);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(433, 88);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(78, 30);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(433, 54);
|
||||
this.buttonChange.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(78, 30);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(433, 20);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(78, 30);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ColumnComponent,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Location = new System.Drawing.Point(18, 18);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(388, 169);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ColumnComponent
|
||||
//
|
||||
this.ColumnComponent.HeaderText = "Компонент";
|
||||
this.ColumnComponent.MinimumWidth = 8;
|
||||
this.ColumnComponent.Name = "ColumnComponent";
|
||||
this.ColumnComponent.Width = 150;
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
this.ColumnCount.HeaderText = "Количество";
|
||||
this.ColumnCount.MinimumWidth = 8;
|
||||
this.ColumnCount.Name = "ColumnCount";
|
||||
this.ColumnCount.Width = 150;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(329, 267);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonSave.TabIndex = 5;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(420, 267);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonCancel.TabIndex = 6;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormBouquet
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(560, 297);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.groupBoxComponent);
|
||||
this.Controls.Add(this.textBoxPrice);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelPrice);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormBouquet";
|
||||
this.Text = "Букет";
|
||||
this.Load += new System.EventHandler(this.BouquetForm_Load);
|
||||
this.groupBoxComponent.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelPrice;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxPrice;
|
||||
private GroupBox groupBoxComponent;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDelete;
|
||||
private Button buttonChange;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridViewTextBoxColumn ColumnComponent;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
222
FlowerShop/FlowerShop/FormBouquet.cs
Normal file
222
FlowerShop/FlowerShop/FormBouquet.cs
Normal file
@ -0,0 +1,222 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormBouquet : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetLogic _logic;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IComponentModel, int)> _bouquetComponents;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormBouquet(ILogger<FormBouquet> logger, IBouquetLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_bouquetComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
}
|
||||
|
||||
private void BouquetForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Receving bouquet");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new BouquetSearchModel { Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.BouquetName;
|
||||
textBoxPrice.Text = view.Price.ToString();
|
||||
_bouquetComponents = view.BouquetComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving bouquet");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонент изделия");
|
||||
try
|
||||
{
|
||||
if (_bouquetComponents != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _bouquetComponents)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||
}
|
||||
textBoxPrice.Text = CalcPrice().ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormBouquetComponent));
|
||||
if (service is FormBouquetComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
|
||||
if (_bouquetComponents.ContainsKey(form.Id))
|
||||
{
|
||||
_bouquetComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_bouquetComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormBouquetComponent));
|
||||
if (service is FormBouquetComponent form)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
form.Id = id;
|
||||
form.Count = _bouquetComponents[id].Item2;
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
_bouquetComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||
_bouquetComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_bouquetComponents == null || _bouquetComponents.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Saving bouquet");
|
||||
try
|
||||
{
|
||||
var model = new BouquetBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
BouquetName = textBoxName.Text,
|
||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||
BouquetComponents = _bouquetComponents
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error during saving");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during saving bouquet");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private double CalcPrice()
|
||||
{
|
||||
double price = 0;
|
||||
|
||||
foreach (var elem in _bouquetComponents)
|
||||
{
|
||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||
}
|
||||
|
||||
return Math.Round(price * 1.1, 2);
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormBouquet.resx
Normal file
60
FlowerShop/FlowerShop/FormBouquet.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
126
FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs
generated
Normal file
126
FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs
generated
Normal file
@ -0,0 +1,126 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormBouquetComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.labelComponent = new System.Windows.Forms.Label();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxComponent
|
||||
//
|
||||
this.comboBoxComponent.FormattingEnabled = true;
|
||||
this.comboBoxComponent.Location = new System.Drawing.Point(104, 6);
|
||||
this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.comboBoxComponent.Name = "comboBoxComponent";
|
||||
this.comboBoxComponent.Size = new System.Drawing.Size(129, 23);
|
||||
this.comboBoxComponent.TabIndex = 0;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(104, 32);
|
||||
this.textBoxCount.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(129, 23);
|
||||
this.textBoxCount.TabIndex = 1;
|
||||
//
|
||||
// labelComponent
|
||||
//
|
||||
this.labelComponent.AutoSize = true;
|
||||
this.labelComponent.Location = new System.Drawing.Point(11, 11);
|
||||
this.labelComponent.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelComponent.Name = "labelComponent";
|
||||
this.labelComponent.Size = new System.Drawing.Size(69, 15);
|
||||
this.labelComponent.TabIndex = 2;
|
||||
this.labelComponent.Text = "Компонент";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(11, 34);
|
||||
this.labelCount.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelCount.TabIndex = 3;
|
||||
this.labelCount.Text = "Количество ";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(102, 61);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(184, 61);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Отменить";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormBouquetComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(273, 97);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.labelComponent);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxComponent);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormBouquetComponent";
|
||||
this.Text = "Компонент букета";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxComponent;
|
||||
private TextBox textBoxCount;
|
||||
private Label labelComponent;
|
||||
private Label labelCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
82
FlowerShop/FlowerShop/FormBouquetComponent.cs
Normal file
82
FlowerShop/FlowerShop/FormBouquetComponent.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormBouquetComponent : Form
|
||||
{
|
||||
private readonly List<ComponentViewModel>? _list;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxComponent.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IComponentModel? ComponentModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _list)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return Convert.ToInt32(textBoxCount.Text); }
|
||||
set { textBoxCount.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
public FormBouquetComponent(IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_list = logic.ReadList(null);
|
||||
if (_list != null)
|
||||
{
|
||||
comboBoxComponent.DisplayMember = "ComponentName";
|
||||
comboBoxComponent.ValueMember = "Id";
|
||||
comboBoxComponent.DataSource = _list;
|
||||
comboBoxComponent.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxComponent.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormBouquetComponent.resx
Normal file
60
FlowerShop/FlowerShop/FormBouquetComponent.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
122
FlowerShop/FlowerShop/FormBouquets.Designer.cs
generated
Normal file
122
FlowerShop/FlowerShop/FormBouquets.Designer.cs
generated
Normal file
@ -0,0 +1,122 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormBouquets
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(321, 293);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(336, 15);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(336, 44);
|
||||
this.buttonChange.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(336, 73);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(336, 102);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||
//
|
||||
// FormBouquets
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(430, 293);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonChange);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormBouquets";
|
||||
this.Text = "Букеты";
|
||||
this.Load += new System.EventHandler(this.BouquetsForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonChange;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
111
FlowerShop/FlowerShop/FormBouquets.cs
Normal file
111
FlowerShop/FlowerShop/FormBouquets.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormBouquets : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetLogic _logic;
|
||||
|
||||
public FormBouquets(ILogger<FormBouquets> logger, IBouquetLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["BouquetName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["BouquetComponents"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Receiving bouquets");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving bouquets");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormBouquet));
|
||||
|
||||
if (service is FormBouquet form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormBouquet));
|
||||
|
||||
if (service is FormBouquet form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Deleting bouquet");
|
||||
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new BouquetBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Error during deleting bouquet");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error deleting bouquet");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void BouquetsForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormBouquets.resx
Normal file
60
FlowerShop/FlowerShop/FormBouquets.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
126
FlowerShop/FlowerShop/FormComponent.Designer.cs
generated
Normal file
126
FlowerShop/FlowerShop/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,126 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelCost = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxCost = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(135, 73);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(78, 26);
|
||||
this.buttonSave.TabIndex = 0;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(227, 73);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(78, 26);
|
||||
this.buttonCancel.TabIndex = 1;
|
||||
this.buttonCancel.Text = "Отменить";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(17, 8);
|
||||
this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(59, 15);
|
||||
this.labelName.TabIndex = 2;
|
||||
this.labelName.Text = "Название";
|
||||
//
|
||||
// labelCost
|
||||
//
|
||||
this.labelCost.AutoSize = true;
|
||||
this.labelCost.Location = new System.Drawing.Point(17, 38);
|
||||
this.labelCost.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelCost.Name = "labelCost";
|
||||
this.labelCost.Size = new System.Drawing.Size(35, 15);
|
||||
this.labelCost.TabIndex = 3;
|
||||
this.labelCost.Text = "Цена";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(76, 6);
|
||||
this.textBoxName.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(208, 23);
|
||||
this.textBoxName.TabIndex = 4;
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
this.textBoxCost.Location = new System.Drawing.Point(76, 35);
|
||||
this.textBoxCost.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxCost.Name = "textBoxCost";
|
||||
this.textBoxCost.Size = new System.Drawing.Size(208, 23);
|
||||
this.textBoxCost.TabIndex = 5;
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(316, 110);
|
||||
this.Controls.Add(this.textBoxCost);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelCost);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormComponent";
|
||||
this.Text = "Компонент";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Label labelName;
|
||||
private Label labelCost;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxCost;
|
||||
}
|
||||
}
|
86
FlowerShop/FlowerShop/FormComponent.cs
Normal file
86
FlowerShop/FlowerShop/FormComponent.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Receiving component");
|
||||
|
||||
var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value });
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.ComponentName;
|
||||
textBoxCost.Text = view.Cost.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving component");
|
||||
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;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Saving component");
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ComponentName = textBoxName.Text,
|
||||
Cost = Convert.ToDouble(textBoxCost.Text)
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error during saving");
|
||||
}
|
||||
|
||||
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Îøèáêà ñîõðàíåíèÿ êîìïîíåíòà");
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormComponent.resx
Normal file
60
FlowerShop/FlowerShop/FormComponent.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
122
FlowerShop/FlowerShop/FormComponents.Designer.cs
generated
Normal file
122
FlowerShop/FlowerShop/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,122 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(321, 293);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(336, 15);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(337, 44);
|
||||
this.buttonChange.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(336, 73);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(336, 102);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(430, 293);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonChange);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.Name = "FormComponents";
|
||||
this.Text = "Компоненты";
|
||||
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonChange;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
102
FlowerShop/FlowerShop/FormComponents.cs
Normal file
102
FlowerShop/FlowerShop/FormComponents.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Receiving components");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving components");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent 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(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление компонента");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRef_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormComponents.resx
Normal file
60
FlowerShop/FlowerShop/FormComponents.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
153
FlowerShop/FlowerShop/FormCreateOrder.Designer.cs
generated
Normal file
153
FlowerShop/FlowerShop/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,153 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBoxBouquet = new System.Windows.Forms.ComboBox();
|
||||
this.labelBouquet = new System.Windows.Forms.Label();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelSum = new System.Windows.Forms.Label();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxBouquet
|
||||
//
|
||||
this.comboBoxBouquet.FormattingEnabled = true;
|
||||
this.comboBoxBouquet.Location = new System.Drawing.Point(80, 8);
|
||||
this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.comboBoxBouquet.Name = "comboBoxBouquet";
|
||||
this.comboBoxBouquet.Size = new System.Drawing.Size(176, 23);
|
||||
this.comboBoxBouquet.TabIndex = 0;
|
||||
//
|
||||
// labelBouquet
|
||||
//
|
||||
this.labelBouquet.AutoSize = true;
|
||||
this.labelBouquet.Location = new System.Drawing.Point(8, 13);
|
||||
this.labelBouquet.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelBouquet.Name = "labelBouquet";
|
||||
this.labelBouquet.Size = new System.Drawing.Size(56, 15);
|
||||
this.labelBouquet.TabIndex = 1;
|
||||
this.labelBouquet.Text = "Изделие:";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(8, 40);
|
||||
this.labelCount.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelCount.TabIndex = 2;
|
||||
this.labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelSum
|
||||
//
|
||||
this.labelSum.AutoSize = true;
|
||||
this.labelSum.Location = new System.Drawing.Point(8, 72);
|
||||
this.labelSum.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.labelSum.Name = "labelSum";
|
||||
this.labelSum.Size = new System.Drawing.Size(48, 15);
|
||||
this.labelSum.TabIndex = 3;
|
||||
this.labelSum.Text = "Сумма:";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(80, 38);
|
||||
this.textBoxCount.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(176, 23);
|
||||
this.textBoxCount.TabIndex = 4;
|
||||
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged);
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(80, 69);
|
||||
this.textBoxSum.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.ReadOnly = true;
|
||||
this.textBoxSum.Size = new System.Drawing.Size(176, 23);
|
||||
this.textBoxSum.TabIndex = 5;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(96, 97);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(178, 97);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(78, 25);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(281, 124);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.labelSum);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.labelBouquet);
|
||||
this.Controls.Add(this.comboBoxBouquet);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormCreateOrder";
|
||||
this.Text = "Заказ";
|
||||
this.Load += new System.EventHandler(this.OrderForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxBouquet;
|
||||
private Label labelBouquet;
|
||||
private Label labelCount;
|
||||
private Label labelSum;
|
||||
private TextBox textBoxCount;
|
||||
private TextBox textBoxSum;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
126
FlowerShop/FlowerShop/FormCreateOrder.cs
Normal file
126
FlowerShop/FlowerShop/FormCreateOrder.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetLogic _logicBouquet;
|
||||
private readonly IOrderLogic _logicOrder;
|
||||
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IBouquetLogic logicBouquet, IOrderLogic logicOrder)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicBouquet = logicBouquet;
|
||||
_logicOrder = logicOrder;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Receiving bouquets for order");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicBouquet.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxBouquet.DisplayMember = "BouquetName";
|
||||
comboBoxBouquet.ValueMember = "Id";
|
||||
comboBoxBouquet.DataSource = list;
|
||||
comboBoxBouquet.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving bouquets for order");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void OrderForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void CalculateSum()
|
||||
{
|
||||
if (comboBoxBouquet.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxBouquet.SelectedValue);
|
||||
var furniture = _logicBouquet.ReadElement(new BouquetSearchModel { Id = id });
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
|
||||
textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString();
|
||||
|
||||
_logger.LogInformation("Calculating order's sum");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during calculating order's sum");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalculateSum();
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxBouquet.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание заказа");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
BouquetId = Convert.ToInt32(comboBoxBouquet.SelectedValue),
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
});
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error during order creation");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during order creation");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormCreateOrder.resx
Normal file
60
FlowerShop/FlowerShop/FormCreateOrder.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
220
FlowerShop/FlowerShop/FormMain.Designer.cs
generated
Normal file
220
FlowerShop/FlowerShop/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,220 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
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()
|
||||
{
|
||||
this.buttonReady = new System.Windows.Forms.Button();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonToWork = new System.Windows.Forms.Button();
|
||||
this.buttonPut = new System.Windows.Forms.Button();
|
||||
this.buttonRefresh = new System.Windows.Forms.Button();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.buttonSupplyShop = new System.Windows.Forms.Button();
|
||||
this.buttonSellBouquets = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonReady
|
||||
//
|
||||
this.buttonReady.Location = new System.Drawing.Point(891, 99);
|
||||
this.buttonReady.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonReady.Name = "buttonReady";
|
||||
this.buttonReady.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonReady.TabIndex = 3;
|
||||
this.buttonReady.Text = "Заказ готов";
|
||||
this.buttonReady.UseVisualStyleBackColor = true;
|
||||
this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(6, 31);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(859, 359);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Location = new System.Drawing.Point(891, 31);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
this.buttonCreate.Text = "Создать заказ";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
//
|
||||
// buttonToWork
|
||||
//
|
||||
this.buttonToWork.Location = new System.Drawing.Point(891, 65);
|
||||
this.buttonToWork.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonToWork.Name = "buttonToWork";
|
||||
this.buttonToWork.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonToWork.TabIndex = 2;
|
||||
this.buttonToWork.Text = "Отдать на выполнение";
|
||||
this.buttonToWork.UseVisualStyleBackColor = true;
|
||||
this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click);
|
||||
//
|
||||
// buttonPut
|
||||
//
|
||||
this.buttonPut.Location = new System.Drawing.Point(891, 133);
|
||||
this.buttonPut.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonPut.Name = "buttonPut";
|
||||
this.buttonPut.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonPut.TabIndex = 4;
|
||||
this.buttonPut.Text = "Заказ выдан";
|
||||
this.buttonPut.UseVisualStyleBackColor = true;
|
||||
this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click);
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(891, 167);
|
||||
this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonRefresh.Name = "buttonRefresh";
|
||||
this.buttonRefresh.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonRefresh.TabIndex = 5;
|
||||
this.buttonRefresh.Text = "Обновить список";
|
||||
this.buttonRefresh.UseVisualStyleBackColor = true;
|
||||
this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.guidesToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1);
|
||||
this.menuStrip.Size = new System.Drawing.Size(1071, 24);
|
||||
this.menuStrip.TabIndex = 6;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// guidesToolStripMenuItem
|
||||
//
|
||||
this.guidesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.componentsToolStripMenuItem,
|
||||
this.bouquetsToolStripMenuItem,
|
||||
this.shopsToolStripMenuItem});
|
||||
this.guidesToolStripMenuItem.Name = "guidesToolStripMenuItem";
|
||||
this.guidesToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
|
||||
this.guidesToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// componentsToolStripMenuItem
|
||||
//
|
||||
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.componentsToolStripMenuItem.Text = "Компоненты";
|
||||
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click);
|
||||
//
|
||||
// bouquetsToolStripMenuItem
|
||||
//
|
||||
this.bouquetsToolStripMenuItem.Name = "bouquetsToolStripMenuItem";
|
||||
this.bouquetsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.bouquetsToolStripMenuItem.Text = "Букеты";
|
||||
this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click);
|
||||
//
|
||||
// shopsToolStripMenuItem
|
||||
//
|
||||
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
|
||||
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.shopsToolStripMenuItem.Text = "Магазины";
|
||||
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
|
||||
//
|
||||
// buttonSupplyShop
|
||||
//
|
||||
this.buttonSupplyShop.Location = new System.Drawing.Point(891, 202);
|
||||
this.buttonSupplyShop.Name = "buttonSupplyShop";
|
||||
this.buttonSupplyShop.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonSupplyShop.TabIndex = 7;
|
||||
this.buttonSupplyShop.Text = "Пополнение магазина";
|
||||
this.buttonSupplyShop.UseVisualStyleBackColor = true;
|
||||
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
|
||||
//
|
||||
// buttonSellBouquets
|
||||
//
|
||||
this.buttonSellBouquets.Location = new System.Drawing.Point(891, 238);
|
||||
this.buttonSellBouquets.Name = "buttonSellBouquets";
|
||||
this.buttonSellBouquets.Size = new System.Drawing.Size(150, 30);
|
||||
this.buttonSellBouquets.TabIndex = 8;
|
||||
this.buttonSellBouquets.Text = "Продажа букетов";
|
||||
this.buttonSellBouquets.UseVisualStyleBackColor = true;
|
||||
this.buttonSellBouquets.Click += new System.EventHandler(this.buttonSellBouquets_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1071, 401);
|
||||
this.Controls.Add(this.buttonSellBouquets);
|
||||
this.Controls.Add(this.buttonSupplyShop);
|
||||
this.Controls.Add(this.buttonRefresh);
|
||||
this.Controls.Add(this.buttonPut);
|
||||
this.Controls.Add(this.buttonReady);
|
||||
this.Controls.Add(this.buttonToWork);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Цветочный магазин";
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCreate;
|
||||
private Button buttonToWork;
|
||||
private Button buttonPut;
|
||||
private Button buttonRefresh;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem guidesToolStripMenuItem;
|
||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||
private ToolStripMenuItem bouquetsToolStripMenuItem;
|
||||
private Button buttonReady;
|
||||
private ToolStripMenuItem shopsToolStripMenuItem;
|
||||
private Button buttonSupplyShop;
|
||||
private Button buttonSellBouquets;
|
||||
}
|
||||
}
|
184
FlowerShop/FlowerShop/FormMain.cs
Normal file
184
FlowerShop/FlowerShop/FormMain.cs
Normal file
@ -0,0 +1,184 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["BouquetId"].Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during receiving orders");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void bouquetsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormBouquets));
|
||||
|
||||
if (service is FormBouquets form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonToWork_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Changing status to 'Processing'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
_logger.LogError("Error during changing order's status to 'Processing'");
|
||||
MessageBox.Show("Заказ должен быть в состоянии 'Принят'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during changing order's status to 'Processing'");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonReady_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Changing status to 'Ready'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||
if (!operationResult)
|
||||
{
|
||||
_logger.LogError("Error during changing order's status to 'Ready'");
|
||||
MessageBox.Show("Заказ должен быть в состоянии 'Выполняется'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during changing order's status to 'Ready'");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonPut_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Order №{id}. Changing status to 'Delivered'", id);
|
||||
try
|
||||
{
|
||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
_logger.LogError("Error during changing order's status to 'Delivered'");
|
||||
MessageBox.Show("Заказ должен быть в состоянии 'Готов'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during changing order's status to 'Delivered'");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
|
||||
if (service is FormShops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSupplyShop_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
|
||||
if (service is FormShopSupply form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSellBouquets_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
FlowerShop/FlowerShop/FormMain.resx
Normal file
63
FlowerShop/FlowerShop/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
216
FlowerShop/FlowerShop/FormShop.Designer.cs
generated
Normal file
216
FlowerShop/FlowerShop/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,216 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormShop
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.textBoxAddress = new System.Windows.Forms.TextBox();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.labelAddress = new System.Windows.Forms.Label();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnBouquetName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.openDateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
this.openDateLabel = new System.Windows.Forms.Label();
|
||||
this.maxCountLabel = new System.Windows.Forms.Label();
|
||||
this.textBoxMaxCount = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
this.textBoxAddress.Location = new System.Drawing.Point(88, 34);
|
||||
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxAddress.Name = "textBoxAddress";
|
||||
this.textBoxAddress.Size = new System.Drawing.Size(276, 23);
|
||||
this.textBoxAddress.TabIndex = 7;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(88, 9);
|
||||
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(276, 23);
|
||||
this.textBoxName.TabIndex = 6;
|
||||
//
|
||||
// labelAddress
|
||||
//
|
||||
this.labelAddress.AutoSize = true;
|
||||
this.labelAddress.Location = new System.Drawing.Point(12, 38);
|
||||
this.labelAddress.Name = "labelAddress";
|
||||
this.labelAddress.Size = new System.Drawing.Size(43, 15);
|
||||
this.labelAddress.TabIndex = 5;
|
||||
this.labelAddress.Text = "Адрес:";
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(12, 11);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||
this.labelName.TabIndex = 4;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ColumnId,
|
||||
this.ColumnBouquetName,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Location = new System.Drawing.Point(13, 133);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(351, 224);
|
||||
this.dataGridView.TabIndex = 10;
|
||||
//
|
||||
// ColumnId
|
||||
//
|
||||
this.ColumnId.HeaderText = "ID";
|
||||
this.ColumnId.MinimumWidth = 6;
|
||||
this.ColumnId.Name = "ColumnId";
|
||||
this.ColumnId.Visible = false;
|
||||
this.ColumnId.Width = 125;
|
||||
//
|
||||
// ColumnBouquetName
|
||||
//
|
||||
this.ColumnBouquetName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.ColumnBouquetName.HeaderText = "Букет";
|
||||
this.ColumnBouquetName.MinimumWidth = 6;
|
||||
this.ColumnBouquetName.Name = "ColumnBouquetName";
|
||||
//
|
||||
// ColumnCount
|
||||
//
|
||||
this.ColumnCount.HeaderText = "Количество";
|
||||
this.ColumnCount.MinimumWidth = 6;
|
||||
this.ColumnCount.Name = "ColumnCount";
|
||||
this.ColumnCount.Width = 125;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(199, 361);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(136, 31);
|
||||
this.buttonCancel.TabIndex = 12;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(43, 361);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(136, 31);
|
||||
this.buttonSave.TabIndex = 11;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// openDateTimePicker
|
||||
//
|
||||
this.openDateTimePicker.Location = new System.Drawing.Point(108, 62);
|
||||
this.openDateTimePicker.Name = "openDateTimePicker";
|
||||
this.openDateTimePicker.Size = new System.Drawing.Size(255, 23);
|
||||
this.openDateTimePicker.TabIndex = 13;
|
||||
//
|
||||
// openDateLabel
|
||||
//
|
||||
this.openDateLabel.AutoSize = true;
|
||||
this.openDateLabel.Location = new System.Drawing.Point(12, 68);
|
||||
this.openDateLabel.Name = "openDateLabel";
|
||||
this.openDateLabel.Size = new System.Drawing.Size(90, 15);
|
||||
this.openDateLabel.TabIndex = 14;
|
||||
this.openDateLabel.Text = "Дата открытия:";
|
||||
//
|
||||
// maxCountLabel
|
||||
//
|
||||
this.maxCountLabel.AutoSize = true;
|
||||
this.maxCountLabel.Location = new System.Drawing.Point(13, 98);
|
||||
this.maxCountLabel.Name = "maxCountLabel";
|
||||
this.maxCountLabel.Size = new System.Drawing.Size(155, 15);
|
||||
this.maxCountLabel.TabIndex = 15;
|
||||
this.maxCountLabel.Text = "Макс. количество букетов:";
|
||||
//
|
||||
// textBoxMaxCount
|
||||
//
|
||||
this.textBoxMaxCount.Location = new System.Drawing.Point(174, 95);
|
||||
this.textBoxMaxCount.Name = "textBoxMaxCount";
|
||||
this.textBoxMaxCount.Size = new System.Drawing.Size(189, 23);
|
||||
this.textBoxMaxCount.TabIndex = 16;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(389, 403);
|
||||
this.Controls.Add(this.textBoxMaxCount);
|
||||
this.Controls.Add(this.maxCountLabel);
|
||||
this.Controls.Add(this.openDateLabel);
|
||||
this.Controls.Add(this.openDateTimePicker);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.textBoxAddress);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelAddress);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormShop";
|
||||
this.Text = "Магазин";
|
||||
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBoxAddress;
|
||||
private TextBox textBoxName;
|
||||
private Label labelAddress;
|
||||
private Label labelName;
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn ColumnBouquetName;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private DateTimePicker openDateTimePicker;
|
||||
private Label openDateLabel;
|
||||
private Label maxCountLabel;
|
||||
private TextBox textBoxMaxCount;
|
||||
}
|
||||
}
|
134
FlowerShop/FlowerShop/FormShop.cs
Normal file
134
FlowerShop/FlowerShop/FormShop.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
|
||||
private readonly IShopLogic _logic;
|
||||
private readonly ILogger _logger;
|
||||
private Dictionary<int, (IBouquetModel, int)> _shopBouquets;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_shopBouquets = new();
|
||||
}
|
||||
|
||||
private void FormShop_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Loading shop");
|
||||
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxAddress.Text = view.Address;
|
||||
openDateTimePicker.Value = view.OpeningDate;
|
||||
textBoxMaxCount.Text = view.MaxCountBouquets.ToString();
|
||||
_shopBouquets = view.ShopBouquets ?? new Dictionary<int, (IBouquetModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading shop");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Loading shop's bouquets");
|
||||
|
||||
try
|
||||
{
|
||||
if (_shopBouquets != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var bouquet in _shopBouquets)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { bouquet.Key, bouquet.Value.Item1.BouquetName, bouquet.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading shop's bouquets");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxMaxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Saving shop");
|
||||
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
OpeningDate = openDateTimePicker.Value,
|
||||
MaxCountBouquets = Convert.ToInt32(textBoxMaxCount.Text),
|
||||
ShopBouquets = _shopBouquets
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during saving shop");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
69
FlowerShop/FlowerShop/FormShop.resx
Normal file
69
FlowerShop/FlowerShop/FormShop.resx
Normal file
@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnBouquetName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
124
FlowerShop/FlowerShop/FormShopSell.Designer.cs
generated
Normal file
124
FlowerShop/FlowerShop/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormShopSell
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelBouquet = new System.Windows.Forms.Label();
|
||||
this.comboBoxBouquet = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(20, 57);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelCount.TabIndex = 1;
|
||||
this.labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelBouquet
|
||||
//
|
||||
this.labelBouquet.AutoSize = true;
|
||||
this.labelBouquet.Location = new System.Drawing.Point(20, 18);
|
||||
this.labelBouquet.Name = "labelBouquet";
|
||||
this.labelBouquet.Size = new System.Drawing.Size(40, 15);
|
||||
this.labelBouquet.TabIndex = 2;
|
||||
this.labelBouquet.Text = "Букет:";
|
||||
//
|
||||
// comboBoxBouquet
|
||||
//
|
||||
this.comboBoxBouquet.FormattingEnabled = true;
|
||||
this.comboBoxBouquet.Location = new System.Drawing.Point(108, 18);
|
||||
this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.comboBoxBouquet.Name = "comboBoxBouquet";
|
||||
this.comboBoxBouquet.Size = new System.Drawing.Size(244, 23);
|
||||
this.comboBoxBouquet.TabIndex = 4;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(108, 55);
|
||||
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(244, 23);
|
||||
this.textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Location = new System.Drawing.Point(206, 106);
|
||||
this.buttonSell.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(89, 31);
|
||||
this.buttonSell.TabIndex = 6;
|
||||
this.buttonSell.Text = "Продажа";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(301, 106);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(89, 31);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(402, 148);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSell);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxBouquet);
|
||||
this.Controls.Add(this.labelBouquet);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormShopSell";
|
||||
this.Text = "Продажа из магазина";
|
||||
this.Load += new System.EventHandler(this.FormShopSell_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Label labelCount;
|
||||
private Label labelBouquet;
|
||||
private ComboBox comboBoxBouquet;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonSell;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
93
FlowerShop/FlowerShop/FormShopSell.cs
Normal file
93
FlowerShop/FlowerShop/FormShopSell.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetLogic _logicBouquet;
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormShopSell(ILogger<FormShopSell> logger, IBouquetLogic logicBouquet, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicBouquet = logicBouquet;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormShopSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Loading bouquets for selling");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicBouquet.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxBouquet.DisplayMember = "BouquetName";
|
||||
comboBoxBouquet.ValueMember = "Id";
|
||||
comboBoxBouquet.DataSource = list;
|
||||
comboBoxBouquet.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading bouquets for selling");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxBouquet.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите букет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание продажи");
|
||||
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SellBouquet(
|
||||
new BouquetBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxBouquet.SelectedValue)
|
||||
},
|
||||
Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания продажи");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormShopSell.resx
Normal file
60
FlowerShop/FlowerShop/FormShopSell.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
150
FlowerShop/FlowerShop/FormShopSupply.Designer.cs
generated
Normal file
150
FlowerShop/FlowerShop/FormShopSupply.Designer.cs
generated
Normal file
@ -0,0 +1,150 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormShopSupply
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelShop = new System.Windows.Forms.Label();
|
||||
this.labelBouquet = new System.Windows.Forms.Label();
|
||||
this.labelBouquetsCount = new System.Windows.Forms.Label();
|
||||
this.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxBouquet = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelShop
|
||||
//
|
||||
this.labelShop.AutoSize = true;
|
||||
this.labelShop.Location = new System.Drawing.Point(23, 14);
|
||||
this.labelShop.Name = "labelShop";
|
||||
this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
|
||||
this.labelShop.Size = new System.Drawing.Size(57, 15);
|
||||
this.labelShop.TabIndex = 0;
|
||||
this.labelShop.Text = "Магазин:";
|
||||
//
|
||||
// labelBouquet
|
||||
//
|
||||
this.labelBouquet.AutoSize = true;
|
||||
this.labelBouquet.Location = new System.Drawing.Point(23, 54);
|
||||
this.labelBouquet.Name = "labelBouquet";
|
||||
this.labelBouquet.Size = new System.Drawing.Size(40, 15);
|
||||
this.labelBouquet.TabIndex = 1;
|
||||
this.labelBouquet.Text = "Букет:";
|
||||
//
|
||||
// labelBouquetsCount
|
||||
//
|
||||
this.labelBouquetsCount.AutoSize = true;
|
||||
this.labelBouquetsCount.Location = new System.Drawing.Point(23, 92);
|
||||
this.labelBouquetsCount.Name = "labelBouquetsCount";
|
||||
this.labelBouquetsCount.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelBouquetsCount.TabIndex = 2;
|
||||
this.labelBouquetsCount.Text = "Количество:";
|
||||
//
|
||||
// comboBoxShop
|
||||
//
|
||||
this.comboBoxShop.FormattingEnabled = true;
|
||||
this.comboBoxShop.Location = new System.Drawing.Point(130, 14);
|
||||
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.comboBoxShop.Name = "comboBoxShop";
|
||||
this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
|
||||
this.comboBoxShop.TabIndex = 3;
|
||||
//
|
||||
// comboBoxBouquet
|
||||
//
|
||||
this.comboBoxBouquet.FormattingEnabled = true;
|
||||
this.comboBoxBouquet.Location = new System.Drawing.Point(130, 52);
|
||||
this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.comboBoxBouquet.Name = "comboBoxBouquet";
|
||||
this.comboBoxBouquet.Size = new System.Drawing.Size(220, 23);
|
||||
this.comboBoxBouquet.TabIndex = 4;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(130, 89);
|
||||
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(110, 23);
|
||||
this.textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(288, 137);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(82, 34);
|
||||
this.buttonCancel.TabIndex = 9;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(200, 137);
|
||||
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(82, 34);
|
||||
this.buttonSave.TabIndex = 8;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// FormShopSupply
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(382, 182);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxBouquet);
|
||||
this.Controls.Add(this.comboBoxShop);
|
||||
this.Controls.Add(this.labelBouquetsCount);
|
||||
this.Controls.Add(this.labelBouquet);
|
||||
this.Controls.Add(this.labelShop);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormShopSupply";
|
||||
this.Text = "Пополнение магазина";
|
||||
this.Load += new System.EventHandler(this.FormShopSupply_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelShop;
|
||||
private Label labelBouquet;
|
||||
private Label labelBouquetsCount;
|
||||
private ComboBox comboBoxShop;
|
||||
private ComboBox comboBoxBouquet;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
}
|
||||
}
|
118
FlowerShop/FlowerShop/FormShopSupply.cs
Normal file
118
FlowerShop/FlowerShop/FormShopSupply.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormShopSupply : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetLogic _logicBouquet;
|
||||
private readonly IShopLogic _logicShop;
|
||||
|
||||
public FormShopSupply(ILogger<FormShopSupply> logger, IBouquetLogic logicBouquet, IShopLogic logicShop)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicBouquet = logicBouquet;
|
||||
_logicShop = logicShop;
|
||||
}
|
||||
|
||||
private void FormShopSupply_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Loading bouquets for supplying");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicBouquet.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxBouquet.DisplayMember = "BouquetName";
|
||||
comboBoxBouquet.ValueMember = "Id";
|
||||
comboBoxBouquet.DataSource = list;
|
||||
comboBoxBouquet.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading bouquets for supplying");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Loading shops for supplying");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicShop.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "Name";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = list;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading shops for supplying");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxBouquet.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите букет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxShop.SelectedValue== null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Creation of supply");
|
||||
|
||||
try
|
||||
{
|
||||
var operationResult = _logicShop.SupplyBouquets(
|
||||
new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text },
|
||||
new BouquetBindingModel { Id = Convert.ToInt32(comboBoxBouquet.SelectedValue), BouquetName = comboBoxBouquet.Text },
|
||||
Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during creation of supply");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormShopSupply.resx
Normal file
60
FlowerShop/FlowerShop/FormShopSupply.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
121
FlowerShop/FlowerShop/FormShops.Designer.cs
generated
Normal file
121
FlowerShop/FlowerShop/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
||||
namespace FlowerShop
|
||||
{
|
||||
partial class FormShops
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonEdit = new System.Windows.Forms.Button();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(10, 9);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(491, 320);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(549, 294);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(133, 33);
|
||||
this.buttonUpdate.TabIndex = 9;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(549, 83);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(133, 33);
|
||||
this.buttonDelete.TabIndex = 8;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
//
|
||||
// buttonEdit
|
||||
//
|
||||
this.buttonEdit.Location = new System.Drawing.Point(549, 46);
|
||||
this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonEdit.Name = "buttonEdit";
|
||||
this.buttonEdit.Size = new System.Drawing.Size(133, 33);
|
||||
this.buttonEdit.TabIndex = 7;
|
||||
this.buttonEdit.Text = "Изменить";
|
||||
this.buttonEdit.UseVisualStyleBackColor = true;
|
||||
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(549, 9);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(133, 33);
|
||||
this.buttonAdd.TabIndex = 6;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// FormShops
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonEdit);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormShops";
|
||||
this.Text = "Магазины";
|
||||
this.Load += new System.EventHandler(this.FormShops_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDelete;
|
||||
private Button buttonEdit;
|
||||
private Button buttonAdd;
|
||||
}
|
||||
}
|
113
FlowerShop/FlowerShop/FormShops.cs
Normal file
113
FlowerShop/FlowerShop/FormShops.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using FlowerShop;
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
public partial class FormShops : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
|
||||
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormShops_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ShopBouquets"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Loading shops");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading shops");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
|
||||
if (service is FormShop form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
|
||||
|
||||
if (service is FormShop form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить магазин?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Deleting shop");
|
||||
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ShopBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during deleting shop");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
FlowerShop/FlowerShop/FormShops.resx
Normal file
60
FlowerShop/FlowerShop/FormShops.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -1,17 +1,53 @@
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using FlowerShopDatabaseImplement.Implements;
|
||||
using FlowerShopBusinessLogic.BusinessLogics;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using NLog.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShop
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// 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.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IBouquetStorage, BouquetStorage>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IBouquetLogic, BouquetLogic>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormBouquet>();
|
||||
services.AddTransient<FormBouquets>();
|
||||
services.AddTransient<FormBouquetComponent>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShopSupply>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BouquetLogic : IBouquetLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBouquetStorage _bouquetStorage;
|
||||
|
||||
public BouquetLogic(ILogger<BouquetLogic> logger, IBouquetStorage bouquetStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_bouquetStorage = bouquetStorage;
|
||||
}
|
||||
|
||||
public List<BouquetViewModel>? ReadList(BouquetSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. BouquetName: {BouquetName}. Id: {Id}", model?.BouquetName, model?.Id);
|
||||
|
||||
var list = model == null ? _bouquetStorage.GetFullList() : _bouquetStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public BouquetViewModel? ReadElement(BouquetSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. BouquetName: {BouquetName}. Id: {Id}", model.BouquetName, model.Id);
|
||||
|
||||
var element = _bouquetStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(BouquetBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_bouquetStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(BouquetBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_bouquetStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BouquetBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_bouquetStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BouquetBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.BouquetName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия букета", nameof(model.BouquetName));
|
||||
}
|
||||
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена букета должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Bouquet. BouquetName: {BouquetName}. Price: {Price}. Id: {Id}", model.BouquetName, model.Price, model.Id);
|
||||
|
||||
var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Букет с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName: {ComponentName}. Id: {Id}", model?.ComponentName, model?.Id);
|
||||
|
||||
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}", model.ComponentName, model.Id);
|
||||
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
|
||||
}
|
||||
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id);
|
||||
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel { ComponentName = model.ComponentName });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
236
FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
236
FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,236 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using FlowerShopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text;
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IBouquetStorage _bouquetStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IBouquetStorage bouquetStorage, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_bouquetStorage = bouquetStorage;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Принят;
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят)
|
||||
{
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Выполняется;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (order?.Status != OrderStatus.Выполняется)
|
||||
{
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
|
||||
var bouquet = _bouquetStorage.GetElement(new BouquetSearchModel() { Id = order.BouquetId });
|
||||
if (bouquet == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to Готов operation failed. Bouquet not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CheckThenSupplyMany(bouquet, order.Count))
|
||||
{
|
||||
_logger.LogWarning("Status update to Готов operation failed. Shop supply error.");
|
||||
throw new Exception("В магазинах не хватает места!");
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Готов;
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
|
||||
if (order?.Status != OrderStatus.Готов)
|
||||
{
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Выдан;
|
||||
model.DateImplement = order.DateImplement;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId);
|
||||
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element != null && element.Id == model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Заказ с таким идентификатором уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckThenSupplyMany(IBouquetModel bouquet, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. Bouquet count < 0.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int freeSpace = 0;
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace += shop.MaxCountBouquets;
|
||||
foreach (var bouq in shop.ShopBouquets)
|
||||
{
|
||||
freeSpace -= bouq.Value.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. There's no place for new bouquets in shops.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace = shop.MaxCountBouquets;
|
||||
|
||||
foreach (var bouq in shop.ShopBouquets)
|
||||
{
|
||||
freeSpace -= bouq.Value.Item2;
|
||||
}
|
||||
|
||||
if (freeSpace == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (freeSpace - count >= 0)
|
||||
{
|
||||
if (_shopLogic.SupplyBouquets(new() { Id = shop.Id }, bouquet, count)) count = 0;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
if (_shopLogic.SupplyBouquets(new() { Id = shop.Id }, bouquet, freeSpace)) count -= freeSpace;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
203
FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
203
FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ShopLogic.cs
Normal file
@ -0,0 +1,203 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage) {
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.Name, model.Id);
|
||||
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement. element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", model?.Name, model?.Id);
|
||||
|
||||
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool SupplyBouquets(ShopSearchModel model, IBouquetModel bouquet, int count)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (bouquet == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(bouquet));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Count of bouquets in supply must be more than 0", nameof(count));
|
||||
}
|
||||
|
||||
var shopElement = _shopStorage.GetElement(model);
|
||||
if (shopElement == null)
|
||||
{
|
||||
_logger.LogWarning("Required shop element not found in storage");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||
|
||||
var countBouquets = 0;
|
||||
foreach (var bouq in shopElement.ShopBouquets)
|
||||
{
|
||||
countBouquets += bouq.Value.Item2;
|
||||
}
|
||||
|
||||
if (shopElement.MaxCountBouquets - countBouquets >= count)
|
||||
{
|
||||
if (shopElement.ShopBouquets.TryGetValue(bouquet.Id, out var sameBouquet))
|
||||
{
|
||||
shopElement.ShopBouquets[bouquet.Id] = (bouquet, sameBouquet.Item2 + count);
|
||||
_logger.LogInformation("Same bouquet found by supply. Added {0} of {1} in {2} shop", count, bouquet.BouquetName, shopElement.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
shopElement.ShopBouquets[bouquet.Id] = (bouquet, count);
|
||||
_logger.LogInformation("New bouquet added by supply. Added {0} of {1} in {2} shop", count, bouquet.BouquetName, shopElement.Name);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
Name = shopElement.Name,
|
||||
Address = shopElement.Address,
|
||||
OpeningDate = shopElement.OpeningDate,
|
||||
ShopBouquets = shopElement.ShopBouquets,
|
||||
MaxCountBouquets = shopElement.MaxCountBouquets
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellBouquet(IBouquetModel bouquet, int count)
|
||||
{
|
||||
return _shopStorage.SellBouquet(bouquet, count);
|
||||
}
|
||||
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
||||
}
|
||||
|
||||
if (model.MaxCountBouquets < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с отрицательным числом максимального количества букетов!");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id);
|
||||
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,12 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.BindingModels
|
||||
{
|
||||
public class BouquetBindingModel : IBouquetModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string BouquetName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BouquetComponents { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.BindingModels
|
||||
{
|
||||
public class ComponentBindingModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using FlowerShopDataModels.Enums;
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int BouquetId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.BindingModels
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public int MaxCountBouquets { get; set; }
|
||||
|
||||
public Dictionary<int, (IBouquetModel, int)> ShopBouquets { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IBouquetLogic
|
||||
{
|
||||
List<BouquetViewModel>? ReadList(BouquetSearchModel? model);
|
||||
BouquetViewModel? ReadElement(BouquetSearchModel model);
|
||||
bool Create(BouquetBindingModel model);
|
||||
bool Update(BouquetBindingModel model);
|
||||
bool Delete(BouquetBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
|
||||
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
bool Update(ComponentBindingModel model);
|
||||
bool Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool SupplyBouquets(ShopSearchModel model, IBouquetModel bouquet, int count);
|
||||
bool SellBouquet(IBouquetModel bouquet, int count);
|
||||
}
|
||||
}
|
13
FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj
Normal file
13
FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,8 @@
|
||||
namespace FlowerShopContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace FlowerShopContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace FlowerShopContracts.SearchModels
|
||||
{
|
||||
public class BouquetSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? BouquetName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace FlowerShopContracts.SearchModels
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
namespace FlowerShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IBouquetStorage
|
||||
{
|
||||
List<BouquetViewModel> GetFullList();
|
||||
List<BouquetViewModel> GetFilteredList(BouquetSearchModel model);
|
||||
BouquetViewModel? GetElement(BouquetSearchModel model);
|
||||
BouquetViewModel? Insert(BouquetBindingModel model);
|
||||
BouquetViewModel? Update(BouquetBindingModel model);
|
||||
BouquetViewModel? Delete(BouquetBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
namespace FlowerShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IComponentStorage
|
||||
{
|
||||
List<ComponentViewModel> GetFullList();
|
||||
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||
ComponentViewModel? Update(ComponentBindingModel model);
|
||||
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
namespace FlowerShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorage
|
||||
{
|
||||
List<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
namespace FlowerShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
List<ShopViewModel> GetFullList();
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellBouquet(IBouquetModel model, int count);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
public class BouquetViewModel : IBouquetModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название букета")]
|
||||
public string BouquetName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> BouquetComponents { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
25
FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs
Normal file
25
FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using FlowerShopDataModels.Enums;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int BouquetId { get; set; }
|
||||
[DisplayName("Букет")]
|
||||
public string BouquetName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
24
FlowerShop/FlowerShopContracts/ViewModels/ShopViewModel.cs
Normal file
24
FlowerShop/FlowerShopContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FlowerShopContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название магазина")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (IBouquetModel, int)> ShopBouquets { get; set; } = new();
|
||||
|
||||
[DisplayName("Макс. букетов в магазине")]
|
||||
public int MaxCountBouquets { get; set; }
|
||||
}
|
||||
}
|
11
FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs
Normal file
11
FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace FlowerShopDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Выполняется = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
7
FlowerShop/FlowerShopDataModels/IId.cs
Normal file
7
FlowerShop/FlowerShopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace FlowerShopDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
9
FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs
Normal file
9
FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace FlowerShopDataModels.Models
|
||||
{
|
||||
public interface IBouquetModel : IId
|
||||
{
|
||||
string BouquetName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> BouquetComponents { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace FlowerShopDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
14
FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs
Normal file
14
FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using FlowerShopDataModels.Enums;
|
||||
|
||||
namespace FlowerShopDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int BouquetId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
11
FlowerShop/FlowerShopDataModels/Models/IShopModel.cs
Normal file
11
FlowerShop/FlowerShopDataModels/Models/IShopModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace FlowerShopDataModels.Models
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
string Address { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
int MaxCountBouquets { get; }
|
||||
Dictionary<int, (IBouquetModel, int)> ShopBouquets { get; }
|
||||
}
|
||||
}
|
23
FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs
Normal file
23
FlowerShop/FlowerShopDatabaseImplement/FlowerShopDatabase.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FlowerShopDatabaseImplement
|
||||
{
|
||||
public class FlowerShopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Initial Catalog=FlowerShopDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Bouquet> Bouquets { set; get; }
|
||||
public virtual DbSet<BouquetComponent> BouquetComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Shop> Shops { set; get; }
|
||||
public virtual DbSet<ShopBouquet> ShopBouquets { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,123 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class BouquetStorage : IBouquetStorage
|
||||
{
|
||||
public BouquetViewModel? GetElement(BouquetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BouquetName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Bouquets.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(
|
||||
x => (!string.IsNullOrEmpty(model.BouquetName) && x.BouquetName == model.BouquetName) || (model.Id.HasValue && x.Id == model.Id)
|
||||
)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<BouquetViewModel> GetFilteredList(BouquetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BouquetName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Bouquets.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.BouquetName.Contains(model.BouquetName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<BouquetViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
return context.Bouquets.Include(x => x.Components).ThenInclude(x => x.Component).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public BouquetViewModel? Insert(BouquetBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
{
|
||||
try
|
||||
{
|
||||
var newBouquet = Bouquet.Create(context, model);
|
||||
if (newBouquet == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Bouquets.Add(newBouquet);
|
||||
|
||||
context.SaveChanges();
|
||||
context.Database.CommitTransaction();
|
||||
|
||||
return newBouquet.GetViewModel;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BouquetViewModel? Update(BouquetBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
{
|
||||
try
|
||||
{
|
||||
var bouquet = context.Bouquets.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (bouquet == null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
|
||||
bouquet.Update(model);
|
||||
bouquet.UpdateComponents(context, model);
|
||||
|
||||
context.SaveChanges();
|
||||
context.Database.CommitTransaction();
|
||||
|
||||
return bouquet.GetViewModel;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BouquetViewModel? Delete(BouquetBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
var element = context.Bouquets.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Bouquets.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
return context.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
var element = context.Components.FirstOrDefault(record => record.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
return context.Orders.Include(x => x.Bouquet).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Bouquet).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
return context.Orders.Include(x => x.Bouquet).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders.Include(x => x.Bouquet).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders.Include(x => x.Bouquet).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
162
FlowerShop/FlowerShopDatabaseImplement/Implements/ShopStorage.cs
Normal file
162
FlowerShop/FlowerShopDatabaseImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,162 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
using FlowerShopDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Shops.Include(x => x.Bouquets)
|
||||
.ThenInclude(x => x.Bouquet)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Shops.Include(x => x.Bouquets).ThenInclude(x => x.Bouquet).Where(x => x.Name.Contains(model.Name)).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
|
||||
return context.Shops.Include(x => x.Bouquets).ThenInclude(x => x.Bouquet).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var newShop = Shop.Create(context, model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (context.Shops.Any(x => x.Name == newShop.Name))
|
||||
{
|
||||
throw new Exception("Название магазина уже занято");
|
||||
}
|
||||
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.Include(x => x.Bouquets).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
if (model.ShopBouquets.Count > 0)
|
||||
{
|
||||
shop.UpdateBouquets(context, model);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
var shop = context.Shops.Include(x => x.Bouquets).FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (shop != null)
|
||||
{
|
||||
context.Shops.Remove(shop);
|
||||
context.SaveChanges();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellBouquet(IBouquetModel model, int count)
|
||||
{
|
||||
using var context = new FlowerShopDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
foreach (var shopBouquets in context.ShopBouquets.Where(x => x.BouquetId == model.Id))
|
||||
{
|
||||
var min = Math.Min(count, shopBouquets.Count);
|
||||
shopBouquets.Count -= min;
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
171
FlowerShop/FlowerShopDatabaseImplement/Migrations/20230312011037_InitialCreate.Designer.cs
generated
Normal file
171
FlowerShop/FlowerShopDatabaseImplement/Migrations/20230312011037_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,171 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FlowerShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlowerShopDatabase))]
|
||||
[Migration("20230312011037_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BouquetName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Bouquets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BouquetComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("BouquetComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("BouquetComponents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Bouquets",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
BouquetName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Bouquets", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
BouquetId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Bouquets_BouquetId",
|
||||
column: x => x.BouquetId,
|
||||
principalTable: "Bouquets",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BouquetComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
BouquetId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BouquetComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BouquetComponents_Bouquets_BouquetId",
|
||||
column: x => x.BouquetId,
|
||||
principalTable: "Bouquets",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_BouquetComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BouquetComponents_BouquetId",
|
||||
table: "BouquetComponents",
|
||||
column: "BouquetId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BouquetComponents_ComponentId",
|
||||
table: "BouquetComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_BouquetId",
|
||||
table: "Orders",
|
||||
column: "BouquetId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BouquetComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Bouquets");
|
||||
}
|
||||
}
|
||||
}
|
248
FlowerShop/FlowerShopDatabaseImplement/Migrations/20230420224142_ShopsAdded.Designer.cs
generated
Normal file
248
FlowerShop/FlowerShopDatabaseImplement/Migrations/20230420224142_ShopsAdded.Designer.cs
generated
Normal file
@ -0,0 +1,248 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FlowerShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlowerShopDatabase))]
|
||||
[Migration("20230420224142_ShopsAdded")]
|
||||
partial class ShopsAdded
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BouquetName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Bouquets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BouquetComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MaxCountBouquets")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopBouquet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopBouquets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("BouquetComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopBouquet", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany()
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Bouquets")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("BouquetComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Bouquets");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ShopsAdded : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
MaxCountBouquets = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopBouquets",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
BouquetId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopBouquets", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopBouquets_Bouquets_BouquetId",
|
||||
column: x => x.BouquetId,
|
||||
principalTable: "Bouquets",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopBouquets_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopBouquets_BouquetId",
|
||||
table: "ShopBouquets",
|
||||
column: "BouquetId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopBouquets_ShopId",
|
||||
table: "ShopBouquets",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopBouquets");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FlowerShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlowerShopDatabase))]
|
||||
partial class FlowerShopDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BouquetName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Bouquets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.ToTable("BouquetComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MaxCountBouquets")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopBouquet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BouquetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BouquetId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopBouquets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.BouquetComponent", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("BouquetComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopBouquet", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Bouquet", "Bouquet")
|
||||
.WithMany()
|
||||
.HasForeignKey("BouquetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Bouquets")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Bouquet");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Bouquet", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("BouquetComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Bouquets");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
100
FlowerShop/FlowerShopDatabaseImplement/Models/Bouquet.cs
Normal file
100
FlowerShop/FlowerShopDatabaseImplement/Models/Bouquet.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Bouquet : IBouquetModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string BouquetName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; private set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _bouquetComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> BouquetComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bouquetComponents == null)
|
||||
{
|
||||
_bouquetComponents = Components.ToDictionary(record => record.ComponentId, record => (record.Component as IComponentModel, record.Count));
|
||||
}
|
||||
return _bouquetComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("BouquetId")]
|
||||
public virtual List<BouquetComponent> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("BouquetId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Bouquet? Create(FlowerShopDatabase context, BouquetBindingModel model)
|
||||
{
|
||||
return new Bouquet()
|
||||
{
|
||||
Id = model.Id,
|
||||
BouquetName = model.BouquetName,
|
||||
Price = model.Price,
|
||||
Components = model.BouquetComponents.Select(x => new BouquetComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BouquetBindingModel model)
|
||||
{
|
||||
BouquetName = model.BouquetName;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public BouquetViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
BouquetName = BouquetName,
|
||||
Price = Price,
|
||||
BouquetComponents = BouquetComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(FlowerShopDatabase context, BouquetBindingModel model)
|
||||
{
|
||||
var bouquetComponents = context.BouquetComponents.Where(record => record.BouquetId == model.Id).ToList();
|
||||
if (bouquetComponents != null && bouquetComponents.Count > 0)
|
||||
{
|
||||
context.BouquetComponents.RemoveRange(bouquetComponents.Where(record => !model.BouquetComponents.ContainsKey(record.ComponentId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateComponent in bouquetComponents)
|
||||
{
|
||||
updateComponent.Count = model.BouquetComponents[updateComponent.ComponentId].Item2;
|
||||
model.BouquetComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var bouquet = context.Bouquets.First(x => x.Id == Id);
|
||||
foreach (var pc in model.BouquetComponents)
|
||||
{
|
||||
context.BouquetComponents.Add(new BouquetComponent
|
||||
{
|
||||
Bouquet = bouquet,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
_bouquetComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class BouquetComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int BouquetId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
|
||||
public virtual Bouquet Bouquet { get; set; } = new();
|
||||
}
|
||||
}
|
56
FlowerShop/FlowerShopDatabaseImplement/Models/Component.cs
Normal file
56
FlowerShop/FlowerShopDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = String.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<BouquetComponent> BouquetComponents { get; set; } = new();
|
||||
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
75
FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs
Normal file
75
FlowerShop/FlowerShopDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Enums;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int BouquetId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Bouquet Bouquet { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order
|
||||
{
|
||||
BouquetId = model.BouquetId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
BouquetId = BouquetId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
BouquetName = Bouquet.BouquetName
|
||||
};
|
||||
}
|
||||
}
|
114
FlowerShop/FlowerShopDatabaseImplement/Models/Shop.cs
Normal file
114
FlowerShop/FlowerShopDatabaseImplement/Models/Shop.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public List<ShopBouquet> Bouquets { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IBouquetModel, int)>? _shopBouquets = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBouquetModel, int)> ShopBouquets
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopBouquets == null)
|
||||
{
|
||||
_shopBouquets = Bouquets.ToDictionary(recPC => recPC.BouquetId, recPC => (recPC.Bouquet as IBouquetModel, recPC.Count));
|
||||
}
|
||||
|
||||
return _shopBouquets;
|
||||
}
|
||||
}
|
||||
|
||||
[Required]
|
||||
public int MaxCountBouquets { get; set; }
|
||||
|
||||
public static Shop Create(FlowerShopDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Bouquets = model.ShopBouquets.Select(x => new ShopBouquet
|
||||
{
|
||||
Bouquet = context.Bouquets.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
MaxCountBouquets = model.MaxCountBouquets
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
OpeningDate = model.OpeningDate;
|
||||
MaxCountBouquets = model.MaxCountBouquets;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopBouquets = ShopBouquets,
|
||||
MaxCountBouquets = MaxCountBouquets
|
||||
};
|
||||
|
||||
public void UpdateBouquets(FlowerShopDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var ShopBouquets = context.ShopBouquets.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
|
||||
if (ShopBouquets != null && this.ShopBouquets.Count > 0)
|
||||
{
|
||||
context.ShopBouquets.RemoveRange(ShopBouquets.Where((ShopBouquet rec) => !model.ShopBouquets.ContainsKey(rec.BouquetId)));
|
||||
context.SaveChanges();
|
||||
|
||||
ShopBouquets = context.ShopBouquets.Where((ShopBouquet rec) => rec.ShopId == model.Id).ToList();
|
||||
|
||||
foreach (var updateBouquet in ShopBouquets)
|
||||
{
|
||||
updateBouquet.Count = model.ShopBouquets[updateBouquet.BouquetId].Item2;
|
||||
model.ShopBouquets.Remove(updateBouquet.BouquetId);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
|
||||
foreach (var elem in model.ShopBouquets)
|
||||
{
|
||||
context.ShopBouquets.Add(new ShopBouquet
|
||||
{
|
||||
Shop = shop,
|
||||
Bouquet = context.Bouquets.First(x => x.Id == elem.Key),
|
||||
Count = elem.Value.Item2
|
||||
});
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
_shopBouquets = null;
|
||||
}
|
||||
}
|
||||
}
|
22
FlowerShop/FlowerShopDatabaseImplement/Models/ShopBouquet.cs
Normal file
22
FlowerShop/FlowerShopDatabaseImplement/Models/ShopBouquet.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class ShopBouquet
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int BouquetId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Bouquet Bouquet { get; set; } = new();
|
||||
}
|
||||
}
|
63
FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs
Normal file
63
FlowerShop/FlowerShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using FlowerShopFileImplement.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton instance;
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string BouquetFileName = "Bouquet.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
|
||||
public List<Order> Orders { get; private set; }
|
||||
|
||||
public List<Bouquet> Bouquets { get; private set; }
|
||||
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveBouquets() => SaveData(Bouquets, BouquetFileName, "Bouquets", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Bouquets = LoadData(BouquetFileName, "Bouquet", x => Bouquet.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FlowerShopContracts\FlowerShopContracts.csproj" />
|
||||
<ProjectReference Include="..\FlowerShopDataModels\FlowerShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,85 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopFileImplement.Models;
|
||||
|
||||
namespace FlowerShopFileImplement.Implements
|
||||
{
|
||||
public class BouquetStorage : IBouquetStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public BouquetStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public BouquetViewModel? GetElement(BouquetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BouquetName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Bouquets.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BouquetName) && x.BouquetName == model.BouquetName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<BouquetViewModel> GetFilteredList(BouquetSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BouquetName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Bouquets.Where(x => x.BouquetName.Contains(model.BouquetName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<BouquetViewModel> GetFullList()
|
||||
{
|
||||
return source.Bouquets.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public BouquetViewModel? Insert(BouquetBindingModel model)
|
||||
{
|
||||
model.Id = source.Bouquets.Count > 0 ? source.Bouquets.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newBouquet = Bouquet.Create(model);
|
||||
if (newBouquet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Bouquets.Add(newBouquet);
|
||||
source.SaveBouquets();
|
||||
|
||||
return newBouquet.GetViewModel;
|
||||
}
|
||||
|
||||
public BouquetViewModel? Update(BouquetBindingModel model)
|
||||
{
|
||||
var bouquet = source.Bouquets.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (bouquet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
bouquet.Update(model);
|
||||
source.SaveBouquets();
|
||||
|
||||
return bouquet.GetViewModel;
|
||||
}
|
||||
|
||||
public BouquetViewModel? Delete(BouquetBindingModel model)
|
||||
{
|
||||
var bouquet = source.Bouquets.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (bouquet == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Bouquets.Remove(bouquet);
|
||||
source.SaveBouquets();
|
||||
|
||||
return bouquet.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopFileImplement.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Components.Add(newComponent);
|
||||
source.SaveComponents();
|
||||
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
component.Update(model);
|
||||
source.SaveComponents();
|
||||
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Components.Remove(component);
|
||||
source.SaveComponents();
|
||||
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
100
FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs
Normal file
100
FlowerShop/FlowerShopFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopFileImplement.Models;
|
||||
|
||||
namespace FlowerShopFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return AttachBouquetName(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel);
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachBouquetName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => AttachBouquetName(x.GetViewModel)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
|
||||
return AttachBouquetName(order.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
|
||||
return AttachBouquetName(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
|
||||
return AttachBouquetName(order.GetViewModel);
|
||||
}
|
||||
|
||||
private OrderViewModel AttachBouquetName(OrderViewModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var bouquet = source.Bouquets.Find(b => b.Id == model.BouquetId);
|
||||
model.BouquetName = bouquet is null ? String.Empty : bouquet.BouquetName;
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
156
FlowerShop/FlowerShopFileImplement/Implements/ShopStorage.cs
Normal file
156
FlowerShop/FlowerShopFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using FlowerShopFileImplement.Models;
|
||||
|
||||
namespace FlowerShopFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return source.Shops.Select(x => x.GetViewModel).Where(x => x.Name.Contains(model.Name ?? string.Empty)).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(shop => shop.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Shops.Remove(shop);
|
||||
source.SaveShops();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellBouquet(IBouquetModel model, int count)
|
||||
{
|
||||
var bouquet = source.Bouquets.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
var countStore = count;
|
||||
|
||||
if (bouquet == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
foreach (var bouq in shop.ShopBouquets)
|
||||
{
|
||||
if (bouq.Value.Item1.Id == bouquet.Id)
|
||||
{
|
||||
count -= bouq.Value.Item2;
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
count = countStore;
|
||||
|
||||
foreach(var shop in source.Shops)
|
||||
{
|
||||
var bouquets = shop.ShopBouquets;
|
||||
|
||||
foreach (var bouq in bouquets.Where(x => x.Value.Item1.Id == bouquet.Id))
|
||||
{
|
||||
var min = Math.Min(bouq.Value.Item2, count);
|
||||
bouquets[bouq.Value.Item1.Id] = (bouq.Value.Item1, bouq.Value.Item2 - min);
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
Name = shop.Name,
|
||||
Address = shop.Address,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
MaxCountBouquets = shop.MaxCountBouquets,
|
||||
ShopBouquets = bouquets
|
||||
});
|
||||
source.SaveShops();
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
104
FlowerShop/FlowerShopFileImplement/Models/Bouquet.cs
Normal file
104
FlowerShop/FlowerShopFileImplement/Models/Bouquet.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Models
|
||||
{
|
||||
public class Bouquet : IBouquetModel
|
||||
{
|
||||
public string BouquetName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Components { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _bouquetComponents = new();
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> BouquetComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bouquetComponents == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_bouquetComponents = Components.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _bouquetComponents;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bouquet? Create(BouquetBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Bouquet()
|
||||
{
|
||||
Id = model.Id,
|
||||
BouquetName = model.BouquetName,
|
||||
Price = model.Price,
|
||||
Components = model.BouquetComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Bouquet? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Bouquet()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
BouquetName = element.Element("BouquetName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Components = element.Element("BouquetComponents")!.Elements("BouquetComponent").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BouquetBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BouquetName = model.BouquetName;
|
||||
Price = model.Price;
|
||||
Components = model.BouquetComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_bouquetComponents = null;
|
||||
}
|
||||
|
||||
public BouquetViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
BouquetName = BouquetName,
|
||||
Price = Price,
|
||||
BouquetComponents = BouquetComponents
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Bouquet",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("BouquetName", BouquetName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("BouquetComponents", Components.Select(x =>
|
||||
new XElement("BouquetComponent",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))).ToArray())
|
||||
);
|
||||
}
|
||||
}
|
72
FlowerShop/FlowerShopFileImplement/Models/Component.cs
Normal file
72
FlowerShop/FlowerShopFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public string ComponentName { get; private set; } = String.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Component? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ComponentName = element.Element("ComponentName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Component",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ComponentName", ComponentName),
|
||||
new XElement("Cost", Cost.ToString())
|
||||
);
|
||||
}
|
||||
}
|
96
FlowerShop/FlowerShopFileImplement/Models/Order.cs
Normal file
96
FlowerShop/FlowerShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Enums;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int BouquetId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order
|
||||
{
|
||||
BouquetId = model.BouquetId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
BouquetId = Convert.ToInt32(element.Element("BouquetId")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
BouquetId = BouquetId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("BouquetId", BouquetId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString())
|
||||
);
|
||||
}
|
||||
}
|
123
FlowerShop/FlowerShopFileImplement/Models/Shop.cs
Normal file
123
FlowerShop/FlowerShopFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public int MaxCountBouquets { get; private set; }
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Bouquets { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IBouquetModel, int)>? _shopBouquets = null;
|
||||
|
||||
public Dictionary<int, (IBouquetModel, int)> ShopBouquets
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopBouquets == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopBouquets = Bouquets.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Bouquets.FirstOrDefault(z => z.Id == y.Key) as IBouquetModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _shopBouquets;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
MaxCountBouquets = model.MaxCountBouquets,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Bouquets = model.ShopBouquets.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Name = element.Element("Name")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
MaxCountBouquets = Convert.ToInt32(element.Element("MaxCountBouquets")!.Value),
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
Bouquets = element.Element("ShopBouquets")!.Elements("ShopBouquet").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
OpeningDate = model.OpeningDate;
|
||||
MaxCountBouquets = model.MaxCountBouquets;
|
||||
|
||||
if (model.ShopBouquets.Count > 0)
|
||||
{
|
||||
Bouquets = model.ShopBouquets.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopBouquets = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopBouquets = ShopBouquets,
|
||||
MaxCountBouquets = MaxCountBouquets
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Name", Name),
|
||||
new XElement("Address", Address),
|
||||
new XElement("MaxCountBouquets", MaxCountBouquets),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopBouquets", Bouquets.Select(x =>
|
||||
new XElement("ShopBouquet",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
31
FlowerShop/FlowerShopListImplement/DataListSingleton.cs
Normal file
31
FlowerShop/FlowerShopListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using FlowerShopListImplement.Models;
|
||||
|
||||
namespace FlowerShopListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Bouquet> Bouquets { get; set; }
|
||||
public List<Shop> Shops { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Bouquets = new List<Bouquet>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user