From 6b93115ff38f470ca4a7a40ad5bcd401ce516dd3 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 31 Jan 2023 15:23:18 +0400 Subject: [PATCH 01/13] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=9B=D0=A01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar.sln | 26 +- SushiBar/SushiBar/Form1.Designer.cs | 39 --- SushiBar/SushiBar/Form1.cs | 10 - SushiBar/SushiBar/Form1.resx | 120 --------- SushiBar/SushiBar/FormCreateOrder.Designer.cs | 149 +++++++++++ SushiBar/SushiBar/FormCreateOrder.cs | 117 +++++++++ SushiBar/SushiBar/FormCreateOrder.resx | 60 +++++ SushiBar/SushiBar/FormIngredient.Designer.cs | 123 +++++++++ SushiBar/SushiBar/FormIngredient.cs | 87 +++++++ SushiBar/SushiBar/FormIngredient.resx | 60 +++++ SushiBar/SushiBar/FormIngredients.Designer.cs | 122 +++++++++ SushiBar/SushiBar/FormIngredients.cs | 100 +++++++ SushiBar/SushiBar/FormIngredients.resx | 60 +++++ SushiBar/SushiBar/FormListSushi.Designer.cs | 122 +++++++++ SushiBar/SushiBar/FormListSushi.cs | 105 ++++++++ SushiBar/SushiBar/FormListSushi.resx | 60 +++++ SushiBar/SushiBar/FormMain.Designer.cs | 182 +++++++++++++ SushiBar/SushiBar/FormMain.cs | 166 ++++++++++++ SushiBar/SushiBar/FormMain.resx | 63 +++++ SushiBar/SushiBar/FormSushi.Designer.cs | 246 ++++++++++++++++++ SushiBar/SushiBar/FormSushi.cs | 207 +++++++++++++++ SushiBar/SushiBar/FormSushi.resx | 69 +++++ .../SushiBar/FormSushiIngredients.Designer.cs | 123 +++++++++ SushiBar/SushiBar/FormSushiIngredients.cs | 79 ++++++ SushiBar/SushiBar/FormSushiIngredients.resx | 60 +++++ SushiBar/SushiBar/Program.cs | 43 ++- SushiBar/SushiBar/SushiBar.csproj | 11 - SushiBar/SushiBar/SushiBarView.csproj | 23 ++ .../BusinessLogics/IngredientLogic.cs | 113 ++++++++ .../BusinessLogics/OrderLogic.cs | 112 ++++++++ .../BusinessLogics/SushiLogic.cs | 112 ++++++++ .../SushiBarBusinessLogic.csproj | 19 ++ .../BindingModels/IngredientBindingModel.cs | 12 + .../BindingModels/OrderBindingModel.cs | 17 ++ .../BindingModels/SushiBindingModel.cs | 17 ++ .../IIngredientLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../BusinessLogicsContracts/ISushiLogic.cs | 15 ++ .../SearchModels/IngredientSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 8 + .../SearchModels/SushiSearchModel.cs | 8 + .../StoragesContracts/IIngredientStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../StoragesContracts/ISushiStorage.cs | 16 ++ .../SushiBarContracts.csproj | 19 ++ .../ViewModels/IngredientViewModel.cs | 14 + .../ViewModels/OrderViewModel.cs | 25 ++ .../ViewModels/SushiViewModel.cs | 19 ++ .../SushiBarDataModels/Enums/OrderStatus.cs | 11 + SushiBar/SushiBarDataModels/IId.cs | 7 + .../Models/IIngredientModel.cs | 8 + .../SushiBarDataModels/Models/IOrderModel.cs | 15 ++ .../SushiBarDataModels/Models/ISushiModel.cs | 9 + .../SushiBarDataModels.csproj | 15 ++ .../DataListSingleton.cs | 26 ++ .../Implements/IngredientStorage.cs | 103 ++++++++ .../Implements/OrderStorage.cs | 100 +++++++ .../Implements/SushiStorage.cs | 103 ++++++++ .../Models/Ingredient.cs | 41 +++ .../SushiBarListImplement/Models/Order.cs | 63 +++++ .../SushiBarListImplement/Models/Sushi.cs | 49 ++++ .../SushiBarListImplement.csproj | 20 ++ SushiBar/SushiBarView/SushiBarView.csproj | 9 + 63 files changed, 3625 insertions(+), 183 deletions(-) delete mode 100644 SushiBar/SushiBar/Form1.Designer.cs delete mode 100644 SushiBar/SushiBar/Form1.cs delete mode 100644 SushiBar/SushiBar/Form1.resx create mode 100644 SushiBar/SushiBar/FormCreateOrder.Designer.cs create mode 100644 SushiBar/SushiBar/FormCreateOrder.cs create mode 100644 SushiBar/SushiBar/FormCreateOrder.resx create mode 100644 SushiBar/SushiBar/FormIngredient.Designer.cs create mode 100644 SushiBar/SushiBar/FormIngredient.cs create mode 100644 SushiBar/SushiBar/FormIngredient.resx create mode 100644 SushiBar/SushiBar/FormIngredients.Designer.cs create mode 100644 SushiBar/SushiBar/FormIngredients.cs create mode 100644 SushiBar/SushiBar/FormIngredients.resx create mode 100644 SushiBar/SushiBar/FormListSushi.Designer.cs create mode 100644 SushiBar/SushiBar/FormListSushi.cs create mode 100644 SushiBar/SushiBar/FormListSushi.resx create mode 100644 SushiBar/SushiBar/FormMain.Designer.cs create mode 100644 SushiBar/SushiBar/FormMain.cs create mode 100644 SushiBar/SushiBar/FormMain.resx create mode 100644 SushiBar/SushiBar/FormSushi.Designer.cs create mode 100644 SushiBar/SushiBar/FormSushi.cs create mode 100644 SushiBar/SushiBar/FormSushi.resx create mode 100644 SushiBar/SushiBar/FormSushiIngredients.Designer.cs create mode 100644 SushiBar/SushiBar/FormSushiIngredients.cs create mode 100644 SushiBar/SushiBar/FormSushiIngredients.resx delete mode 100644 SushiBar/SushiBar/SushiBar.csproj create mode 100644 SushiBar/SushiBar/SushiBarView.csproj create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs create mode 100644 SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj create mode 100644 SushiBar/SushiBarContracts/BindingModels/IngredientBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IIngredientLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/IngredientSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IIngredientStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs create mode 100644 SushiBar/SushiBarContracts/SushiBarContracts.csproj create mode 100644 SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/Enums/OrderStatus.cs create mode 100644 SushiBar/SushiBarDataModels/IId.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IIngredientModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/IOrderModel.cs create mode 100644 SushiBar/SushiBarDataModels/Models/ISushiModel.cs create mode 100644 SushiBar/SushiBarDataModels/SushiBarDataModels.csproj create mode 100644 SushiBar/SushiBarListImplement/DataListSingleton.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/OrderStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/SushiStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Ingredient.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Order.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Sushi.cs create mode 100644 SushiBar/SushiBarListImplement/SushiBarListImplement.csproj create mode 100644 SushiBar/SushiBarView/SushiBarView.csproj diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index 1a58c56..d25d4a8 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBar", "SushiBar\SushiBar.csproj", "{021299FA-4932-4367-A9A7-378EB340D8BC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{021299FA-4932-4367-A9A7-378EB340D8BC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1B31E006-79D1-4376-AEEB-55AF60806AB1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{2755BF17-8728-4D7E-A4EE-BC8810C508F6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarListImplement", "SushiBarListImplement\SushiBarListImplement.csproj", "{81A91405-3721-40EF-A47C-CEBD92C0A4D0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {021299FA-4932-4367-A9A7-378EB340D8BC}.Debug|Any CPU.Build.0 = Debug|Any CPU {021299FA-4932-4367-A9A7-378EB340D8BC}.Release|Any CPU.ActiveCfg = Release|Any CPU {021299FA-4932-4367-A9A7-378EB340D8BC}.Release|Any CPU.Build.0 = Release|Any CPU + {8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DD9F541-A4FA-4C0B-8E7D-8525C0D77E1C}.Release|Any CPU.Build.0 = Release|Any CPU + {1B31E006-79D1-4376-AEEB-55AF60806AB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B31E006-79D1-4376-AEEB-55AF60806AB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B31E006-79D1-4376-AEEB-55AF60806AB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B31E006-79D1-4376-AEEB-55AF60806AB1}.Release|Any CPU.Build.0 = Release|Any CPU + {2755BF17-8728-4D7E-A4EE-BC8810C508F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2755BF17-8728-4D7E-A4EE-BC8810C508F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2755BF17-8728-4D7E-A4EE-BC8810C508F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2755BF17-8728-4D7E-A4EE-BC8810C508F6}.Release|Any CPU.Build.0 = Release|Any CPU + {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81A91405-3721-40EF-A47C-CEBD92C0A4D0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SushiBar/SushiBar/Form1.Designer.cs b/SushiBar/SushiBar/Form1.Designer.cs deleted file mode 100644 index b5f899b..0000000 --- a/SushiBar/SushiBar/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SushiBar -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/SushiBar/SushiBar/Form1.cs b/SushiBar/SushiBar/Form1.cs deleted file mode 100644 index 0eaa471..0000000 --- a/SushiBar/SushiBar/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SushiBar -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/SushiBar/SushiBar/Form1.resx b/SushiBar/SushiBar/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/SushiBar/SushiBar/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SushiBar/SushiBar/FormCreateOrder.Designer.cs b/SushiBar/SushiBar/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..8693725 --- /dev/null +++ b/SushiBar/SushiBar/FormCreateOrder.Designer.cs @@ -0,0 +1,149 @@ +namespace SushiBarView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(241, 90); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(153, 90); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(93, 63); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(230, 23); + this.textBoxSum.TabIndex = 13; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(93, 36); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 12; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(93, 9); + this.comboBoxSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(230, 23); + this.comboBoxSushi.TabIndex = 11; + this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSushi_SelectedIndexChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 63); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 10; + this.labelSum.Text = "Сумма:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 36); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 9; + this.labelCount.Text = "Количество:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(42, 15); + this.labelName.TabIndex = 8; + this.labelName.Text = "Суши:"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(343, 128); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxSum; + private TextBox textBoxCount; + private ComboBox comboBoxSushi; + private Label labelSum; + private Label labelCount; + private Label labelName; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs new file mode 100644 index 0000000..613f1b8 --- /dev/null +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + +namespace SushiBarView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicS; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ISushiLogic logicS, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка суши для заказа"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = list; + comboBoxSushi.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSushi.SelectedValue); + var product = _logicS.ReadElement(new SushiSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле 'Количество'", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + SushiName = comboBoxSushi.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBar/FormCreateOrder.resx b/SushiBar/SushiBar/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormIngredient.Designer.cs b/SushiBar/SushiBar/FormIngredient.Designer.cs new file mode 100644 index 0000000..4ae8e9f --- /dev/null +++ b/SushiBar/SushiBar/FormIngredient.Designer.cs @@ -0,0 +1,123 @@ +namespace SushiBarView +{ + partial class FormIngredient + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelBlankName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(200, 73); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(112, 73); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(111, 38); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(183, 23); + this.textBoxCost.TabIndex = 9; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(111, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(329, 23); + this.textBoxName.TabIndex = 8; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 37); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(38, 15); + this.labelPrice.TabIndex = 7; + this.labelPrice.Text = "Цена:"; + // + // labelBlankName + // + this.labelBlankName.AutoSize = true; + this.labelBlankName.Location = new System.Drawing.Point(12, 14); + this.labelBlankName.Name = "labelBlankName"; + this.labelBlankName.Size = new System.Drawing.Size(62, 15); + this.labelBlankName.TabIndex = 6; + this.labelBlankName.Text = "Название:"; + // + // FormIngredient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelBlankName); + this.Name = "FormIngredient"; + this.Text = "Ингредиент"; + this.Load += new System.EventHandler(this.FormIngredient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCost; + private TextBox textBoxName; + private Label labelPrice; + private Label labelBlankName; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormIngredient.cs b/SushiBar/SushiBar/FormIngredient.cs new file mode 100644 index 0000000..775ea56 --- /dev/null +++ b/SushiBar/SushiBar/FormIngredient.cs @@ -0,0 +1,87 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormIngredient : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormIngredient(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIngredient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение ингредиента"); + var view = _logic.ReadElement(new IngredientSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.IngredientName; + textBoxCost.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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение ингредиента"); + try + { + var model = new IngredientBindingModel + { + Id = _id ?? 0, + IngredientName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.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(); + } + + } +} diff --git a/SushiBar/SushiBar/FormIngredient.resx b/SushiBar/SushiBar/FormIngredient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormIngredient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormIngredients.Designer.cs b/SushiBar/SushiBar/FormIngredients.Designer.cs new file mode 100644 index 0000000..ae7cd9c --- /dev/null +++ b/SushiBar/SushiBar/FormIngredients.Designer.cs @@ -0,0 +1,122 @@ +namespace SushiBarView +{ + partial class FormIngredients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 186); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 9; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 160); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 8; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 134); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 7; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 108); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 348); + this.dataGridView.TabIndex = 5; + // + // FormIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(571, 348); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormIngredients"; + this.Text = "Ингредиенты"; + this.Load += new System.EventHandler(this.FormIngredients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs new file mode 100644 index 0000000..73d7cfa --- /dev/null +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormIngredients : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + public FormIngredients(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormIngredients_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["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка ингредиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ингредиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + if (service is FormIngredient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredient)); + if (service is FormIngredient form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление ингредиента"); + try + { + if (!_logic.Delete(new IngredientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/FormIngredients.resx b/SushiBar/SushiBar/FormIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormIngredients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormListSushi.Designer.cs b/SushiBar/SushiBar/FormListSushi.Designer.cs new file mode 100644 index 0000000..6ab6fd2 --- /dev/null +++ b/SushiBar/SushiBar/FormListSushi.Designer.cs @@ -0,0 +1,122 @@ +namespace SushiBarView +{ + partial class FormListSushi + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 345); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 183); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 157); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 131); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 105); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormListSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(570, 345); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormListSushi"; + this.Text = "Список суши"; + this.Load += new System.EventHandler(this.FormDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs new file mode 100644 index 0000000..333b51c --- /dev/null +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBarView +{ + public partial class FormListSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + public FormListSushi(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDocuments_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["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["SushiIngredients"].Visible = false; + } + _logger.LogInformation("Загрузка суши"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление суши"); + try + { + if (!_logic.Delete(new SushiBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/FormListSushi.resx b/SushiBar/SushiBar/FormListSushi.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormListSushi.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs new file mode 100644 index 0000000..ba3e4ae --- /dev/null +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -0,0 +1,182 @@ +namespace SushiBarView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonSetToFinish = new System.Windows.Forms.Button(); + this.buttonSetToDone = new System.Windows.Forms.Button(); + this.buttonSetToWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(975, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ингредиентыToolStripMenuItem, + this.сушиToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // ингредиентыToolStripMenuItem + // + this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; + this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); + // + // сушиToolStripMenuItem + // + this.сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; + this.сушиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.сушиToolStripMenuItem.Text = "Суши"; + this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(793, 315); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(170, 58); + this.buttonUpdate.TabIndex = 12; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonSetToFinish + // + this.buttonSetToFinish.Location = new System.Drawing.Point(793, 253); + this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToFinish.Name = "buttonSetToFinish"; + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); + this.buttonSetToFinish.TabIndex = 11; + this.buttonSetToFinish.Text = "Заказ выдан"; + this.buttonSetToFinish.UseVisualStyleBackColor = true; + this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonSetToDone + // + this.buttonSetToDone.Location = new System.Drawing.Point(793, 191); + this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToDone.Name = "buttonSetToDone"; + this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); + this.buttonSetToDone.TabIndex = 10; + this.buttonSetToDone.Text = "Заказ готов"; + this.buttonSetToDone.UseVisualStyleBackColor = true; + this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonSetToWork + // + this.buttonSetToWork.Location = new System.Drawing.Point(793, 129); + this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToWork.Name = "buttonSetToWork"; + this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); + this.buttonSetToWork.TabIndex = 9; + this.buttonSetToWork.Text = "Отдать на выполнение"; + this.buttonSetToWork.UseVisualStyleBackColor = true; + this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(793, 67); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); + this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 24); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(787, 426); + this.dataGridView.TabIndex = 7; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(975, 450); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonSetToFinish); + this.Controls.Add(this.buttonSetToDone); + this.Controls.Add(this.buttonSetToWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Суши-бар"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ингредиентыToolStripMenuItem; + private ToolStripMenuItem сушиToolStripMenuItem; + private Button buttonUpdate; + private Button buttonSetToFinish; + private Button buttonSetToDone; + private Button buttonSetToWork; + private Button buttonCreateOrder; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs new file mode 100644 index 0000000..fb523ea --- /dev/null +++ b/SushiBar/SushiBar/FormMain.cs @@ -0,0 +1,166 @@ +using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarDataModels.Enums; + +namespace SushiBarView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger 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["SushiId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + if (service is FormIngredients form) + { + form.ShowDialog(); + } + } + private void SushiToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.resx b/SushiBar/SushiBar/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/SushiBar/SushiBar/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.Designer.cs b/SushiBar/SushiBar/FormSushi.Designer.cs new file mode 100644 index 0000000..fff99db --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.Designer.cs @@ -0,0 +1,246 @@ +namespace SushiBarView +{ + partial class FormSushi + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.groupBoxIngredients = new System.Windows.Forms.GroupBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnIngredientName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxIngredients.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(90, 36); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(138, 23); + this.textBoxPrice.TabIndex = 7; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(90, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 23); + this.textBoxName.TabIndex = 6; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 41); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(70, 15); + this.labelPrice.TabIndex = 5; + this.labelPrice.Text = "Стоимость:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 14); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 4; + this.labelName.Text = "Название:"; + // + // groupBoxIngredients + // + this.groupBoxIngredients.Controls.Add(this.buttonCancel); + this.groupBoxIngredients.Controls.Add(this.buttonSave); + this.groupBoxIngredients.Controls.Add(this.buttonUpdate); + this.groupBoxIngredients.Controls.Add(this.buttonDelete); + this.groupBoxIngredients.Controls.Add(this.buttonEdit); + this.groupBoxIngredients.Controls.Add(this.buttonAdd); + this.groupBoxIngredients.Controls.Add(this.dataGridView); + this.groupBoxIngredients.Dock = System.Windows.Forms.DockStyle.Bottom; + this.groupBoxIngredients.Location = new System.Drawing.Point(0, 70); + this.groupBoxIngredients.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Name = "groupBoxIngredients"; + this.groupBoxIngredients.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Size = new System.Drawing.Size(592, 206); + this.groupBoxIngredients.TabIndex = 8; + this.groupBoxIngredients.TabStop = false; + this.groupBoxIngredients.Text = "Компоненты"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(504, 176); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(79, 22); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(504, 150); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 22); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(504, 98); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(79, 22); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(504, 72); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(79, 22); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(504, 46); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(79, 22); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(504, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(79, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnIngredientName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(493, 182); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // ColumnIngredientName + // + this.ColumnIngredientName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.ColumnIngredientName.HeaderText = "Ингредиент"; + this.ColumnIngredientName.MinimumWidth = 6; + this.ColumnIngredientName.Name = "ColumnIngredientName"; + this.ColumnIngredientName.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.ColumnIngredientName.Width = 312; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // FormSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(592, 276); + this.Controls.Add(this.groupBoxIngredients); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormSushi"; + this.Text = "Суши"; + this.Load += new System.EventHandler(this.FormSushi_Load); + this.groupBoxIngredients.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label labelPrice; + private Label labelName; + private GroupBox groupBoxIngredients; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnIngredientName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs new file mode 100644 index 0000000..9d98bd1 --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.cs @@ -0,0 +1,207 @@ +using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarDataModels.Models; + +namespace SushiBarView +{ + public partial class FormSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + private int? _id; + private Dictionary _sushiIngredients; + public int Id { set { _id = value; } } + public FormSushi(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _sushiIngredients = new Dictionary(); + } + private void FormSushi_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка суши"); + try + { + var view = _logic.ReadElement(new SushiSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SushiName; + textBoxPrice.Text = view.Price.ToString(); + _sushiIngredients = view.SushiIngredients ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиент суши"); + try + { + if (_sushiIngredients != null) + { + dataGridView.Rows.Clear(); + foreach (var sc in _sushiIngredients) + { + dataGridView.Rows.Add(new object[] { sc.Key, sc.Value.Item1.IngredientName, sc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ингредиент суши"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + if (service is FormSushiIngredients form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); + if (_sushiIngredients.ContainsKey(form.Id)) + { + _sushiIngredients[form.Id] = (form.IngredientModel, + form.Count); + } + else + { + _sushiIngredients.Add(form.Id, (form.IngredientModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); + if (service is FormSushiIngredients form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _sushiIngredients[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента: { IngredientName} - { Count} ", form.IngredientModel.IngredientName, form.Count); + _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление ингредиента: { IngredientName} - { Count} ", + dataGridView.SelectedRows[0].Cells[1].Value); _sushiIngredients?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_sushiIngredients == null || _sushiIngredients.Count == 0) + { + MessageBox.Show("Заполните ингредиенты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение суши"); + try + { + var model = new SushiBindingModel + { + Id = _id ?? 0, + SushiName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SushiIngredients = _sushiIngredients + }; + 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(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _sushiIngredients) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/SushiBar/SushiBar/FormSushi.resx b/SushiBar/SushiBar/FormSushi.resx new file mode 100644 index 0000000..bb082f6 --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiIngredients.Designer.cs b/SushiBar/SushiBar/FormSushiIngredients.Designer.cs new file mode 100644 index 0000000..3fb6536 --- /dev/null +++ b/SushiBar/SushiBar/FormSushiIngredients.Designer.cs @@ -0,0 +1,123 @@ +namespace SushiBarView +{ + partial class FormSushiIngredients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxIngredient = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelIngredient = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(319, 80); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(80, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(233, 80); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(80, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(116, 43); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(283, 23); + this.textBoxCount.TabIndex = 9; + // + // comboBoxIngredient + // + this.comboBoxIngredient.FormattingEnabled = true; + this.comboBoxIngredient.Location = new System.Drawing.Point(116, 11); + this.comboBoxIngredient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxIngredient.Name = "comboBoxIngredient"; + this.comboBoxIngredient.Size = new System.Drawing.Size(282, 23); + this.comboBoxIngredient.TabIndex = 8; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 46); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 7; + this.labelCount.Text = "Количество:"; + // + // labelIngredient + // + this.labelIngredient.AutoSize = true; + this.labelIngredient.Location = new System.Drawing.Point(10, 14); + this.labelIngredient.Name = "labelIngredient"; + this.labelIngredient.Size = new System.Drawing.Size(75, 15); + this.labelIngredient.TabIndex = 6; + this.labelIngredient.Text = "Ингредиент:"; + // + // FormSushiIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(410, 115); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxIngredient); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelIngredient); + this.Name = "FormSushiIngredients"; + this.Text = "Ингредиент суши"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private ComboBox comboBoxIngredient; + private Label labelCount; + private Label labelIngredient; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiIngredients.cs b/SushiBar/SushiBar/FormSushiIngredients.cs new file mode 100644 index 0000000..8923f11 --- /dev/null +++ b/SushiBar/SushiBar/FormSushiIngredients.cs @@ -0,0 +1,79 @@ +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarView +{ + public partial class FormSushiIngredients : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxIngredient.SelectedValue); + } + set + { + comboBoxIngredient.SelectedValue = value; + } + } + public IIngredientModel? IngredientModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormSushiIngredients(IIngredientLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxIngredient.DisplayMember = "IngredientName"; + comboBoxIngredient.ValueMember = "Id"; + comboBoxIngredient.DataSource = _list; + comboBoxIngredient.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле 'Количество'", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxIngredient.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(); + } + } +} diff --git a/SushiBar/SushiBar/FormSushiIngredients.resx b/SushiBar/SushiBar/FormSushiIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormSushiIngredients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 402417b..07ff1b6 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -1,7 +1,18 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SushiBarBusinessLogic.BusinessLogics; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushiBarListImplement.Implements; +using SushiBarView; + namespace SushiBar { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,35 @@ namespace SushiBar // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } -} \ No newline at end of file +} diff --git a/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj deleted file mode 100644 index b57c89e..0000000 --- a/SushiBar/SushiBar/SushiBar.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj new file mode 100644 index 0000000..dceb0d9 --- /dev/null +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -0,0 +1,23 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs new file mode 100644 index 0000000..d7dce4c --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class IngredientLogic : IIngredientLogic + { + private readonly ILogger _logger; + private readonly IIngredientStorage _componentStorage; + public IngredientLogic(ILogger logger, IIngredientStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(IngredientSearchModel? model) + { + _logger.LogInformation("ReadList. IngredientName: {IngredientName}. Id: {Id}", + model?.IngredientName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public IngredientViewModel? ReadElement(IngredientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IngredientName: {IngredientName}. Id: {Id}", + model.IngredientName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IngredientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(IngredientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IngredientName)) + { + throw new ArgumentNullException("Нет названия ингредиента", + nameof(model.IngredientName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", + nameof(model.Cost)); + } + _logger.LogInformation("Ingredient. IngredientName: {IngredientName}. Cost: {Cost}. Id: {Id}", + model.IngredientName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new IngredientSearchModel + { + IngredientName = model.IngredientName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..13b21b6 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SushiId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId)); + } + 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. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId); + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs new file mode 100644 index 0000000..e40d8f5 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class SushiLogic : ISushiLogic + { + private readonly ILogger _logger; + private readonly ISushiStorage _sushiStorage; + public SushiLogic(ILogger logger, ISushiStorage sushiStorage) + { + _logger = logger; + _sushiStorage = sushiStorage; + } + public List? ReadList(SushiSearchModel? model) + { + _logger.LogInformation("ReadList. SushiName: {SushiName}. Id: {Id}", + model?.SushiName, model?.Id); + var list = model == null ? _sushiStorage.GetFullList() : + _sushiStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public SushiViewModel? ReadElement(SushiSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. SushiName: {SushiName}. Id: {Id}", + model.SushiName, model.Id); + var element = _sushiStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(SushiBindingModel model) + { + CheckModel(model); + if (_sushiStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(SushiBindingModel model) + { + CheckModel(model); + if (_sushiStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(SushiBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_sushiStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(SushiBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SushiName)) + { + throw new ArgumentNullException("Нет названия суши", nameof(model.SushiName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена суши должна быть больше 0", + nameof(model.Price)); + } + _logger.LogInformation("Sushi. SushiName: {SushiName}. Cost: {Cost}. Id: {Id}", + model.SushiName, model.Price, model.Id); + var element = _sushiStorage.GetElement(new SushiSearchModel + { + SushiName = model.SushiName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Суши с таким названием уже есть"); + } + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj new file mode 100644 index 0000000..8d082e6 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/SushiBar/SushiBarContracts/BindingModels/IngredientBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/IngredientBindingModel.cs new file mode 100644 index 0000000..5b9d39b --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/IngredientBindingModel.cs @@ -0,0 +1,12 @@ +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class IngredientBindingModel : IIngredientModel + { + public int Id { get; set; } + public string IngredientName { get; set; } = string.Empty; + public double Cost { get; set; } + } + +} diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..65c3d70 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int SushiId { get; set; } + public string SushiName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + public int Id { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs new file mode 100644 index 0000000..a89a458 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs @@ -0,0 +1,17 @@ +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SushiBindingModel : ISushiModel + { + public int Id { get; set; } + public string SushiName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary SushiIngredients + { + get; + set; + } = new(); + } + +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IIngredientLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IIngredientLogic.cs new file mode 100644 index 0000000..2966ae0 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IIngredientLogic.cs @@ -0,0 +1,15 @@ +using SushiBarContracts.ViewModels; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IIngredientLogic + { + List? ReadList(IngredientSearchModel? model); + IngredientViewModel? ReadElement(IngredientSearchModel model); + bool Create(IngredientBindingModel model); + bool Update(IngredientBindingModel model); + bool Delete(IngredientBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..be0cb58 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs new file mode 100644 index 0000000..e0d7a79 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs @@ -0,0 +1,15 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface ISushiLogic + { + List? ReadList(SushiSearchModel? model); + SushiViewModel? ReadElement(SushiSearchModel model); + bool Create(SushiBindingModel model); + bool Update(SushiBindingModel model); + bool Delete(SushiBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/IngredientSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/IngredientSearchModel.cs new file mode 100644 index 0000000..4b79bbb --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/IngredientSearchModel.cs @@ -0,0 +1,9 @@ +namespace SushiBarContracts.SearchModels +{ + public class IngredientSearchModel + { + public int? Id { get; set; } + public string? IngredientName { get; set; } + } + +} diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..63214df --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } + +} diff --git a/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs new file mode 100644 index 0000000..55e424e --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.SearchModels +{ + public class SushiSearchModel + { + public int? Id { get; set; } + public string? SushiName { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IIngredientStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IIngredientStorage.cs new file mode 100644 index 0000000..3a9931a --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IIngredientStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IIngredientStorage + { + List GetFullList(); + List GetFilteredList(IngredientSearchModel model); + IngredientViewModel? GetElement(IngredientSearchModel model); + IngredientViewModel? Insert(IngredientBindingModel model); + IngredientViewModel? Update(IngredientBindingModel model); + IngredientViewModel? Delete(IngredientBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..f337dbf --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs new file mode 100644 index 0000000..ff49391 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface ISushiStorage + { + List GetFullList(); + List GetFilteredList(SushiSearchModel model); + SushiViewModel? GetElement(SushiSearchModel model); + SushiViewModel? Insert(SushiBindingModel model); + SushiViewModel? Update(SushiBindingModel model); + SushiViewModel? Delete(SushiBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/SushiBarContracts.csproj b/SushiBar/SushiBarContracts/SushiBarContracts.csproj new file mode 100644 index 0000000..49dc40e --- /dev/null +++ b/SushiBar/SushiBarContracts/SushiBarContracts.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs new file mode 100644 index 0000000..eada9d4 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/IngredientViewModel.cs @@ -0,0 +1,14 @@ +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class IngredientViewModel : IIngredientModel + { + public int Id { get; set; } + [DisplayName("Название ингредиента")] + public string IngredientName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..172322a --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int SushiId { get; set; } + [DisplayName("Суши")] + public string SushiName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs new file mode 100644 index 0000000..12c51a0 --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -0,0 +1,19 @@ +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class SushiViewModel : ISushiModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string SushiName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary SushiIngredients + { + get; + set; + } = new(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..e7973ca --- /dev/null +++ b/SushiBar/SushiBarDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace SushiBarDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3, + } +} diff --git a/SushiBar/SushiBarDataModels/IId.cs b/SushiBar/SushiBarDataModels/IId.cs new file mode 100644 index 0000000..91a1366 --- /dev/null +++ b/SushiBar/SushiBarDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace SushiBarDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/Models/IIngredientModel.cs b/SushiBar/SushiBarDataModels/Models/IIngredientModel.cs new file mode 100644 index 0000000..1d1ef91 --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IIngredientModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarDataModels.Models +{ + public interface IIngredientModel : IId + { + string IngredientName { get; } + double Cost { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..cb918ea --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs @@ -0,0 +1,15 @@ +using SushiBarDataModels.Enums; + +namespace SushiBarDataModels.Models +{ + public interface IOrderModel : IId + { + int SushiId { get; } + string SushiName { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/Models/ISushiModel.cs b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs new file mode 100644 index 0000000..507e1da --- /dev/null +++ b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs @@ -0,0 +1,9 @@ +namespace SushiBarDataModels.Models +{ + public interface ISushiModel : IId + { + string SushiName { get; } + double Price { get; } + Dictionary SushiIngredients { get; } + } +} diff --git a/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj b/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj new file mode 100644 index 0000000..daf9ebc --- /dev/null +++ b/SushiBar/SushiBarDataModels/SushiBarDataModels.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs new file mode 100644 index 0000000..f344d8f --- /dev/null +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using SushiBarListImplement.Models; + +namespace SushiBarListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Ingredients { get; set; } + public List Orders { get; set; } + public List ListSushi { get; set; } + private DataListSingleton() + { + Ingredients = new List(); + Orders = new List(); + ListSushi = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs new file mode 100644 index 0000000..83b0d16 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -0,0 +1,103 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class IngredientStorage : IIngredientStorage + { + private readonly DataListSingleton _source; + public IngredientStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Ingredients) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(IngredientSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.IngredientName)) + { + return result; + } + foreach (var component in _source.Ingredients) + { + if (component.IngredientName.Contains(model.IngredientName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public IngredientViewModel? GetElement(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Ingredients) + { + if ((!string.IsNullOrEmpty(model.IngredientName) && + component.IngredientName == model.IngredientName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public IngredientViewModel? Insert(IngredientBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Ingredients) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newIngredient = Ingredient.Create(model); + if (newIngredient == null) + { + return null; + } + _source.Ingredients.Add(newIngredient); + return newIngredient.GetViewModel; + } + public IngredientViewModel? Update(IngredientBindingModel model) + { + foreach (var component in _source.Ingredients) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public IngredientViewModel? Delete(IngredientBindingModel model) + { + for (int i = 0; i < _source.Ingredients.Count; ++i) + { + if (_source.Ingredients[i].Id == model.Id) + { + var element = _source.Ingredients[i]; + _source.Ingredients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..9105ec6 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -0,0 +1,100 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return 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 newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return 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 element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs new file mode 100644 index 0000000..7674b86 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -0,0 +1,103 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class SushiStorage : ISushiStorage + { + private readonly DataListSingleton _source; + public SushiStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var sushi in _source.ListSushi) + { + result.Add(sushi.GetViewModel); + } + return result; + } + public List GetFilteredList(SushiSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SushiName)) + { + return result; + } + foreach (var sushi in _source.ListSushi) + { + if (sushi.SushiName.Contains(model.SushiName)) + { + result.Add(sushi.GetViewModel); + } + } + return result; + } + public SushiViewModel? GetElement(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) + { + return null; + } + foreach (var sushi in _source.ListSushi) + { + if ((!string.IsNullOrEmpty(model.SushiName) && + sushi.SushiName == model.SushiName) || + (model.Id.HasValue && sushi.Id == model.Id)) + { + return sushi.GetViewModel; + } + } + return null; + } + public SushiViewModel? Insert(SushiBindingModel model) + { + model.Id = 1; + foreach (var sushi in _source.ListSushi) + { + if (model.Id <= sushi.Id) + { + model.Id = sushi.Id + 1; + } + } + var newSushi = Sushi.Create(model); + if (newSushi == null) + { + return null; + } + _source.ListSushi.Add(newSushi); + return newSushi.GetViewModel; + } + public SushiViewModel? Update(SushiBindingModel model) + { + foreach (var sushi in _source.ListSushi) + { + if (sushi.Id == model.Id) + { + sushi.Update(model); + return sushi.GetViewModel; + } + } + return null; + } + public SushiViewModel? Delete(SushiBindingModel model) + { + for (int i = 0; i < _source.ListSushi.Count; ++i) + { + if (_source.ListSushi[i].Id == model.Id) + { + var element = _source.ListSushi[i]; + _source.ListSushi.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/Models/Ingredient.cs b/SushiBar/SushiBarListImplement/Models/Ingredient.cs new file mode 100644 index 0000000..2f61296 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Ingredient.cs @@ -0,0 +1,41 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public void Update(IngredientBindingModel? model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs new file mode 100644 index 0000000..6d2dbba --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -0,0 +1,63 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class Order : IOrderModel + { + public int SushiId { get; private set; } + public string SushiName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + SushiId = model.SushiId, + SushiName = model.SushiName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + SushiId = model.SushiId; + SushiName = model.SushiName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + public OrderViewModel GetViewModel => new() + { + SushiId = SushiId, + SushiName = SushiName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Sushi.cs b/SushiBar/SushiBarListImplement/Models/Sushi.cs new file mode 100644 index 0000000..3a589e8 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Sushi.cs @@ -0,0 +1,49 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.Models +{ + public class Sushi : ISushiModel + { + public int Id { get; private set; } + public string SushiName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary SushiIngredients + { + get; + private set; + } = new Dictionary(); + public static Sushi? Create(SushiBindingModel? model) + { + if (model == null) + { + return null; + } + return new Sushi() + { + Id = model.Id, + SushiName = model.SushiName, + Price = model.Price, + SushiIngredients = model.SushiIngredients + }; + } + public void Update(SushiBindingModel? model) + { + if (model == null) + { + return; + } + SushiName = model.SushiName; + Price = model.Price; + SushiIngredients = model.SushiIngredients; + } + public SushiViewModel GetViewModel => new() + { + Id = Id, + SushiName = SushiName, + Price = Price, + SushiIngredients = SushiIngredients + }; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj new file mode 100644 index 0000000..f2515de --- /dev/null +++ b/SushiBar/SushiBarListImplement/SushiBarListImplement.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SushiBar/SushiBarView/SushiBarView.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + -- 2.25.1 From 0c05166def7928564d9e112f9eccef9cd6dc65a2 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 31 Jan 2023 18:07:09 +0400 Subject: [PATCH 02/13] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormIngredient.Designer.cs | 4 ++-- SushiBar/SushiBar/FormIngredient.cs | 4 ++-- .../SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/SushiBar/SushiBar/FormIngredient.Designer.cs b/SushiBar/SushiBar/FormIngredient.Designer.cs index 4ae8e9f..038f5ca 100644 --- a/SushiBar/SushiBar/FormIngredient.Designer.cs +++ b/SushiBar/SushiBar/FormIngredient.Designer.cs @@ -45,7 +45,7 @@ this.buttonCancel.TabIndex = 11; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // buttonSave // @@ -56,7 +56,7 @@ this.buttonSave.TabIndex = 10; this.buttonSave.Text = "Сохранить"; this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // textBoxCost // diff --git a/SushiBar/SushiBar/FormIngredient.cs b/SushiBar/SushiBar/FormIngredient.cs index 775ea56..3349363 100644 --- a/SushiBar/SushiBar/FormIngredient.cs +++ b/SushiBar/SushiBar/FormIngredient.cs @@ -45,7 +45,7 @@ namespace SushiBarView } } - private void buttonSave_Click(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { @@ -77,7 +77,7 @@ namespace SushiBarView } } - private void buttonCancel_Click(object sender, EventArgs e) + private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs index d7dce4c..5b93cb8 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -90,8 +90,7 @@ namespace SushiBarBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.IngredientName)) { - throw new ArgumentNullException("Нет названия ингредиента", - nameof(model.IngredientName)); + throw new ArgumentNullException("Нет названия ингредиента", nameof(model.IngredientName)); } if (model.Cost <= 0) { -- 2.25.1 From 6306b2043035e1bbbfe57951fcef5cb3c702e805 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 1 Feb 2023 12:16:22 +0400 Subject: [PATCH 03/13] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 16 ++++++++-------- .../SushiBarDataModels/Models/IOrderModel.cs | 1 - .../Implements/IngredientStorage.cs | 3 +-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index ba3e4ae..cad392a 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -64,20 +64,20 @@ // ингредиентыToolStripMenuItem // this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; - this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); // // сушиToolStripMenuItem // this.сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - this.сушиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.сушиToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.сушиToolStripMenuItem.Text = "Суши"; this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(793, 315); + this.buttonUpdate.Location = new System.Drawing.Point(780, 314); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(170, 58); @@ -88,7 +88,7 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(793, 253); + this.buttonSetToFinish.Location = new System.Drawing.Point(780, 252); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); @@ -99,7 +99,7 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(793, 191); + this.buttonSetToDone.Location = new System.Drawing.Point(780, 190); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); @@ -110,7 +110,7 @@ // // buttonSetToWork // - this.buttonSetToWork.Location = new System.Drawing.Point(793, 129); + this.buttonSetToWork.Location = new System.Drawing.Point(780, 128); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); @@ -121,7 +121,7 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(793, 67); + this.buttonCreateOrder.Location = new System.Drawing.Point(780, 66); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); @@ -139,7 +139,7 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(787, 426); + this.dataGridView.Size = new System.Drawing.Size(755, 426); this.dataGridView.TabIndex = 7; // // FormMain diff --git a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs index cb918ea..3770e12 100644 --- a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs @@ -5,7 +5,6 @@ namespace SushiBarDataModels.Models public interface IOrderModel : IId { int SushiId { get; } - string SushiName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs index 83b0d16..15a0746 100644 --- a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -22,8 +22,7 @@ namespace SushiBarListImplement.Implements } return result; } - public List GetFilteredList(IngredientSearchModel - model) + public List GetFilteredList(IngredientSearchModel model) { var result = new List(); if (string.IsNullOrEmpty(model.IngredientName)) -- 2.25.1 From 4a72fab709c6d6425d4f1d74a5d41d9ebc61e655 Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 1 Feb 2023 14:58:05 +0400 Subject: [PATCH 04/13] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarView/SushiBarView.csproj | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 SushiBar/SushiBarView/SushiBarView.csproj diff --git a/SushiBar/SushiBarView/SushiBarView.csproj b/SushiBar/SushiBarView/SushiBarView.csproj deleted file mode 100644 index 132c02c..0000000 --- a/SushiBar/SushiBarView/SushiBarView.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - -- 2.25.1 From f550a6900bfd6e3e46f4cabed0724f66dbf50361 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 7 Feb 2023 12:55:45 +0400 Subject: [PATCH 05/13] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormCreateOrder.cs | 4 +- SushiBar/SushiBar/FormSushi.cs | 28 +++---- .../BusinessLogics/IngredientLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 74 +++++++++---------- .../Implements/IngredientStorage.cs | 33 ++++----- .../Implements/SushiStorage.cs | 3 +- .../SushiBarListImplement/Models/Order.cs | 2 +- 7 files changed, 67 insertions(+), 79 deletions(-) diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index 613f1b8..26d31f5 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -45,12 +45,12 @@ namespace SushiBarView try { int id = Convert.ToInt32(comboBoxSushi.SelectedValue); - var product = _logicS.ReadElement(new SushiSearchModel + var sushi = _logicS.ReadElement(new SushiSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString(); _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 9d98bd1..67496b1 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -50,7 +50,7 @@ namespace SushiBarView } private void LoadData() { - _logger.LogInformation("Загрузка ингредиент суши"); + _logger.LogInformation("Загрузка ингредиентов суши"); try { if (_sushiIngredients != null) @@ -65,7 +65,7 @@ namespace SushiBarView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ингредиент суши"); + _logger.LogError(ex, "Ошибка загрузки ингредиентов суши"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -83,13 +83,11 @@ namespace SushiBarView _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); if (_sushiIngredients.ContainsKey(form.Id)) { - _sushiIngredients[form.Id] = (form.IngredientModel, - form.Count); + _sushiIngredients[form.Id] = (form.IngredientModel, form.Count); } else { - _sushiIngredients.Add(form.Id, (form.IngredientModel, - form.Count)); + _sushiIngredients.Add(form.Id, (form.IngredientModel, form.Count)); } LoadData(); } @@ -102,8 +100,7 @@ namespace SushiBarView var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); if (service is FormSushiIngredients form) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; form.Count = _sushiIngredients[id].Item2; if (form.ShowDialog() == DialogResult.OK) @@ -123,8 +120,7 @@ namespace SushiBarView { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { @@ -133,8 +129,7 @@ namespace SushiBarView } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } @@ -148,20 +143,17 @@ namespace SushiBarView { if (string.IsNullOrEmpty(textBoxName.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxPrice.Text)) { - MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_sushiIngredients == null || _sushiIngredients.Count == 0) { - MessageBox.Show("Заполните ингредиенты", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Сохранение суши"); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs index 5b93cb8..0b3ba93 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -105,7 +105,7 @@ namespace SushiBarBusinessLogic.BusinessLogics }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Ингридиент с таким названием уже есть"); } } } diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 13b21b6..8b5ad72 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,6 +18,18 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger = logger; _orderStorage = orderStorage; } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } public bool CreateOrder(OrderBindingModel model) { @@ -36,6 +48,30 @@ namespace SushiBarBusinessLogic.BusinessLogics } return true; } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.SushiId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId)); + } + 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. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId); + } public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { @@ -70,43 +106,5 @@ namespace SushiBarBusinessLogic.BusinessLogics { return StatusUpdate(model, OrderStatus.Готов); } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("Order. OrderID:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.SushiId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId)); - } - 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. OrderID:{Id}. Sum:{ Sum}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId); - } } } diff --git a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs index 15a0746..92a771b 100644 --- a/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/IngredientStorage.cs @@ -16,9 +16,9 @@ namespace SushiBarListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - result.Add(component.GetViewModel); + result.Add(ingredient.GetViewModel); } return result; } @@ -29,11 +29,11 @@ namespace SushiBarListImplement.Implements { return result; } - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (component.IngredientName.Contains(model.IngredientName)) + if (ingredient.IngredientName.Contains(model.IngredientName)) { - result.Add(component.GetViewModel); + result.Add(ingredient.GetViewModel); } } return result; @@ -44,13 +44,12 @@ namespace SushiBarListImplement.Implements { return null; } - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if ((!string.IsNullOrEmpty(model.IngredientName) && - component.IngredientName == model.IngredientName) || - (model.Id.HasValue && component.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.IngredientName) && ingredient.IngredientName == model.IngredientName) || + (model.Id.HasValue && ingredient.Id == model.Id)) { - return component.GetViewModel; + return ingredient.GetViewModel; } } return null; @@ -58,11 +57,11 @@ namespace SushiBarListImplement.Implements public IngredientViewModel? Insert(IngredientBindingModel model) { model.Id = 1; - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (model.Id <= component.Id) + if (model.Id <= ingredient.Id) { - model.Id = component.Id + 1; + model.Id = ingredient.Id + 1; } } var newIngredient = Ingredient.Create(model); @@ -75,12 +74,12 @@ namespace SushiBarListImplement.Implements } public IngredientViewModel? Update(IngredientBindingModel model) { - foreach (var component in _source.Ingredients) + foreach (var ingredient in _source.Ingredients) { - if (component.Id == model.Id) + if (ingredient.Id == model.Id) { - component.Update(model); - return component.GetViewModel; + ingredient.Update(model); + return ingredient.GetViewModel; } } return null; diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index 7674b86..d2878ca 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -47,8 +47,7 @@ namespace SushiBarListImplement.Implements } foreach (var sushi in _source.ListSushi) { - if ((!string.IsNullOrEmpty(model.SushiName) && - sushi.SushiName == model.SushiName) || + if ((!string.IsNullOrEmpty(model.SushiName) && sushi.SushiName == model.SushiName) || (model.Id.HasValue && sushi.Id == model.Id)) { return sushi.GetViewModel; diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 6d2dbba..a3bcd59 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -7,6 +7,7 @@ namespace SushiBarListImplement.Models { public class Order : IOrderModel { + public int Id { get; private set; } public int SushiId { get; private set; } public string SushiName { get; private set; } = string.Empty; public int Count { get; private set; } @@ -14,7 +15,6 @@ namespace SushiBarListImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null) -- 2.25.1 From 9af0c201fb03fac0ab2429b3e0ada8444f2e400c Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 12:11:49 +0400 Subject: [PATCH 06/13] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormCreateOrder.cs | 1 - SushiBar/SushiBar/FormMain.cs | 18 ------------- .../BusinessLogics/OrderLogic.cs | 17 +++++++++++-- .../BindingModels/OrderBindingModel.cs | 1 - .../Implements/OrderStorage.cs | 25 ++++++++++++++----- .../SushiBarListImplement/Models/Order.cs | 4 --- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index 26d31f5..ebec9b3 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -88,7 +88,6 @@ namespace SushiBarView var operationResult = _logicO.CreateOrder(new OrderBindingModel { SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), - SushiName = comboBoxSushi.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index fb523ea..aa6f30c 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -75,12 +75,6 @@ namespace SushiBarView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -106,12 +100,6 @@ namespace SushiBarView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -137,12 +125,6 @@ namespace SushiBarView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 8b5ad72..31e9042 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -75,14 +75,27 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); - if (model.Status + 1 != newStatus) + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; } model.Status = newStatus; + model.SushiId = viewModel.SushiId; + model.Count = viewModel.Count; + model.Sum = viewModel.Sum; + model.DateCreate = viewModel.DateCreate; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); if (_orderStorage.Update(model) == null) { model.Status--; diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index 65c3d70..9f761e8 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -6,7 +6,6 @@ namespace SushiBarContracts.BindingModels public class OrderBindingModel : IOrderModel { public int SushiId { get; set; } - public string SushiName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index 9105ec6..c6b6e64 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -18,7 +18,7 @@ namespace SushiBarListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -33,7 +33,7 @@ namespace SushiBarListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } return result; @@ -48,11 +48,24 @@ namespace SushiBarListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetViewModel(order); } } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var iceCream in _source.ListSushi) + { + if (iceCream.Id == order.SushiId) + { + viewModel.SushiName = iceCream.SushiName; + break; + } + } + return viewModel; + } public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; @@ -69,7 +82,7 @@ namespace SushiBarListImplement.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) { @@ -78,7 +91,7 @@ namespace SushiBarListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -91,7 +104,7 @@ namespace SushiBarListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } return null; diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index a3bcd59..473e056 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -9,7 +9,6 @@ namespace SushiBarListImplement.Models { public int Id { get; private set; } public int SushiId { get; private set; } - public string SushiName { get; private set; } = string.Empty; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -24,7 +23,6 @@ namespace SushiBarListImplement.Models return new Order { SushiId = model.SushiId, - SushiName = model.SushiName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -40,7 +38,6 @@ namespace SushiBarListImplement.Models return; } SushiId = model.SushiId; - SushiName = model.SushiName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -51,7 +48,6 @@ namespace SushiBarListImplement.Models public OrderViewModel GetViewModel => new() { SushiId = SushiId, - SushiName = SushiName, Count = Count, Sum = Sum, DateCreate = DateCreate, -- 2.25.1 From 218ba80bf653f477725f0c855f40189d4f0a435c Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 12:27:26 +0400 Subject: [PATCH 07/13] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs | 4 ---- SushiBar/SushiBarListImplement/Models/Order.cs | 6 ------ 2 files changed, 10 deletions(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 31e9042..c4393ef 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -86,10 +86,6 @@ namespace SushiBarBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - model.SushiId = viewModel.SushiId; - model.Count = viewModel.Count; - model.Sum = viewModel.Sum; - model.DateCreate = viewModel.DateCreate; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; else { diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 473e056..522d392 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -37,13 +37,7 @@ namespace SushiBarListImplement.Models { return; } - SushiId = model.SushiId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; - DateImplement = model.DateImplement; - Id = model.Id; } public OrderViewModel GetViewModel => new() { -- 2.25.1 From df37126b5475a210495bbc1ac917932a35c37260 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 12:33:09 +0400 Subject: [PATCH 08/13] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index c4393ef..2d37796 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -86,7 +86,7 @@ namespace SushiBarBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; else { model.DateImplement = viewModel.DateImplement; -- 2.25.1 From 5cf4115a8e6d9cadbf56ca6194cc8892e5e1aafa Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 13:11:05 +0400 Subject: [PATCH 09/13] =?UTF-8?q?=D0=9D=D0=B0=D0=B4=D0=B5=D1=8E=D1=81?= =?UTF-8?q?=D1=8C=20=D1=8D=D1=82=D0=BE=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.cs | 15 +++++++++++++++ SushiBar/SushiBarListImplement/Models/Order.cs | 1 + 2 files changed, 16 insertions(+) diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index aa6f30c..4ea5668 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -75,6 +75,11 @@ namespace SushiBarView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -100,6 +105,11 @@ namespace SushiBarView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -125,6 +135,11 @@ namespace SushiBarView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index 522d392..445b162 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -38,6 +38,7 @@ namespace SushiBarListImplement.Models return; } Status = model.Status; + DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { -- 2.25.1 From b95a2c41731aab5af52915aad10d0a81e7c5d475 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 14:58:35 +0400 Subject: [PATCH 10/13] =?UTF-8?q?=D0=9D=D1=83=20=D1=8D=D1=82=D0=BE=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/Implements/OrderStorage.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index c6b6e64..3254155 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -56,11 +56,11 @@ namespace SushiBarListImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var iceCream in _source.ListSushi) + foreach (var sushi in _source.ListSushi) { - if (iceCream.Id == order.SushiId) + if (sushi.Id == order.SushiId) { - viewModel.SushiName = iceCream.SushiName; + viewModel.SushiName = sushi.SushiName; break; } } -- 2.25.1 From 4a2b0c5192f55373a0ca3081bd6ede67e8209c7a Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 16:23:30 +0400 Subject: [PATCH 11/13] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D0=B2=D0=B0=20=D0=B8=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 07ff1b6..f38dd3a 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -5,9 +5,8 @@ using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarListImplement.Implements; -using SushiBarView; -namespace SushiBar +namespace SushiBarView { internal static class Program { -- 2.25.1 From 2591be00fddf49b3cc672d9612ae97910164a306 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 11:44:33 +0400 Subject: [PATCH 12/13] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=8E=20=D1=81=D1=83=D1=88=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 4ea5668..5c13930 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -49,8 +49,8 @@ namespace SushiBarView } private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); - if (service is FormSushi form) + var service = Program.ServiceProvider?.GetService(typeof(FormListSushi)); + if (service is FormListSushi form) { form.ShowDialog(); } -- 2.25.1 From 12ca78bbe5edb8850d8a94392f078e52dfa40092 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 14 Feb 2023 12:31:20 +0400 Subject: [PATCH 13/13] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormIngredients.cs | 1 - SushiBar/SushiBar/FormListSushi.cs | 1 - SushiBar/SushiBar/FormMain.cs | 22 +++---------------- SushiBar/SushiBar/FormSushi.cs | 1 - .../BusinessLogics/OrderLogic.cs | 2 +- 5 files changed, 4 insertions(+), 23 deletions(-) diff --git a/SushiBar/SushiBar/FormIngredients.cs b/SushiBar/SushiBar/FormIngredients.cs index 73d7cfa..781205f 100644 --- a/SushiBar/SushiBar/FormIngredients.cs +++ b/SushiBar/SushiBar/FormIngredients.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormListSushi.cs b/SushiBar/SushiBar/FormListSushi.cs index 333b51c..d20376b 100644 --- a/SushiBar/SushiBar/FormListSushi.cs +++ b/SushiBar/SushiBar/FormListSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index 5c13930..6255276 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarDataModels.Enums; @@ -74,12 +73,7 @@ namespace SushiBarView { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { @@ -104,12 +98,7 @@ namespace SushiBarView { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { @@ -134,12 +123,7 @@ namespace SushiBarView { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) { diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 67496b1..515011f 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using SushiBar; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 2d37796..3baee63 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -91,7 +91,7 @@ namespace SushiBarBusinessLogic.BusinessLogics { model.DateImplement = viewModel.DateImplement; } - CheckModel(model); + CheckModel(model, false); if (_orderStorage.Update(model) == null) { model.Status--; -- 2.25.1