Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
8dfc5b2a93 |
49
Bar/Bar.sln
Normal file
49
Bar/Bar.sln
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarView", "Bar\BarView.csproj", "{C2397C01-1A84-41C9-88FC-973959990385}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarBusinessLogic", "BarBusinessLogic\BarBusinessLogic\BarBusinessLogic.csproj", "{1BB13544-63F5-4C8A-AA50-0D9174D1D0B6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarContracts", "BarContracts\BarContracts\BarContracts.csproj", "{E1AD000E-CCA7-45AD-9E41-412819D18B12}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarDataModels", "BarDataModels\BarDataModels\BarDataModels.csproj", "{901C8DB1-06F1-45E8-B47B-2C035F87FCF0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarListImplement", "BarListImplement\BarListImplement\BarListImplement.csproj", "{FE39065B-D1CA-4CF4-9274-2160A26F8A68}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C2397C01-1A84-41C9-88FC-973959990385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2397C01-1A84-41C9-88FC-973959990385}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2397C01-1A84-41C9-88FC-973959990385}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2397C01-1A84-41C9-88FC-973959990385}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1BB13544-63F5-4C8A-AA50-0D9174D1D0B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1BB13544-63F5-4C8A-AA50-0D9174D1D0B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1BB13544-63F5-4C8A-AA50-0D9174D1D0B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1BB13544-63F5-4C8A-AA50-0D9174D1D0B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E1AD000E-CCA7-45AD-9E41-412819D18B12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E1AD000E-CCA7-45AD-9E41-412819D18B12}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E1AD000E-CCA7-45AD-9E41-412819D18B12}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E1AD000E-CCA7-45AD-9E41-412819D18B12}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{901C8DB1-06F1-45E8-B47B-2C035F87FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{901C8DB1-06F1-45E8-B47B-2C035F87FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{901C8DB1-06F1-45E8-B47B-2C035F87FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{901C8DB1-06F1-45E8-B47B-2C035F87FCF0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FE39065B-D1CA-4CF4-9274-2160A26F8A68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FE39065B-D1CA-4CF4-9274-2160A26F8A68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FE39065B-D1CA-4CF4-9274-2160A26F8A68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FE39065B-D1CA-4CF4-9274-2160A26F8A68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6DB86F5F-AD60-412B-970D-005AB04C72EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
28
Bar/Bar/BarView.csproj
Normal file
28
Bar/Bar/BarView.csproj
Normal file
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.3.2" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarBusinessLogic\BarBusinessLogic\BarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BarListImplement\BarListImplement\BarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
175
Bar/Bar/FormMain.Designer.cs
generated
Normal file
175
Bar/Bar/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,175 @@
|
||||
namespace BarView
|
||||
{
|
||||
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.CreateOrderButton = new System.Windows.Forms.Button();
|
||||
this.TakeInWorkButton = new System.Windows.Forms.Button();
|
||||
this.ReadyButton = new System.Windows.Forms.Button();
|
||||
this.IssuedButton = new System.Windows.Forms.Button();
|
||||
this.RefreshButton = new System.Windows.Forms.Button();
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.ToolStripMenu = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ComponentsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.CocktailStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// CreateOrderButton
|
||||
//
|
||||
this.CreateOrderButton.Location = new System.Drawing.Point(1073, 93);
|
||||
this.CreateOrderButton.Name = "CreateOrderButton";
|
||||
this.CreateOrderButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.CreateOrderButton.TabIndex = 9;
|
||||
this.CreateOrderButton.Text = "Создать заказ";
|
||||
this.CreateOrderButton.UseVisualStyleBackColor = true;
|
||||
this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click);
|
||||
//
|
||||
// TakeInWorkButton
|
||||
//
|
||||
this.TakeInWorkButton.Location = new System.Drawing.Point(1073, 148);
|
||||
this.TakeInWorkButton.Name = "TakeInWorkButton";
|
||||
this.TakeInWorkButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.TakeInWorkButton.TabIndex = 10;
|
||||
this.TakeInWorkButton.Text = "Отдать на выполнение";
|
||||
this.TakeInWorkButton.UseVisualStyleBackColor = true;
|
||||
this.TakeInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click);
|
||||
//
|
||||
// ReadyButton
|
||||
//
|
||||
this.ReadyButton.Location = new System.Drawing.Point(1073, 207);
|
||||
this.ReadyButton.Name = "ReadyButton";
|
||||
this.ReadyButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.ReadyButton.TabIndex = 11;
|
||||
this.ReadyButton.Text = "Заказ готов";
|
||||
this.ReadyButton.UseVisualStyleBackColor = true;
|
||||
this.ReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click);
|
||||
//
|
||||
// IssuedButton
|
||||
//
|
||||
this.IssuedButton.Location = new System.Drawing.Point(1073, 264);
|
||||
this.IssuedButton.Name = "IssuedButton";
|
||||
this.IssuedButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.IssuedButton.TabIndex = 12;
|
||||
this.IssuedButton.Text = "Заказ выдан";
|
||||
this.IssuedButton.UseVisualStyleBackColor = true;
|
||||
this.IssuedButton.Click += new System.EventHandler(this.OrderDeliveredButton_Click);
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
this.RefreshButton.Location = new System.Drawing.Point(1073, 325);
|
||||
this.RefreshButton.Name = "RefreshButton";
|
||||
this.RefreshButton.Size = new System.Drawing.Size(194, 40);
|
||||
this.RefreshButton.TabIndex = 13;
|
||||
this.RefreshButton.Text = "Обновить список";
|
||||
this.RefreshButton.UseVisualStyleBackColor = true;
|
||||
this.RefreshButton.Click += new System.EventHandler(this.RefreshButton_Click);
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Location = new System.Drawing.Point(12, 46);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 29;
|
||||
this.DataGridView.Size = new System.Drawing.Size(1029, 362);
|
||||
this.DataGridView.TabIndex = 14;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ToolStripMenu});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1279, 28);
|
||||
this.menuStrip1.TabIndex = 15;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// ToolStripMenu
|
||||
//
|
||||
this.ToolStripMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ComponentsStripMenuItem,
|
||||
this.CocktailStripMenuItem});
|
||||
this.ToolStripMenu.Name = "ToolStripMenu";
|
||||
this.ToolStripMenu.Size = new System.Drawing.Size(117, 24);
|
||||
this.ToolStripMenu.Text = "Справочники";
|
||||
//
|
||||
// ComponentsStripMenuItem
|
||||
//
|
||||
this.ComponentsStripMenuItem.Name = "ComponentsStripMenuItem";
|
||||
this.ComponentsStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.ComponentsStripMenuItem.Text = "Компоненты";
|
||||
this.ComponentsStripMenuItem.Click += new System.EventHandler(this.ComponentsStripMenuItem_Click);
|
||||
//
|
||||
// CocktailStripMenuItem
|
||||
//
|
||||
this.CocktailStripMenuItem.Name = "CocktailStripMenuItem";
|
||||
this.CocktailStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.CocktailStripMenuItem.Text = "Коктейль";
|
||||
this.CocktailStripMenuItem.Click += new System.EventHandler(this.CocktailsStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1279, 450);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Controls.Add(this.RefreshButton);
|
||||
this.Controls.Add(this.CreateOrderButton);
|
||||
this.Controls.Add(this.TakeInWorkButton);
|
||||
this.Controls.Add(this.ReadyButton);
|
||||
this.Controls.Add(this.IssuedButton);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Бар";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button CreateOrderButton;
|
||||
private Button TakeInWorkButton;
|
||||
private Button ReadyButton;
|
||||
private Button IssuedButton;
|
||||
private Button RefreshButton;
|
||||
private DataGridView DataGridView;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem ToolStripMenu;
|
||||
private ToolStripMenuItem ComponentsStripMenuItem;
|
||||
private ToolStripMenuItem CocktailStripMenuItem;
|
||||
}
|
||||
}
|
168
Bar/Bar/FormMain.cs
Normal file
168
Bar/Bar/FormMain.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarView.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
public FormMain(ILogger<FormMain> Logger, IOrderLogic OrderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_orderLogic = OrderLogic;
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
|
||||
try
|
||||
{
|
||||
var List = _orderLogic.ReadList(null);
|
||||
|
||||
if (List != null)
|
||||
{
|
||||
DataGridView.DataSource = List;
|
||||
DataGridView.Columns["CocktailId"].Visible = false;
|
||||
DataGridView.Columns["CocktailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComponentsStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
|
||||
if (Service is FormComponents Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void CocktailsStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCocktails));
|
||||
|
||||
if (Service is FormCocktails Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateOrderButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
|
||||
if (Service is FormCreateOrder Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OrderReadyButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OrderDeliveredButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
63
Bar/Bar/FormMain.resx
Normal file
63
Bar/Bar/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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>18, 23</value>
|
||||
</metadata>
|
||||
</root>
|
234
Bar/Bar/Forms/FormCocktail.Designer.cs
generated
Normal file
234
Bar/Bar/Forms/FormCocktail.Designer.cs
generated
Normal file
@ -0,0 +1,234 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
partial class FormCocktail
|
||||
{
|
||||
/// <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.NameLabel = new System.Windows.Forms.Label();
|
||||
this.NameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.RefreshButton = new System.Windows.Forms.Button();
|
||||
this.DeleteButton = new System.Windows.Forms.Button();
|
||||
this.ChangeButton = new System.Windows.Forms.Button();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.CancelButton = new System.Windows.Forms.Button();
|
||||
this.SaveButton = new System.Windows.Forms.Button();
|
||||
this.PriceTextBox = new System.Windows.Forms.TextBox();
|
||||
this.PriceLabel = new System.Windows.Forms.Label();
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.IdColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ComponentNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.CountColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ComponentsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.ComponentsGroupBox.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// NameLabel
|
||||
//
|
||||
this.NameLabel.AutoSize = true;
|
||||
this.NameLabel.Location = new System.Drawing.Point(12, 26);
|
||||
this.NameLabel.Name = "NameLabel";
|
||||
this.NameLabel.Size = new System.Drawing.Size(77, 20);
|
||||
this.NameLabel.TabIndex = 0;
|
||||
this.NameLabel.Text = "Название";
|
||||
//
|
||||
// NameTextBox
|
||||
//
|
||||
this.NameTextBox.Location = new System.Drawing.Point(101, 19);
|
||||
this.NameTextBox.Name = "NameTextBox";
|
||||
this.NameTextBox.Size = new System.Drawing.Size(275, 27);
|
||||
this.NameTextBox.TabIndex = 1;
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
this.RefreshButton.Location = new System.Drawing.Point(448, 215);
|
||||
this.RefreshButton.Name = "RefreshButton";
|
||||
this.RefreshButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.RefreshButton.TabIndex = 8;
|
||||
this.RefreshButton.Text = "Обновить";
|
||||
this.RefreshButton.UseVisualStyleBackColor = true;
|
||||
this.RefreshButton.Click += new System.EventHandler(this.RefreshButton_Click);
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
this.DeleteButton.Location = new System.Drawing.Point(448, 158);
|
||||
this.DeleteButton.Name = "DeleteButton";
|
||||
this.DeleteButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.DeleteButton.TabIndex = 7;
|
||||
this.DeleteButton.Text = "Удалить";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
this.ChangeButton.Location = new System.Drawing.Point(448, 99);
|
||||
this.ChangeButton.Name = "ChangeButton";
|
||||
this.ChangeButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.ChangeButton.TabIndex = 6;
|
||||
this.ChangeButton.Text = "Изменить";
|
||||
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||
this.ChangeButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(448, 44);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.AddButton.TabIndex = 5;
|
||||
this.AddButton.Text = "Добавить";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
this.CancelButton.Location = new System.Drawing.Point(309, 400);
|
||||
this.CancelButton.Name = "CancelButton";
|
||||
this.CancelButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.CancelButton.TabIndex = 10;
|
||||
this.CancelButton.Text = "Отмена";
|
||||
this.CancelButton.UseVisualStyleBackColor = true;
|
||||
this.CancelButton.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
this.SaveButton.Location = new System.Drawing.Point(209, 400);
|
||||
this.SaveButton.Name = "SaveButton";
|
||||
this.SaveButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.SaveButton.TabIndex = 9;
|
||||
this.SaveButton.Text = "Сохранить";
|
||||
this.SaveButton.UseVisualStyleBackColor = true;
|
||||
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||
//
|
||||
// PriceTextBox
|
||||
//
|
||||
this.PriceTextBox.Location = new System.Drawing.Point(101, 70);
|
||||
this.PriceTextBox.Name = "PriceTextBox";
|
||||
this.PriceTextBox.ReadOnly = true;
|
||||
this.PriceTextBox.Size = new System.Drawing.Size(275, 27);
|
||||
this.PriceTextBox.TabIndex = 11;
|
||||
//
|
||||
// PriceLabel
|
||||
//
|
||||
this.PriceLabel.AutoSize = true;
|
||||
this.PriceLabel.Location = new System.Drawing.Point(12, 77);
|
||||
this.PriceLabel.Name = "PriceLabel";
|
||||
this.PriceLabel.Size = new System.Drawing.Size(83, 20);
|
||||
this.PriceLabel.TabIndex = 12;
|
||||
this.PriceLabel.Text = "Стоимость";
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.IdColumn,
|
||||
this.ComponentNameColumn,
|
||||
this.CountColumn});
|
||||
this.DataGridView.Location = new System.Drawing.Point(19, 44);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 29;
|
||||
this.DataGridView.Size = new System.Drawing.Size(391, 213);
|
||||
this.DataGridView.TabIndex = 13;
|
||||
this.DataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellContentClick);
|
||||
//
|
||||
// IdColumn
|
||||
//
|
||||
this.IdColumn.HeaderText = "Id";
|
||||
this.IdColumn.MinimumWidth = 6;
|
||||
this.IdColumn.Name = "IdColumn";
|
||||
this.IdColumn.Visible = false;
|
||||
this.IdColumn.Width = 125;
|
||||
//
|
||||
// ComponentNameColumn
|
||||
//
|
||||
this.ComponentNameColumn.HeaderText = "Название";
|
||||
this.ComponentNameColumn.MinimumWidth = 6;
|
||||
this.ComponentNameColumn.Name = "ComponentNameColumn";
|
||||
this.ComponentNameColumn.Width = 125;
|
||||
//
|
||||
// CountColumn
|
||||
//
|
||||
this.CountColumn.HeaderText = "Количество";
|
||||
this.CountColumn.MinimumWidth = 6;
|
||||
this.CountColumn.Name = "CountColumn";
|
||||
this.CountColumn.Width = 125;
|
||||
//
|
||||
// ComponentsGroupBox
|
||||
//
|
||||
this.ComponentsGroupBox.Controls.Add(this.DataGridView);
|
||||
this.ComponentsGroupBox.Controls.Add(this.AddButton);
|
||||
this.ComponentsGroupBox.Controls.Add(this.ChangeButton);
|
||||
this.ComponentsGroupBox.Controls.Add(this.DeleteButton);
|
||||
this.ComponentsGroupBox.Controls.Add(this.RefreshButton);
|
||||
this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 118);
|
||||
this.ComponentsGroupBox.Name = "ComponentsGroupBox";
|
||||
this.ComponentsGroupBox.Size = new System.Drawing.Size(574, 276);
|
||||
this.ComponentsGroupBox.TabIndex = 14;
|
||||
this.ComponentsGroupBox.TabStop = false;
|
||||
this.ComponentsGroupBox.Text = "Компоненты";
|
||||
//
|
||||
// FormCocktail
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.ComponentsGroupBox);
|
||||
this.Controls.Add(this.PriceLabel);
|
||||
this.Controls.Add(this.PriceTextBox);
|
||||
this.Controls.Add(this.CancelButton);
|
||||
this.Controls.Add(this.SaveButton);
|
||||
this.Controls.Add(this.NameTextBox);
|
||||
this.Controls.Add(this.NameLabel);
|
||||
this.Name = "FormCocktail";
|
||||
this.Text = "Коктейль";
|
||||
this.Load += new System.EventHandler(this.FormCocktail_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.ComponentsGroupBox.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label NameLabel;
|
||||
private TextBox NameTextBox;
|
||||
private Button RefreshButton;
|
||||
private Button DeleteButton;
|
||||
private Button ChangeButton;
|
||||
private Button AddButton;
|
||||
private Button CancelButton;
|
||||
private Button SaveButton;
|
||||
private TextBox PriceTextBox;
|
||||
private Label PriceLabel;
|
||||
private DataGridView DataGridView;
|
||||
private GroupBox ComponentsGroupBox;
|
||||
private DataGridViewTextBoxColumn IdColumn;
|
||||
private DataGridViewTextBoxColumn ComponentNameColumn;
|
||||
private DataGridViewTextBoxColumn CountColumn;
|
||||
}
|
||||
}
|
241
Bar/Bar/Forms/FormCocktail.cs
Normal file
241
Bar/Bar/Forms/FormCocktail.cs
Normal file
@ -0,0 +1,241 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
public partial class FormCocktail : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly ICocktailLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)> _CocktailComponents;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormCocktail(ILogger<FormCocktail> Logger, ICocktailLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
_CocktailComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||
}
|
||||
|
||||
private void FormCocktail_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка коктеля");
|
||||
|
||||
try
|
||||
{
|
||||
var View = _logic.ReadElement(new CocktailSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
|
||||
if (View != null)
|
||||
{
|
||||
NameTextBox.Text = View.CocktailName;
|
||||
PriceTextBox.Text = View.Price.ToString();
|
||||
|
||||
_CocktailComponents = View.CocktailComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки коктеля");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонентов коктеля");
|
||||
|
||||
try
|
||||
{
|
||||
if (_CocktailComponents != null)
|
||||
{
|
||||
DataGridView.Rows.Clear();
|
||||
foreach (var Comp in _CocktailComponents)
|
||||
{
|
||||
DataGridView.Rows.Add(new object[] { Comp.Key, Comp.Value.Item1.ComponentName, Comp.Value.Item2 });
|
||||
}
|
||||
|
||||
PriceTextBox.Text = CalcPrice().ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов коктеля");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCocktailComponent));
|
||||
|
||||
if (Service is FormCocktailComponent Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (Form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", Form.ComponentModel.ComponentName, Form.Count);
|
||||
|
||||
if (_CocktailComponents.ContainsKey(Form.Id))
|
||||
{
|
||||
_CocktailComponents[Form.Id] = (Form.ComponentModel, Form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CocktailComponents.Add(Form.Id, (Form.ComponentModel, Form.Count));
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCocktailComponent));
|
||||
if (service is FormCocktailComponent Form)
|
||||
{
|
||||
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value);
|
||||
Form.Id = id;
|
||||
Form.Count = _CocktailComponents[id].Item2;
|
||||
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (Form.ComponentModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", Form.ComponentModel.ComponentName, Form.Count);
|
||||
_CocktailComponents[Form.Id] = (Form.ComponentModel, Form.Count);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_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,
|
||||
DataGridView.SelectedRows[0].Cells[2].Value);
|
||||
|
||||
_CocktailComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(NameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(PriceTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_CocktailComponents == null || _CocktailComponents.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение коктеля");
|
||||
|
||||
try
|
||||
{
|
||||
var Мodel = new CocktailBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
CocktailName = NameTextBox.Text,
|
||||
Price = Convert.ToDouble(PriceTextBox.Text),
|
||||
CocktailComponents = _CocktailComponents
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(Мodel) : _logic.Create(Мodel);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private double CalcPrice()
|
||||
{
|
||||
double Price = 0;
|
||||
|
||||
foreach (var Elem in _CocktailComponents)
|
||||
{
|
||||
Price += ((Elem.Value.Item1?.Cost ?? 0) * Elem.Value.Item2);
|
||||
}
|
||||
|
||||
return Math.Round(Price * 1, 2);
|
||||
}
|
||||
|
||||
private void DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
69
Bar/Bar/Forms/FormCocktail.resx
Normal file
69
Bar/Bar/Forms/FormCocktail.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="IdColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ComponentNameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="CountColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
119
Bar/Bar/Forms/FormCocktailComponent.Designer.cs
generated
Normal file
119
Bar/Bar/Forms/FormCocktailComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
partial class FormCocktailComponent
|
||||
{
|
||||
/// <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.ComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ComboBox
|
||||
//
|
||||
this.ComboBox.FormattingEnabled = true;
|
||||
this.ComboBox.Location = new System.Drawing.Point(110, 26);
|
||||
this.ComboBox.Name = "ComboBox";
|
||||
this.ComboBox.Size = new System.Drawing.Size(227, 28);
|
||||
this.ComboBox.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(10, 29);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(88, 20);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Компонент";
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
this.CountTextBox.Location = new System.Drawing.Point(110, 72);
|
||||
this.CountTextBox.Name = "CountTextBox";
|
||||
this.CountTextBox.Size = new System.Drawing.Size(227, 27);
|
||||
this.CountTextBox.TabIndex = 2;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(91, 130);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(94, 29);
|
||||
this.button1.TabIndex = 3;
|
||||
this.button1.Text = "Сохранить";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(191, 130);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(94, 29);
|
||||
this.button2.TabIndex = 4;
|
||||
this.button2.Text = "Отмена";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(10, 75);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(90, 20);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "Количество";
|
||||
//
|
||||
// FormCocktailComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(388, 219);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.CountTextBox);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.ComboBox);
|
||||
this.Name = "FormCocktailComponent";
|
||||
this.Text = "Компонент коктейля";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox ComboBox;
|
||||
private Label label1;
|
||||
private TextBox CountTextBox;
|
||||
private Button button1;
|
||||
private Button button2;
|
||||
private Label label2;
|
||||
}
|
||||
}
|
89
Bar/Bar/Forms/FormCocktailComponent.cs
Normal file
89
Bar/Bar/Forms/FormCocktailComponent.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
public partial class FormCocktailComponent : Form
|
||||
{
|
||||
private readonly List<ComponentViewModel>? _list;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(ComboBox.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
ComboBox.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(CountTextBox.Text); }
|
||||
set { CountTextBox.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
public FormCocktailComponent(IComponentLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_list = Logic.ReadList(null);
|
||||
|
||||
if (_list != null)
|
||||
{
|
||||
ComboBox.DisplayMember = "ComponentName";
|
||||
ComboBox.ValueMember = "Id";
|
||||
ComboBox.DataSource = _list;
|
||||
ComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ComboBox.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
Bar/Bar/Forms/FormCocktailComponent.resx
Normal file
60
Bar/Bar/Forms/FormCocktailComponent.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>
|
116
Bar/Bar/Forms/FormCocktails.Designer.cs
generated
Normal file
116
Bar/Bar/Forms/FormCocktails.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
partial class FormCocktails
|
||||
{
|
||||
/// <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.RefreshButton = new System.Windows.Forms.Button();
|
||||
this.DeleteButton = new System.Windows.Forms.Button();
|
||||
this.ChangeButton = new System.Windows.Forms.Button();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
this.RefreshButton.Location = new System.Drawing.Point(571, 196);
|
||||
this.RefreshButton.Name = "RefreshButton";
|
||||
this.RefreshButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.RefreshButton.TabIndex = 9;
|
||||
this.RefreshButton.Text = "Обновить";
|
||||
this.RefreshButton.UseVisualStyleBackColor = true;
|
||||
this.RefreshButton.Click += new System.EventHandler(this.RefreshButton_Click);
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
this.DeleteButton.Location = new System.Drawing.Point(571, 139);
|
||||
this.DeleteButton.Name = "DeleteButton";
|
||||
this.DeleteButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.DeleteButton.TabIndex = 8;
|
||||
this.DeleteButton.Text = "Удалить";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
this.ChangeButton.Location = new System.Drawing.Point(571, 80);
|
||||
this.ChangeButton.Name = "ChangeButton";
|
||||
this.ChangeButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.ChangeButton.TabIndex = 7;
|
||||
this.ChangeButton.Text = "Изменить";
|
||||
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||
this.ChangeButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(571, 25);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.AddButton.TabIndex = 6;
|
||||
this.AddButton.Text = "Добавить";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Location = new System.Drawing.Point(12, 25);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 29;
|
||||
this.DataGridView.Size = new System.Drawing.Size(542, 385);
|
||||
this.DataGridView.TabIndex = 5;
|
||||
this.DataGridView.SelectionChanged += new System.EventHandler(this.DataGridView_SelectionChanged);
|
||||
//
|
||||
// FormCocktails
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(683, 439);
|
||||
this.Controls.Add(this.RefreshButton);
|
||||
this.Controls.Add(this.DeleteButton);
|
||||
this.Controls.Add(this.ChangeButton);
|
||||
this.Controls.Add(this.AddButton);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Name = "FormCocktails";
|
||||
this.Text = "Коктейли";
|
||||
this.Load += new System.EventHandler(this.FormCocktails_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button RefreshButton;
|
||||
private Button DeleteButton;
|
||||
private Button ChangeButton;
|
||||
private Button AddButton;
|
||||
private DataGridView DataGridView;
|
||||
}
|
||||
}
|
118
Bar/Bar/Forms/FormCocktails.cs
Normal file
118
Bar/Bar/Forms/FormCocktails.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
public partial class FormCocktails : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICocktailLogic _logic;
|
||||
|
||||
public FormCocktails(ILogger<FormCocktails> Logger, ICocktailLogic Logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_logic = Logic;
|
||||
}
|
||||
|
||||
private void FormCocktails_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["CocktailName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["CocktailComponents"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка коктеля");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки коктеля");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCocktail));
|
||||
|
||||
if (Service is FormCocktail Form)
|
||||
{
|
||||
if (Form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormCocktail));
|
||||
|
||||
if (Service is FormCocktail Form)
|
||||
{
|
||||
var Temp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
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("Удаление коктеля");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new CocktailBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления коктеля");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void DataGridView_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
60
Bar/Bar/Forms/FormCocktails.resx
Normal file
60
Bar/Bar/Forms/FormCocktails.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>
|
119
Bar/Bar/Forms/FormComponent.Designer.cs
generated
Normal file
119
Bar/Bar/Forms/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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.Save = new System.Windows.Forms.Button();
|
||||
this.ComponentNameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.ComponentPriceTextBox = new System.Windows.Forms.TextBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Save
|
||||
//
|
||||
this.Save.Location = new System.Drawing.Point(68, 132);
|
||||
this.Save.Name = "Save";
|
||||
this.Save.Size = new System.Drawing.Size(94, 29);
|
||||
this.Save.TabIndex = 0;
|
||||
this.Save.Text = "Сохранить";
|
||||
this.Save.UseVisualStyleBackColor = true;
|
||||
this.Save.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// ComponentNameTextBox
|
||||
//
|
||||
this.ComponentNameTextBox.Location = new System.Drawing.Point(99, 23);
|
||||
this.ComponentNameTextBox.Name = "ComponentNameTextBox";
|
||||
this.ComponentNameTextBox.Size = new System.Drawing.Size(234, 27);
|
||||
this.ComponentNameTextBox.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 26);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(80, 20);
|
||||
this.label1.TabIndex = 2;
|
||||
this.label1.Text = "Название:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 69);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(48, 20);
|
||||
this.label2.TabIndex = 3;
|
||||
this.label2.Text = "Цена:";
|
||||
//
|
||||
// ComponentPriceTextBox
|
||||
//
|
||||
this.ComponentPriceTextBox.Location = new System.Drawing.Point(99, 62);
|
||||
this.ComponentPriceTextBox.Name = "ComponentPriceTextBox";
|
||||
this.ComponentPriceTextBox.Size = new System.Drawing.Size(234, 27);
|
||||
this.ComponentPriceTextBox.TabIndex = 4;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(168, 132);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(94, 29);
|
||||
this.button1.TabIndex = 5;
|
||||
this.button1.Text = "Отмена";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(345, 183);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.ComponentPriceTextBox);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.ComponentNameTextBox);
|
||||
this.Controls.Add(this.Save);
|
||||
this.Name = "FormComponent";
|
||||
this.Text = "Компонент";
|
||||
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button Save;
|
||||
private TextBox ComponentNameTextBox;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox ComponentPriceTextBox;
|
||||
private Button button1;
|
||||
}
|
||||
}
|
95
Bar/Bar/Forms/FormComponent.cs
Normal file
95
Bar/Bar/Forms/FormComponent.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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("Получение компонента");
|
||||
var View = _logic.ReadElement(new ComponentSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
|
||||
if (View != null)
|
||||
{
|
||||
ComponentNameTextBox.Text = View.ComponentName;
|
||||
ComponentPriceTextBox.Text = View.Cost.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ComponentNameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Сохранение компонента");
|
||||
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ComponentName = ComponentNameTextBox.Text,
|
||||
Cost = Convert.ToDouble(ComponentPriceTextBox.Text)
|
||||
};
|
||||
|
||||
var OperationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
|
||||
if (!OperationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
Bar/Bar/Forms/FormComponent.resx
Normal file
60
Bar/Bar/Forms/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>
|
115
Bar/Bar/Forms/FormComponents.Designer.cs
generated
Normal file
115
Bar/Bar/Forms/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,115 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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.AddButton = new System.Windows.Forms.Button();
|
||||
this.ChangeButton = new System.Windows.Forms.Button();
|
||||
this.DeleteButton = new System.Windows.Forms.Button();
|
||||
this.RefreshButton = 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(12, 30);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 29;
|
||||
this.DataGridView.Size = new System.Drawing.Size(542, 385);
|
||||
this.DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(571, 30);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.AddButton.TabIndex = 1;
|
||||
this.AddButton.Text = "Добавить";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
this.ChangeButton.Location = new System.Drawing.Point(571, 85);
|
||||
this.ChangeButton.Name = "ChangeButton";
|
||||
this.ChangeButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.ChangeButton.TabIndex = 2;
|
||||
this.ChangeButton.Text = "Изменить";
|
||||
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
this.DeleteButton.Location = new System.Drawing.Point(571, 144);
|
||||
this.DeleteButton.Name = "DeleteButton";
|
||||
this.DeleteButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.DeleteButton.TabIndex = 3;
|
||||
this.DeleteButton.Text = "Удалить";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// RefreshButton
|
||||
//
|
||||
this.RefreshButton.Location = new System.Drawing.Point(571, 201);
|
||||
this.RefreshButton.Name = "RefreshButton";
|
||||
this.RefreshButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.RefreshButton.TabIndex = 4;
|
||||
this.RefreshButton.Text = "Обновить";
|
||||
this.RefreshButton.UseVisualStyleBackColor = true;
|
||||
this.RefreshButton.Click += new System.EventHandler(this.RefreshButton_Click);
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(689, 435);
|
||||
this.Controls.Add(this.RefreshButton);
|
||||
this.Controls.Add(this.DeleteButton);
|
||||
this.Controls.Add(this.ChangeButton);
|
||||
this.Controls.Add(this.AddButton);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Name = "FormComponents";
|
||||
this.Text = "Компоненты";
|
||||
this.Load += new System.EventHandler(this.ComponentsForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button ChangeButton;
|
||||
private Button DeleteButton;
|
||||
private Button RefreshButton;
|
||||
}
|
||||
}
|
114
Bar/Bar/Forms/FormComponents.cs
Normal file
114
Bar/Bar/Forms/FormComponents.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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 ComponentsForm_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("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_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 ChangeButton_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 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("Удаление компонента");
|
||||
|
||||
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 RefreshButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
60
Bar/Bar/Forms/FormComponents.resx
Normal file
60
Bar/Bar/Forms/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>
|
145
Bar/Bar/Forms/FormCreateOrder.Designer.cs
generated
Normal file
145
Bar/Bar/Forms/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,145 @@
|
||||
namespace BarView.Forms
|
||||
{
|
||||
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.CancelButton = new System.Windows.Forms.Button();
|
||||
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||
this.CountLabel = new System.Windows.Forms.Label();
|
||||
this.CocktailLabel = new System.Windows.Forms.Label();
|
||||
this.SaveButton = new System.Windows.Forms.Button();
|
||||
this.SumTextBox = new System.Windows.Forms.TextBox();
|
||||
this.SumLabel = new System.Windows.Forms.Label();
|
||||
this.CocktailComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// CancelButton
|
||||
//
|
||||
this.CancelButton.Location = new System.Drawing.Point(177, 147);
|
||||
this.CancelButton.Name = "CancelButton";
|
||||
this.CancelButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.CancelButton.TabIndex = 11;
|
||||
this.CancelButton.Text = "Отмена";
|
||||
this.CancelButton.UseVisualStyleBackColor = true;
|
||||
this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
this.CountTextBox.Location = new System.Drawing.Point(116, 56);
|
||||
this.CountTextBox.Name = "CountTextBox";
|
||||
this.CountTextBox.Size = new System.Drawing.Size(234, 27);
|
||||
this.CountTextBox.TabIndex = 10;
|
||||
this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged);
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
this.CountLabel.AutoSize = true;
|
||||
this.CountLabel.Location = new System.Drawing.Point(12, 63);
|
||||
this.CountLabel.Name = "CountLabel";
|
||||
this.CountLabel.Size = new System.Drawing.Size(93, 20);
|
||||
this.CountLabel.TabIndex = 9;
|
||||
this.CountLabel.Text = "Количество:";
|
||||
//
|
||||
// CocktailLabel
|
||||
//
|
||||
this.CocktailLabel.AutoSize = true;
|
||||
this.CocktailLabel.Location = new System.Drawing.Point(12, 20);
|
||||
this.CocktailLabel.Name = "CocktailLabel";
|
||||
this.CocktailLabel.Size = new System.Drawing.Size(76, 20);
|
||||
this.CocktailLabel.TabIndex = 8;
|
||||
this.CocktailLabel.Text = "Коктейль:";
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
this.SaveButton.Location = new System.Drawing.Point(77, 147);
|
||||
this.SaveButton.Name = "SaveButton";
|
||||
this.SaveButton.Size = new System.Drawing.Size(94, 29);
|
||||
this.SaveButton.TabIndex = 6;
|
||||
this.SaveButton.Text = "Сохранить";
|
||||
this.SaveButton.UseVisualStyleBackColor = true;
|
||||
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||
//
|
||||
// SumTextBox
|
||||
//
|
||||
this.SumTextBox.Location = new System.Drawing.Point(116, 93);
|
||||
this.SumTextBox.Name = "SumTextBox";
|
||||
this.SumTextBox.ReadOnly = true;
|
||||
this.SumTextBox.Size = new System.Drawing.Size(234, 27);
|
||||
this.SumTextBox.TabIndex = 13;
|
||||
//
|
||||
// SumLabel
|
||||
//
|
||||
this.SumLabel.AutoSize = true;
|
||||
this.SumLabel.Location = new System.Drawing.Point(12, 100);
|
||||
this.SumLabel.Name = "SumLabel";
|
||||
this.SumLabel.Size = new System.Drawing.Size(58, 20);
|
||||
this.SumLabel.TabIndex = 12;
|
||||
this.SumLabel.Text = "Сумма:";
|
||||
//
|
||||
// CocktailComboBox
|
||||
//
|
||||
this.CocktailComboBox.FormattingEnabled = true;
|
||||
this.CocktailComboBox.Location = new System.Drawing.Point(115, 17);
|
||||
this.CocktailComboBox.Name = "CocktailComboBox";
|
||||
this.CocktailComboBox.Size = new System.Drawing.Size(235, 28);
|
||||
this.CocktailComboBox.TabIndex = 14;
|
||||
this.CocktailComboBox.SelectedIndexChanged += new System.EventHandler(this.CocktailComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(362, 199);
|
||||
this.Controls.Add(this.CocktailComboBox);
|
||||
this.Controls.Add(this.SumTextBox);
|
||||
this.Controls.Add(this.SumLabel);
|
||||
this.Controls.Add(this.CancelButton);
|
||||
this.Controls.Add(this.CountTextBox);
|
||||
this.Controls.Add(this.CountLabel);
|
||||
this.Controls.Add(this.CocktailLabel);
|
||||
this.Controls.Add(this.SaveButton);
|
||||
this.Name = "FormCreateOrder";
|
||||
this.Text = "FormCreateOrder";
|
||||
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button CancelButton;
|
||||
private TextBox CountTextBox;
|
||||
private Label CountLabel;
|
||||
private Label CocktailLabel;
|
||||
private Button SaveButton;
|
||||
private TextBox SumTextBox;
|
||||
private Label SumLabel;
|
||||
private ComboBox CocktailComboBox;
|
||||
}
|
||||
}
|
128
Bar/Bar/Forms/FormCreateOrder.cs
Normal file
128
Bar/Bar/Forms/FormCreateOrder.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarView.Forms
|
||||
{
|
||||
public partial class FormCreateOrder : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICocktailLogic _cocktailLogic;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> Logger, ICocktailLogic CocktailLogic, IOrderLogic OrderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_logger = Logger;
|
||||
_cocktailLogic = CocktailLogic;
|
||||
_orderLogic = OrderLogic;
|
||||
}
|
||||
|
||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка коктелей для заказа");
|
||||
|
||||
try
|
||||
{
|
||||
var List = _cocktailLogic.ReadList(null);
|
||||
if (List != null)
|
||||
{
|
||||
CocktailComboBox.DisplayMember = "CocktailName";
|
||||
CocktailComboBox.ValueMember = "Id";
|
||||
CocktailComboBox.DataSource = List;
|
||||
CocktailComboBox.SelectedItem = null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Коктели загружены");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки коктелей");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CalcSum()
|
||||
{
|
||||
if (CocktailComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(CocktailComboBox.SelectedValue);
|
||||
var Cocktail = _cocktailLogic.ReadElement(new CocktailSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
int Count = Convert.ToInt32(CountTextBox.Text);
|
||||
|
||||
SumTextBox.Text = Math.Round(Count * (Cocktail?.Price ?? 0), 2).ToString();
|
||||
|
||||
_logger.LogInformation("Расчет суммы заказа");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CountTextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(CountTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CocktailComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите коктель", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Создание заказа");
|
||||
|
||||
try
|
||||
{
|
||||
var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
CocktailId = Convert.ToInt32(CocktailComboBox.SelectedValue),
|
||||
Count = Convert.ToInt32(CountTextBox.Text),
|
||||
Sum = Convert.ToDouble(SumTextBox.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 CancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CocktailComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcSum();
|
||||
}
|
||||
}
|
||||
}
|
60
Bar/Bar/Forms/FormCreateOrder.resx
Normal file
60
Bar/Bar/Forms/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>
|
54
Bar/Bar/Program.cs
Normal file
54
Bar/Bar/Program.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using BarBusinessLogic.BusinessLogics;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarListImplement.Implements;
|
||||
using BarView.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
|
||||
namespace BarView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
||||
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<ICocktailStorage, CocktailStorage>();
|
||||
Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
Services.AddTransient<ICocktailLogic, CocktailLogic>();
|
||||
|
||||
Services.AddTransient<FormMain>();
|
||||
Services.AddTransient<FormComponent>();
|
||||
Services.AddTransient<FormComponents>();
|
||||
Services.AddTransient<FormCreateOrder>();
|
||||
Services.AddTransient<FormCocktail>();
|
||||
Services.AddTransient<FormCocktailComponent>();
|
||||
Services.AddTransient<FormCocktails>();
|
||||
}
|
||||
}
|
||||
}
|
9
Bar/Bar/nlog.config
Normal file
9
Bar/Bar/nlog.config
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog throwExceptions="true">
|
||||
<targets>
|
||||
<target name="file" type="File" fileName="${basedir}/log.txt" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minLevel="Trace" writeTo="file" />
|
||||
</rules>
|
||||
</nlog>
|
31
Bar/BarBusinessLogic/BarBusinessLogic.sln
Normal file
31
Bar/BarBusinessLogic/BarBusinessLogic.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarBusinessLogic", "BarBusinessLogic\BarBusinessLogic.csproj", "{1D8E732A-3606-4D9D-93C3-B462140CCD42}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarContracts", "..\BarContracts\BarContracts\BarContracts.csproj", "{4F98835A-6D71-4F8C-A54B-65EA47207D69}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1D8E732A-3606-4D9D-93C3-B462140CCD42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1D8E732A-3606-4D9D-93C3-B462140CCD42}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1D8E732A-3606-4D9D-93C3-B462140CCD42}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1D8E732A-3606-4D9D-93C3-B462140CCD42}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4F98835A-6D71-4F8C-A54B-65EA47207D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4F98835A-6D71-4F8C-A54B-65EA47207D69}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4F98835A-6D71-4F8C-A54B-65EA47207D69}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4F98835A-6D71-4F8C-A54B-65EA47207D69}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C7A22A4A-209E-46CA-AFC1-B5E2138647CB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BarContracts\BarContracts\BarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,126 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CocktailLogic : ICocktailLogic
|
||||
{
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly ICocktailStorage _cocktailStorage;
|
||||
|
||||
public CocktailLogic(ILogger<CocktailLogic> Logger, ICocktailStorage CocktailStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_cocktailStorage = CocktailStorage;
|
||||
}
|
||||
|
||||
public List<CocktailViewModel>? ReadList(CocktailSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. CocktailName:{CocktailName}. Id:{Id}",
|
||||
Model?.CocktailName, Model?.Id);
|
||||
|
||||
var List = Model is null ? _cocktailStorage.GetFullList() : _cocktailStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", List.Count);
|
||||
return List;
|
||||
}
|
||||
|
||||
public CocktailViewModel? ReadElement(CocktailSearchModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
_logger.LogInformation("ReadElement. CocktailName:{CocktailName}. Id:{Id}",
|
||||
Model.CocktailName, Model.Id);
|
||||
|
||||
var Element = _cocktailStorage.GetElement(Model);
|
||||
|
||||
if (Element is null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(CocktailBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_cocktailStorage.Insert(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CocktailBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_cocktailStorage.Update(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CocktailBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
_logger.LogInformation("Delete. Id:{Id}", Model.Id);
|
||||
|
||||
if (_cocktailStorage.Delete(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CocktailBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(Model.CocktailName))
|
||||
throw new ArgumentNullException("Нет названия коктеля", nameof(Model.CocktailName));
|
||||
|
||||
if (Model.Price <= 0)
|
||||
throw new ArgumentNullException("Стоимость коктеля должна быть больше 0", nameof(Model.Price));
|
||||
|
||||
_logger.LogInformation("Cocktail. CocktailName:{CocktailName}. Price:{Price}. Id: {Id}",
|
||||
Model.CocktailName, Model.Price, Model.Id);
|
||||
|
||||
var Element = _cocktailStorage.GetElement(new CocktailSearchModel
|
||||
{
|
||||
CocktailName = Model.CocktailName
|
||||
});
|
||||
|
||||
if (Element != null && Element.Id != Model.Id)
|
||||
throw new InvalidOperationException("Коктель с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarBusinessLogic.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 is null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is 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 is null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}",
|
||||
Model.ComponentName, Model.Id);
|
||||
|
||||
var Element = _componentStorage.GetElement(Model);
|
||||
|
||||
if (Element is null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement element found. Id:{Id}", Element.Id);
|
||||
return Element;
|
||||
}
|
||||
|
||||
public bool Create(ComponentBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_componentStorage.Insert(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel Model)
|
||||
{
|
||||
CheckModel(Model);
|
||||
|
||||
if (_componentStorage.Update(Model) is 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) is 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("Cocktail. 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("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.BusinessLogicContracts;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BarBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<CocktailLogic> Logger, IOrderStorage OrderStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_orderStorage = OrderStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? Model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", Model?.Id);
|
||||
var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model);
|
||||
|
||||
if (List is 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.Undefined)
|
||||
{
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
|
||||
Model.Status = OrderStatus.Accepted;
|
||||
|
||||
if (_orderStorage.Insert(Model) is null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ChangeOrderStatus(OrderBindingModel Model, OrderStatus NewStatus)
|
||||
{
|
||||
CheckModel(Model, false);
|
||||
|
||||
var Order = _orderStorage.GetElement(new OrderSearchModel { Id = Model.Id });
|
||||
|
||||
if (Order == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Order not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Order.Status + 1 != NewStatus)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Incorrect new status: {NewStatus}. Current status: {currStatus}",
|
||||
NewStatus, Order.Status);
|
||||
return false;
|
||||
}
|
||||
|
||||
Model.CocktailId = Order.CocktailId;
|
||||
Model.Count = Order.Count;
|
||||
Model.Sum = Order.Sum;
|
||||
Model.DateCreate = Order.DateCreate;
|
||||
Model.Status = NewStatus;
|
||||
|
||||
if (Model.Status == OrderStatus.Ready)
|
||||
Model.DateImplement = DateTime.Now;
|
||||
else
|
||||
Model.DateImplement = Order.DateImplement;
|
||||
|
||||
if (_orderStorage.Update(Model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.BeingProcessed);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.Ready);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel Model)
|
||||
{
|
||||
return ChangeOrderStatus(Model, OrderStatus.Delivered);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel Model, bool WithParams = true)
|
||||
{
|
||||
if (Model == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
if (!WithParams)
|
||||
return;
|
||||
|
||||
if (Model.Count <= 0)
|
||||
throw new ArgumentNullException("Количество напитков в заказе быть больше 0", nameof(Model.Count));
|
||||
|
||||
if (Model.Sum <= 0)
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(Model.Sum));
|
||||
|
||||
_logger.LogInformation("Order. CocktailId:{CocktailId}. Count:{Count}. Sum:{Sum}. " +
|
||||
"Status:{Status}. DateCreate:{DateCreate}. DateImplement:{DateImplement}. Id: {Id}",
|
||||
Model.CocktailId, Model.Count, Model.Sum, Model.Status, Model.DateCreate,
|
||||
Model.DateImplement, Model.Id);
|
||||
}
|
||||
}
|
||||
}
|
25
Bar/BarContracts/BarContracts.sln
Normal file
25
Bar/BarContracts/BarContracts.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarContracts", "BarContracts\BarContracts.csproj", "{B9C63DFA-D1AE-42D0-B8ED-4027B631B5C5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B9C63DFA-D1AE-42D0-B8ED-4027B631B5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B9C63DFA-D1AE-42D0-B8ED-4027B631B5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B9C63DFA-D1AE-42D0-B8ED-4027B631B5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B9C63DFA-D1AE-42D0-B8ED-4027B631B5C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6E9D42DC-B2B8-4176-8796-05D4EA3EF847}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
13
Bar/BarContracts/BarContracts/BarContracts.csproj
Normal file
13
Bar/BarContracts/BarContracts/BarContracts.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="..\..\BarDataModels\BarDataModels\BarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,16 @@
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarContracts.BindingModels
|
||||
{
|
||||
public class CocktailBindingModel : ICocktailModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> CocktailComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarContracts.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 BarDataModels.Enums;
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int CocktailId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface ICocktailLogic
|
||||
{
|
||||
List<CocktailViewModel>? ReadList(CocktailSearchModel? Model);
|
||||
CocktailViewModel? ReadElement(CocktailSearchModel Model);
|
||||
bool Create(CocktailBindingModel Model);
|
||||
bool Update(CocktailBindingModel Model);
|
||||
bool Delete(CocktailBindingModel Model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.BusinessLogicContracts
|
||||
{
|
||||
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 BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.BusinessLogicContracts
|
||||
{
|
||||
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,8 @@
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class CocktailSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? CocktailName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class ComponentSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ComponentName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace BarContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.StoragesContracts
|
||||
{
|
||||
public interface ICocktailStorage
|
||||
{
|
||||
List<CocktailViewModel> GetFullList();
|
||||
List<CocktailViewModel> GetFilteredList(CocktailSearchModel Model);
|
||||
CocktailViewModel? GetElement(CocktailSearchModel Model);
|
||||
CocktailViewModel? Insert(CocktailBindingModel Model);
|
||||
CocktailViewModel? Update(CocktailBindingModel Model);
|
||||
CocktailViewModel? Delete(CocktailBindingModel Model);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.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 BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.ViewModels;
|
||||
|
||||
namespace BarContracts.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,22 @@
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class CocktailViewModel : ICocktailModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название Коктейля")]
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> CocktailComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название компонента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
33
Bar/BarContracts/BarContracts/ViewModels/OrderViewModel.cs
Normal file
33
Bar/BarContracts/BarContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using BarDataModels.Enums;
|
||||
using BarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace BarContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int CocktailId { get; set; }
|
||||
|
||||
[DisplayName("Коктейль")]
|
||||
public string CocktailName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Undefined;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
25
Bar/BarDataModels/BarDataModels.sln
Normal file
25
Bar/BarDataModels/BarDataModels.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarDataModels", "BarDataModels\BarDataModels.csproj", "{6A6D7927-57EC-49C0-A002-0E4074CAE8A4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6A6D7927-57EC-49C0-A002-0E4074CAE8A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6A6D7927-57EC-49C0-A002-0E4074CAE8A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6A6D7927-57EC-49C0-A002-0E4074CAE8A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6A6D7927-57EC-49C0-A002-0E4074CAE8A4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8D3AA9E7-9CF4-4075-966E-AAB6D6F95124}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
9
Bar/BarDataModels/BarDataModels/BarDataModels.csproj
Normal file
9
Bar/BarDataModels/BarDataModels/BarDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
11
Bar/BarDataModels/BarDataModels/Enums/OrderStatus.cs
Normal file
11
Bar/BarDataModels/BarDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace BarDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Undefined = -1,
|
||||
Accepted,
|
||||
BeingProcessed,
|
||||
Ready,
|
||||
Delivered,
|
||||
}
|
||||
}
|
9
Bar/BarDataModels/BarDataModels/Models/ICocktailModel.cs
Normal file
9
Bar/BarDataModels/BarDataModels/Models/ICocktailModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace BarDataModels.Models
|
||||
{
|
||||
public interface ICocktailModel : IId
|
||||
{
|
||||
string CocktailName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> CocktailComponents { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace BarDataModels.Models
|
||||
{
|
||||
public interface IComponentModel : IId
|
||||
{
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
}
|
||||
}
|
7
Bar/BarDataModels/BarDataModels/Models/IId.cs
Normal file
7
Bar/BarDataModels/BarDataModels/Models/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace BarDataModels.Models
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
14
Bar/BarDataModels/BarDataModels/Models/IOrderModel.cs
Normal file
14
Bar/BarDataModels/BarDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using BarDataModels.Enums;
|
||||
|
||||
namespace BarDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int CocktailId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
25
Bar/BarListImplement/BarListImplement.sln
Normal file
25
Bar/BarListImplement/BarListImplement.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarListImplement", "BarListImplement\BarListImplement.csproj", "{ABC3A8B4-F95A-458D-986D-2A8B7E8F1024}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ABC3A8B4-F95A-458D-986D-2A8B7E8F1024}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{ABC3A8B4-F95A-458D-986D-2A8B7E8F1024}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{ABC3A8B4-F95A-458D-986D-2A8B7E8F1024}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{ABC3A8B4-F95A-458D-986D-2A8B7E8F1024}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B8F100C6-B92B-46E1-88CB-A371502E4134}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BarContracts\BarContracts\BarContracts.csproj" />
|
||||
<ProjectReference Include="..\..\BarDataModels\BarDataModels\BarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
32
Bar/BarListImplement/BarListImplement/DataListSingleton.cs
Normal file
32
Bar/BarListImplement/BarListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using BarListImplement.Models;
|
||||
|
||||
namespace BarListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
|
||||
public List<Component> Components { get; set; }
|
||||
|
||||
public List<Order> Orders { get; set; }
|
||||
|
||||
public List<Cocktail> Cocktails { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Cocktails = new List<Cocktail>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarListImplement.Models;
|
||||
|
||||
namespace BarListImplement.Implements
|
||||
{
|
||||
public class CocktailStorage : ICocktailStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public CocktailStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<CocktailViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<CocktailViewModel>();
|
||||
|
||||
foreach (var Cocktail in _source.Cocktails)
|
||||
{
|
||||
Result.Add(Cocktail.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<CocktailViewModel> GetFilteredList(CocktailSearchModel Model)
|
||||
{
|
||||
var Result = new List<CocktailViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.CocktailName))
|
||||
return Result;
|
||||
|
||||
foreach (var Cocktail in _source.Cocktails)
|
||||
{
|
||||
if (Cocktail.CocktailName.Contains(Model.CocktailName))
|
||||
{
|
||||
Result.Add(Cocktail.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public CocktailViewModel? GetElement(CocktailSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.CocktailName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Cocktail in _source.Cocktails)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.CocktailName)
|
||||
&& Cocktail.CocktailName == Model.CocktailName)
|
||||
|| (Model.Id.HasValue && Cocktail.Id == Model.Id))
|
||||
{
|
||||
return Cocktail.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CocktailViewModel? Insert(CocktailBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Cocktail in _source.Cocktails)
|
||||
{
|
||||
if (Model.Id <= Cocktail.Id)
|
||||
{
|
||||
Model.Id = Cocktail.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewCocktail = Cocktail.Create(Model);
|
||||
|
||||
if (NewCocktail == null)
|
||||
return null;
|
||||
|
||||
_source.Cocktails.Add(NewCocktail);
|
||||
return NewCocktail.GetViewModel;
|
||||
}
|
||||
|
||||
public CocktailViewModel? Update(CocktailBindingModel Model)
|
||||
{
|
||||
foreach (var Cocktail in _source.Cocktails)
|
||||
{
|
||||
if (Cocktail.Id == Model.Id)
|
||||
{
|
||||
Cocktail.Update(Model);
|
||||
return Cocktail.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CocktailViewModel? Delete(CocktailBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Cocktails.Count; ++i)
|
||||
{
|
||||
if (_source.Cocktails[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Cocktails[i];
|
||||
_source.Cocktails.RemoveAt(i);
|
||||
|
||||
return Element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarListImplement.Models;
|
||||
|
||||
|
||||
namespace BarListImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ComponentStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<ComponentViewModel>();
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
Result.Add(Component.GetViewModel);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel Model)
|
||||
{
|
||||
var Result = new List<ComponentViewModel>();
|
||||
|
||||
if (string.IsNullOrEmpty(Model.ComponentName))
|
||||
return Result;
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Component.ComponentName.Contains(Model.ComponentName))
|
||||
{
|
||||
Result.Add(Component.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ComponentName) && !Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(Model.ComponentName)
|
||||
&& Component.ComponentName == Model.ComponentName)
|
||||
|| (Model.Id.HasValue && Component.Id == Model.Id))
|
||||
{
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Model.Id <= Component.Id)
|
||||
{
|
||||
Model.Id = Component.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewComponent = Component.Create(Model);
|
||||
|
||||
if (NewComponent == null)
|
||||
return null;
|
||||
|
||||
_source.Components.Add(NewComponent);
|
||||
return NewComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel Model)
|
||||
{
|
||||
foreach (var Component in _source.Components)
|
||||
{
|
||||
if (Component.Id == Model.Id)
|
||||
{
|
||||
Component.Update(Model);
|
||||
return Component.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Components.Count; ++i)
|
||||
{
|
||||
if (_source.Components[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Components[i];
|
||||
_source.Components.RemoveAt(i);
|
||||
|
||||
return Element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
126
Bar/BarListImplement/BarListImplement/Implements/OrderStorage.cs
Normal file
126
Bar/BarListImplement/BarListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.SearchModels;
|
||||
using BarContracts.StoragesContracts;
|
||||
using BarContracts.ViewModels;
|
||||
using BarListImplement.Models;
|
||||
|
||||
namespace BarListImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
var Result = new List<OrderViewModel>();
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
Result.Add(JoinCocktailName(Order.GetViewModel));
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
||||
{
|
||||
var Result = new List<OrderViewModel>();
|
||||
|
||||
if (!Model.Id.HasValue)
|
||||
return Result;
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
Result.Add(JoinCocktailName(Order.GetViewModel));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
||||
{
|
||||
if (!Model.Id.HasValue)
|
||||
return null;
|
||||
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
return JoinCocktailName(Order.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
||||
{
|
||||
Model.Id = 1;
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Model.Id <= Order.Id)
|
||||
{
|
||||
Model.Id = Order.Id + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var NewOrder = Order.Create(Model);
|
||||
|
||||
if (NewOrder == null)
|
||||
return null;
|
||||
|
||||
_source.Orders.Add(NewOrder);
|
||||
return JoinCocktailName(NewOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
{
|
||||
foreach (var Order in _source.Orders)
|
||||
{
|
||||
if (Order.Id == Model.Id)
|
||||
{
|
||||
Order.Update(Model);
|
||||
return JoinCocktailName(Order.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||
{
|
||||
if (_source.Orders[i].Id == Model.Id)
|
||||
{
|
||||
var Element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
|
||||
return JoinCocktailName(Element.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private OrderViewModel JoinCocktailName(OrderViewModel Model)
|
||||
{
|
||||
var SelectedCocktail = _source.Cocktails.Find(reinforced => reinforced.Id == Model.CocktailId);
|
||||
|
||||
if (SelectedCocktail != null)
|
||||
{
|
||||
Model.CocktailName = SelectedCocktail.CocktailName;
|
||||
}
|
||||
return Model;
|
||||
}
|
||||
}
|
||||
}
|
53
Bar/BarListImplement/BarListImplement/Models/Cocktail.cs
Normal file
53
Bar/BarListImplement/BarListImplement/Models/Cocktail.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarListImplement.Models
|
||||
{
|
||||
public class Cocktail : ICocktailModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string CocktailName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> CocktailComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
|
||||
public static Cocktail? Create(CocktailBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Cocktail()
|
||||
{
|
||||
Id = Model.Id,
|
||||
CocktailName = Model.CocktailName,
|
||||
Price = Model.Price,
|
||||
CocktailComponents = Model.CocktailComponents
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CocktailBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
CocktailName = Model.CocktailName;
|
||||
Price = Model.Price;
|
||||
CocktailComponents = Model.CocktailComponents;
|
||||
}
|
||||
|
||||
public CocktailViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CocktailName = CocktailName,
|
||||
Price = Price,
|
||||
CocktailComponents = CocktailComponents
|
||||
};
|
||||
}
|
||||
}
|
44
Bar/BarListImplement/BarListImplement/Models/Component.cs
Normal file
44
Bar/BarListImplement/BarListImplement/Models/Component.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarListImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public static Component? Create(ComponentBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Component()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ComponentName = Model.ComponentName,
|
||||
Cost = Model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ComponentBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ComponentName = Model.ComponentName;
|
||||
Cost = Model.Cost;
|
||||
}
|
||||
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
66
Bar/BarListImplement/BarListImplement/Models/Order.cs
Normal file
66
Bar/BarListImplement/BarListImplement/Models/Order.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using BarContracts.BindingModels;
|
||||
using BarContracts.ViewModels;
|
||||
using BarDataModels.Enums;
|
||||
using BarDataModels.Models;
|
||||
|
||||
namespace BarListImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int CocktailId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Undefined;
|
||||
|
||||
public DateTime DateCreate { get; private set; }
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? Model)
|
||||
{
|
||||
if (Model is null)
|
||||
return null;
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = Model.Id,
|
||||
CocktailId = Model.CocktailId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
DateCreate = Model.DateCreate,
|
||||
DateImplement = Model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return;
|
||||
|
||||
CocktailId = Model.CocktailId;
|
||||
Count = Model.Count;
|
||||
Sum = Model.Sum;
|
||||
Status = Model.Status;
|
||||
DateCreate = Model.DateCreate;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CocktailId = CocktailId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user