From 021255a13443a40e588e687adbb9e29fd990da24 Mon Sep 17 00:00:00 2001 From: Allllen4a Date: Thu, 8 Feb 2024 17:48:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pizzeria/Pizzeria.sln | 49 ++++ Pizzeria/Pizzeria/FormComponent.Designer.cs | 118 +++++++++ Pizzeria/Pizzeria/FormComponent.cs | 93 +++++++ Pizzeria/Pizzeria/FormComponent.resx | 120 +++++++++ Pizzeria/Pizzeria/FormComponents.Designer.cs | 121 ++++++++++ Pizzeria/Pizzeria/FormComponents.cs | 123 ++++++++++ Pizzeria/Pizzeria/FormComponents.resx | 120 +++++++++ Pizzeria/Pizzeria/FormCreateOrder.Designer.cs | 143 +++++++++++ Pizzeria/Pizzeria/FormCreateOrder.cs | 124 ++++++++++ Pizzeria/Pizzeria/FormCreateOrder.resx | 120 +++++++++ Pizzeria/Pizzeria/FormMain.Designer.cs | 171 +++++++++++++ Pizzeria/Pizzeria/FormMain.cs | 162 +++++++++++++ Pizzeria/Pizzeria/FormMain.resx | 123 ++++++++++ Pizzeria/Pizzeria/FormPizza.Designer.cs | 220 +++++++++++++++++ Pizzeria/Pizzeria/FormPizza.cs | 228 ++++++++++++++++++ Pizzeria/Pizzeria/FormPizza.resx | 129 ++++++++++ .../Pizzeria/FormPizzaComponent.Designer.cs | 118 +++++++++ Pizzeria/Pizzeria/FormPizzaComponent.cs | 90 +++++++ Pizzeria/Pizzeria/FormPizzaComponent.resx | 120 +++++++++ Pizzeria/Pizzeria/FormPizzas.Designer.cs | 113 +++++++++ Pizzeria/Pizzeria/FormPizzas.cs | 116 +++++++++ Pizzeria/Pizzeria/FormPizzas.resx | 120 +++++++++ Pizzeria/Pizzeria/PizzeriaView.csproj | 34 +++ Pizzeria/Pizzeria/Program.cs | 55 +++++ Pizzeria/Pizzeria/nlog.config | 3 + .../BusinessLogics/ComponentLogic.cs | 119 +++++++++ .../BusinessLogics/OrderLogic.cs | 125 ++++++++++ .../BusinessLogics/PizzaLogic.cs | 116 +++++++++ .../PizzeriaBusinessLogic.csproj | 13 + .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../BindingModels/PizzaBindingModel.cs | 17 ++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/IPizzaLogic.cs | 20 ++ .../PizzeriaContracts.csproj | 17 ++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/PizzaSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 21 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IPizzaStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 21 ++ .../ViewModels/OrderViewModel.cs | 37 +++ .../ViewModels/PizzaViewModel.cs | 23 ++ .../PizzeriaDataModels/Enums/OrderStatus.cs | 17 ++ Pizzeria/PizzeriaDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 14 ++ .../PizzeriaDataModels/Models/IOrderModel.cs | 19 ++ .../PizzeriaDataModels/Models/IPizzaModel.cs | 15 ++ .../PizzeriaDataModels.csproj | 9 + .../DataListSingleton.cs | 33 +++ .../Implements/ComponentStorage.cs | 113 +++++++++ .../Implements/OrderStorage.cs | 125 ++++++++++ .../Implements/PizzaStorage.cs | 113 +++++++++ .../PizzeriaListImplement/Models/Component.cs | 47 ++++ .../PizzeriaListImplement/Models/Order.cs | 62 +++++ .../PizzeriaListImplement/Models/Pizza.cs | 53 ++++ .../PizzeriaListImplement.csproj | 13 + 59 files changed, 4268 insertions(+) create mode 100644 Pizzeria/Pizzeria.sln create mode 100644 Pizzeria/Pizzeria/FormComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.resx create mode 100644 Pizzeria/Pizzeria/FormComponents.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.resx create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.resx create mode 100644 Pizzeria/Pizzeria/FormMain.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormMain.cs create mode 100644 Pizzeria/Pizzeria/FormMain.resx create mode 100644 Pizzeria/Pizzeria/FormPizza.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.resx create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.cs create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.resx create mode 100644 Pizzeria/Pizzeria/FormPizzas.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.resx create mode 100644 Pizzeria/Pizzeria/PizzeriaView.csproj create mode 100644 Pizzeria/Pizzeria/Program.cs create mode 100644 Pizzeria/Pizzeria/nlog.config create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogics/PizzaLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs create mode 100644 Pizzeria/PizzeriaDataModels/IId.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj create mode 100644 Pizzeria/PizzeriaListImplement/DataListSingleton.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Component.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Order.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Pizza.cs create mode 100644 Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln new file mode 100644 index 0000000..031e3eb --- /dev/null +++ b/Pizzeria/Pizzeria.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34322.80 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaView", "Pizzeria\PizzeriaView.csproj", "{72AA6ABF-D9EE-4A9D-8E2E-26802D7D2CF3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{B9E1561D-35EA-4C83-9B09-6D5F6306D3BC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaContracts", "PizzeriaContracts\PizzeriaContracts.csproj", "{3888C0EA-7BF2-4E41-882F-FBB08D9E17E9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDataModels", "PizzeriaDataModels\PizzeriaDataModels.csproj", "{42B0E1E3-0BCC-48BE-AE71-382ABBACBEA6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{E219B355-7A12-4E5C-A09A-035A60B11A9D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {72AA6ABF-D9EE-4A9D-8E2E-26802D7D2CF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72AA6ABF-D9EE-4A9D-8E2E-26802D7D2CF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72AA6ABF-D9EE-4A9D-8E2E-26802D7D2CF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72AA6ABF-D9EE-4A9D-8E2E-26802D7D2CF3}.Release|Any CPU.Build.0 = Release|Any CPU + {B9E1561D-35EA-4C83-9B09-6D5F6306D3BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9E1561D-35EA-4C83-9B09-6D5F6306D3BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9E1561D-35EA-4C83-9B09-6D5F6306D3BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9E1561D-35EA-4C83-9B09-6D5F6306D3BC}.Release|Any CPU.Build.0 = Release|Any CPU + {3888C0EA-7BF2-4E41-882F-FBB08D9E17E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3888C0EA-7BF2-4E41-882F-FBB08D9E17E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3888C0EA-7BF2-4E41-882F-FBB08D9E17E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3888C0EA-7BF2-4E41-882F-FBB08D9E17E9}.Release|Any CPU.Build.0 = Release|Any CPU + {42B0E1E3-0BCC-48BE-AE71-382ABBACBEA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42B0E1E3-0BCC-48BE-AE71-382ABBACBEA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {42B0E1E3-0BCC-48BE-AE71-382ABBACBEA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {42B0E1E3-0BCC-48BE-AE71-382ABBACBEA6}.Release|Any CPU.Build.0 = Release|Any CPU + {E219B355-7A12-4E5C-A09A-035A60B11A9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E219B355-7A12-4E5C-A09A-035A60B11A9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E219B355-7A12-4E5C-A09A-035A60B11A9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E219B355-7A12-4E5C-A09A-035A60B11A9D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D2464445-A249-49AE-ACA3-1581CF7797F1} + EndGlobalSection +EndGlobal diff --git a/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs new file mode 100644 index 0000000..90d35e8 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace PizzeriaView +{ + partial class FormComponent + { + /// + /// 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() + { + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(124, 23); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(317, 31); + textBoxName.TabIndex = 0; + // + // textBoxCost + // + textBoxCost.Location = new Point(124, 92); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(132, 31); + textBoxCost.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(22, 29); + labelName.Name = "labelName"; + labelName.Size = new Size(90, 25); + labelName.TabIndex = 2; + labelName.Text = "Название"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(22, 98); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(53, 25); + labelCost.TabIndex = 3; + labelCost.Text = "Цена"; + // + // buttonSave + // + buttonSave.Location = new Point(124, 155); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(107, 47); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(257, 155); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(100, 47); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(469, 214); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelName; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs new file mode 100644 index 0000000..30a505f --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение ингредиента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + 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 ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + 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/Pizzeria/Pizzeria/FormComponent.resx b/Pizzeria/Pizzeria/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs new file mode 100644 index 0000000..9fb09fe --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -0,0 +1,121 @@ +namespace PizzeriaView +{ + partial class FormComponents + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(739, 491); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(785, 44); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(128, 45); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(785, 128); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(128, 45); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(785, 215); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(130, 42); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(785, 298); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(128, 43); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(929, 491); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs new file mode 100644 index 0000000..643cba5 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -0,0 +1,123 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].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(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void 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 ComponentBindingModel + { + 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/Pizzeria/Pizzeria/FormComponents.resx b/Pizzeria/Pizzeria/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..edc1d24 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace PizzeriaView +{ + 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() + { + comboBoxPizza = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelPizza = new Label(); + labelCount = new Label(); + labelSum = new Label(); + SuspendLayout(); + // + // comboBoxPizza + // + comboBoxPizza.FormattingEnabled = true; + comboBoxPizza.Location = new Point(166, 25); + comboBoxPizza.Name = "comboBoxPizza"; + comboBoxPizza.Size = new Size(274, 33); + comboBoxPizza.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(166, 71); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(199, 31); + textBoxCount.TabIndex = 1; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(166, 120); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(239, 31); + textBoxSum.TabIndex = 2; + textBoxSum.TextChanged += textBoxSum_TextChanged; + // + // buttonSave + // + buttonSave.Location = new Point(192, 208); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 46); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(313, 211); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(153, 40); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelPizza + // + labelPizza.AutoSize = true; + labelPizza.Location = new Point(37, 25); + labelPizza.Name = "labelPizza"; + labelPizza.Size = new Size(80, 25); + labelPizza.TabIndex = 5; + labelPizza.Text = "Изделие"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(37, 77); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(107, 25); + labelCount.TabIndex = 6; + labelCount.Text = "Количество"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(37, 126); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(67, 25); + labelSum.TabIndex = 7; + labelSum.Text = "Сумма"; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(507, 283); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelPizza); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPizza); + Name = "FormCreateOrder"; + Text = "FormCreateOrder"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxPizza; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + private Label labelPizza; + private Label labelCount; + private Label labelSum; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs new file mode 100644 index 0000000..75d4873 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.cs @@ -0,0 +1,124 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logicP; + private readonly IOrderLogic _logicO; + private List? _list; + + public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _list; + comboBoxPizza.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для заказа"); + } + } + + + private void CalcSum() + { + if (comboBoxPizza.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPizza.SelectedValue); + var Pizza = _logicP.ReadElement(new PizzaSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void textBoxSum_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/Pizzeria/FormCreateOrder.resx b/Pizzeria/Pizzeria/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs new file mode 100644 index 0000000..da05432 --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.Designer.cs @@ -0,0 +1,171 @@ +namespace Pizzeria +{ + 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() + { + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + bookToolStripMenuItem = new MenuStrip(); + справочникToolStripMenuItem = new ToolStripMenuItem(); + ингредиентыToolStripMenuItem = new ToolStripMenuItem(); + пиццаToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + bookToolStripMenuItem.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 28); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(548, 410); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(607, 49); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(166, 33); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "button1"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(607, 112); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(166, 33); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "button2"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(607, 174); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(166, 33); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "button3"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(607, 249); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(166, 33); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "button4"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(607, 324); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(166, 33); + buttonRef.TabIndex = 6; + buttonRef.Text = "button5"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // bookToolStripMenuItem + // + bookToolStripMenuItem.ImageScalingSize = new Size(24, 24); + bookToolStripMenuItem.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem }); + bookToolStripMenuItem.Location = new Point(0, 0); + bookToolStripMenuItem.Name = "bookToolStripMenuItem"; + bookToolStripMenuItem.Size = new Size(800, 33); + bookToolStripMenuItem.TabIndex = 7; + bookToolStripMenuItem.Text = "menuStrip1"; + // + // справочникToolStripMenuItem + // + справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ингредиентыToolStripMenuItem, пиццаToolStripMenuItem }); + справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; + справочникToolStripMenuItem.Size = new Size(129, 29); + справочникToolStripMenuItem.Text = "Справочник"; + // + // ингредиентыToolStripMenuItem + // + ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; + ингредиентыToolStripMenuItem.Size = new Size(223, 34); + ингредиентыToolStripMenuItem.Text = "Ингредиенты"; + ингредиентыToolStripMenuItem.Click += ингредиентыToolStripMenuItem_Click; + // + // пиццаToolStripMenuItem + // + пиццаToolStripMenuItem.Name = "пиццаToolStripMenuItem"; + пиццаToolStripMenuItem.Size = new Size(223, 34); + пиццаToolStripMenuItem.Text = "Пицца"; + пиццаToolStripMenuItem.Click += пиццаToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(bookToolStripMenuItem); + MainMenuStrip = bookToolStripMenuItem; + Name = "FormMain"; + Text = "Form1"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + bookToolStripMenuItem.ResumeLayout(false); + bookToolStripMenuItem.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private MenuStrip bookToolStripMenuItem; + private ToolStripMenuItem справочникToolStripMenuItem; + private ToolStripMenuItem ингредиентыToolStripMenuItem; + private ToolStripMenuItem пиццаToolStripMenuItem; + } +} diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs new file mode 100644 index 0000000..276fbbc --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.cs @@ -0,0 +1,162 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaView; +using System.Windows.Forms; + +namespace Pizzeria +{ + 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 buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + + } + } + + + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PizzaId"].Visible = false; + dataGridView.Columns["PizzaName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzas)); + if (service is FormPizzas form) + { + form.ShowDialog(); + } + } + + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" No{id}. ' '", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" No{id}. ''", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" No{id}. ''", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception(" . ."); + } + _logger.LogInformation(" No{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(); + } + } +} diff --git a/Pizzeria/Pizzeria/FormMain.resx b/Pizzeria/Pizzeria/FormMain.resx new file mode 100644 index 0000000..3eca2d0 --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormPizza.Designer.cs b/Pizzeria/Pizzeria/FormPizza.Designer.cs new file mode 100644 index 0000000..460b0bf --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs @@ -0,0 +1,220 @@ +namespace PizzeriaView +{ + partial class FormPizza + { + /// + /// 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() + { + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(244, 23); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(265, 31); + textBoxName.TabIndex = 0; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(244, 70); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(259, 31); + textBoxPrice.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(148, 29); + labelName.Name = "labelName"; + labelName.Size = new Size(90, 25); + labelName.TabIndex = 2; + labelName.Text = "Название"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(148, 89); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(53, 25); + labelCost.TabIndex = 3; + labelCost.Text = "Цена"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount }); + dataGridView.Location = new Point(12, 117); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(497, 335); + dataGridView.TabIndex = 4; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 8; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 150; + // + // ColumnComponent + // + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.MinimumWidth = 6; + ColumnComponent.Name = "ColumnComponent"; + ColumnComponent.ReadOnly = true; + ColumnComponent.Width = 150; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 150; + // + // buttonAdd + // + buttonAdd.Location = new Point(601, 132); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(133, 52); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(600, 219); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(133, 30); + buttonEdit.TabIndex = 6; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(603, 280); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(126, 36); + buttonDelete.TabIndex = 7; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(611, 355); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(126, 42); + buttonUpdate.TabIndex = 8; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonSave + // + buttonSave.Location = new Point(524, 411); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(74, 27); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(648, 414); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(105, 28); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormPizza + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Name = "FormPizza"; + Text = "FormPizza"; + Load += FormPizza_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxPrice; + private Label labelName; + private Label labelCost; + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs new file mode 100644 index 0000000..f28c3b4 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.cs @@ -0,0 +1,228 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormPizza : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + private int? _id; + private Dictionary _PizzaComponents; + public int Id { set { _id = value; } } + + public FormPizza(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _PizzaComponents = new Dictionary(); + } + + private void FormPizza_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка пиццы"); + try + { + var view = _logic.ReadElement(new PizzaSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PizzaName; + textBoxPrice.Text = view.Price.ToString(); + _PizzaComponents = view.PizzaComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + + + + } + + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиент пиццы"); + try + { + if (_PizzaComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _PizzaComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки ингредиента пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _PizzaComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_PizzaComponents.ContainsKey(form.Id)) + { + _PizzaComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _PizzaComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + + private void buttonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _PizzaComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление ингредиента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_PizzaComponents == null || _PizzaComponents.Count == 0) + { + MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение пиццы"); + try + { + var model = new PizzaBindingModel + { + Id = _id ?? 0, + PizzaName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PizzaComponents = _PizzaComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/Pizzeria/FormPizza.resx b/Pizzeria/Pizzeria/FormPizza.resx new file mode 100644 index 0000000..524a4e1 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs new file mode 100644 index 0000000..7adaade --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace PizzeriaView +{ + partial class FormPizzaComponent + { + /// + /// 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() + { + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + labelComponent = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(127, 27); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(329, 33); + comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(127, 85); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(315, 31); + textBoxCount.TabIndex = 1; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(38, 35); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(59, 25); + labelComponent.TabIndex = 2; + labelComponent.Text = "label1"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(38, 91); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(59, 25); + labelCount.TabIndex = 3; + labelCount.Text = "label2"; + // + // buttonSave + // + buttonSave.Location = new Point(127, 128); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(127, 44); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(305, 128); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(151, 44); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormPizzaComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(557, 184); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Name = "FormPizzaComponent"; + Text = "Ингредиент для пиццы"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.cs b/Pizzeria/Pizzeria/FormPizzaComponent.cs new file mode 100644 index 0000000..cc6f82b --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.cs @@ -0,0 +1,90 @@ +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormPizzaComponent : Form + { + private readonly List? _list; + + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + + public FormPizzaComponent(IComponentLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.resx b/Pizzeria/Pizzeria/FormPizzaComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs new file mode 100644 index 0000000..c8386f9 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs @@ -0,0 +1,113 @@ +namespace PizzeriaView +{ + partial class FormPizzas + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonEdit = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(29, 28); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(471, 383); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(540, 58); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(202, 71); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "button1"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(540, 140); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(202, 71); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "button2"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(540, 217); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(202, 71); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "button3"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(540, 328); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(202, 71); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "button4"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // FormPizzas + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormPizzas"; + Text = "FormPizzas"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzas.cs b/Pizzeria/Pizzeria/FormPizzas.cs new file mode 100644 index 0000000..5e4bb25 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PizzeriaView +{ + public partial class FormPizzas : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + + public FormPizzas(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PizzaComponents"].Visible = false; + dataGridView.Columns["PizzaName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка пиццы"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); + if (service is FormPizza form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonEdit_Click(object sender, EventArgs e) + { + + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); + if (service is FormPizza form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + } + + 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 PizzaBindingModel + { + 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/Pizzeria/Pizzeria/FormPizzas.resx b/Pizzeria/Pizzeria/FormPizzas.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/PizzeriaView.csproj b/Pizzeria/Pizzeria/PizzeriaView.csproj new file mode 100644 index 0000000..9fb823c --- /dev/null +++ b/Pizzeria/Pizzeria/PizzeriaView.csproj @@ -0,0 +1,34 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs new file mode 100644 index 0000000..f5d752b --- /dev/null +++ b/Pizzeria/Pizzeria/Program.cs @@ -0,0 +1,55 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PizzeriaBusinessLogic.BusinessLogics; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.StoragesContracts; +using PizzeriaListImplement.Implements; +using PizzeriaView; +using System; + +namespace Pizzeria +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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/Pizzeria/Pizzeria/nlog.config b/Pizzeria/Pizzeria/nlog.config new file mode 100644 index 0000000..49cc43e --- /dev/null +++ b/Pizzeria/Pizzeria/nlog.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..c6712a8 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия ингредиента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}.Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Ингредиент с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..16d1722 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.PizzaId, model.Count, model.Sum, model.Id); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + model.DateCreate = element.DateCreate; + model.PizzaId = element.PizzaId; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (requiredStatus - model.Status == 1) + { + model.Status = requiredStatus; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/PizzaLogic.cs new file mode 100644 index 0000000..eda3ee0 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/PizzaLogic.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class PizzaLogic : IPizzaLogic + { + private readonly ILogger _logger; + private readonly IPizzaStorage _PizzaStorage; + public PizzaLogic(ILogger logger, IPizzaStorage PizzaStorage) + { + _logger = logger; + _PizzaStorage = PizzaStorage; + } + public List? ReadList(PizzaSearchModel? model) + { + _logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id); + var list = model == null ? _PizzaStorage.GetFullList() : _PizzaStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public PizzaViewModel? ReadElement(PizzaSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id}", model.PizzaName, model.Id); + var element = _PizzaStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(PizzaBindingModel model) + { + CheckModel(model); + if (_PizzaStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PizzaBindingModel model) + { + CheckModel(model); + if (_PizzaStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PizzaBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_PizzaStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PizzaBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PizzaName)) + { + throw new ArgumentNullException("Нет названия пиццы", nameof(model.PizzaName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); + } + if (model.PizzaComponents == null || model.PizzaComponents.Count == 0) + { + throw new ArgumentNullException("Перечень ингредиентов не может быть пустым", nameof(model.PizzaComponents)); + } + _logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{Price}.Id: { Id}", model.PizzaName, model.Price, model.Id); + var element = _PizzaStorage.GetElement(new PizzaSearchModel + { + PizzaName = model.PizzaName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пицца с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj new file mode 100644 index 0000000..eef06e7 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..06f07c8 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..18f900c --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PizzaId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs new file mode 100644 index 0000000..e5390cb --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs @@ -0,0 +1,17 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BindingModels +{ + public class PizzaBindingModel : IPizzaModel + { + public int Id { get; set; } + public string PizzaName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PizzaComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..96c1ea5 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..ef47900 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.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/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs new file mode 100644 index 0000000..fe88f72 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs @@ -0,0 +1,20 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IPizzaLogic + { + List? ReadList(PizzaSearchModel? model); + PizzaViewModel? ReadElement(PizzaSearchModel model); + bool Create(PizzaBindingModel model); + bool Update(PizzaBindingModel model); + bool Delete(PizzaBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj new file mode 100644 index 0000000..e821d51 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..bba94a4 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..baddda5 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs new file mode 100644 index 0000000..fc24a54 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class PizzaSearchModel + { + public int? Id { get; set; } + public string? PizzaName { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..b44e8a5 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..ad90930 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.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/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs new file mode 100644 index 0000000..5be0092 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IPizzaStorage.cs @@ -0,0 +1,21 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.StoragesContracts +{ + public interface IPizzaStorage + { + List GetFullList(); + List GetFilteredList(PizzaSearchModel model); + PizzaViewModel? GetElement(PizzaSearchModel model); + PizzaViewModel? Insert(PizzaBindingModel model); + PizzaViewModel? Update(PizzaBindingModel model); + PizzaViewModel? Delete(PizzaBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..fa3377d --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название ингредиента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..13bf7b1 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int PizzaId { get; set; } + + [DisplayName("Пицца")] + public string PizzaName { 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/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs new file mode 100644 index 0000000..bc37a36 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs @@ -0,0 +1,23 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class PizzaViewModel : IPizzaModel + { + public int Id { get; set; } + + [DisplayName("Название пиццы")] + public string PizzaName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary PizzaComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..0dfea07 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/IId.cs b/Pizzeria/PizzeriaDataModels/IId.cs new file mode 100644 index 0000000..3ff48db --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..eae664b --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..bfb88af --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using PizzeriaDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface IOrderModel : IId + { + int PizzaId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs new file mode 100644 index 0000000..8cdbe9b --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface IPizzaModel : IId + { + string PizzaName { get; } + double Price { get; } + Dictionary PizzaComponents { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs new file mode 100644 index 0000000..f61d7cd --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -0,0 +1,33 @@ +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Pizzas { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Pizzas = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..093f270 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,113 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..74afdc8 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -0,0 +1,125 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.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(AttachPizzaName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachPizzaName(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 AttachPizzaName(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 AttachPizzaName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachPizzaName(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 AttachPizzaName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachPizzaName(OrderViewModel model) + { + foreach (var pizza in _source.Pizzas) + { + if (pizza.Id == model.PizzaId) + { + model.PizzaName = pizza.PizzaName; + return model; + } + } + return model; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs new file mode 100644 index 0000000..a9db898 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs @@ -0,0 +1,113 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Implements +{ + public class PizzaStorage : IPizzaStorage + { + private readonly DataListSingleton _source; + + public PizzaStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var pizzas in _source.Pizzas) + { + result.Add(pizzas.GetViewModel); + } + return result; + } + + public List GetFilteredList(PizzaSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PizzaName)) + { + return result; + } + foreach (var pizzas in _source.Pizzas) + { + if (pizzas.PizzaName.Contains(model.PizzaName)) + { + result.Add(pizzas.GetViewModel); + } + } + return result; + } + + public PizzaViewModel? GetElement(PizzaSearchModel model) + { + if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue) + { + return null; + } + foreach (var pizzas in _source.Pizzas) + { + if ((!string.IsNullOrEmpty(model.PizzaName) && pizzas.PizzaName == model.PizzaName) || + (model.Id.HasValue && pizzas.Id == model.Id)) + { + return pizzas.GetViewModel; + } + } + return null; + } + + public PizzaViewModel? Insert(PizzaBindingModel model) + { + model.Id = 1; + foreach (var pizzas in _source.Pizzas) + { + if (model.Id <= pizzas.Id) + { + model.Id = pizzas.Id + 1; + } + } + var newPizzas = Pizza.Create(model); + if (newPizzas == null) + { + return null; + } + _source.Pizzas.Add(newPizzas); + return newPizzas.GetViewModel; + } + + public PizzaViewModel? Update(PizzaBindingModel model) + { + foreach (var pizzas in _source.Pizzas) + { + if (pizzas.Id == model.Id) + { + pizzas.Update(model); + return pizzas.GetViewModel; + } + } + return null; + } + + public PizzaViewModel? Delete(PizzaBindingModel model) + { + for (int i = 0; i < _source.Pizzas.Count; ++i) + { + if (_source.Pizzas[i].Id == model.Id) + { + var element = _source.Pizzas[i]; + _source.Pizzas.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Component.cs b/Pizzeria/PizzeriaListImplement/Models/Component.cs new file mode 100644 index 0000000..9c9ec06 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; private set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs new file mode 100644 index 0000000..79fb1fc --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -0,0 +1,62 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PizzaId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PizzaId = model.PizzaId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PizzaId = PizzaId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs new file mode 100644 index 0000000..4317ed1 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs @@ -0,0 +1,53 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Pizza : IPizzaModel + { + public int Id { get; private set; } + public string PizzaName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PizzaComponents { get; private set; } = new Dictionary(); + + public static Pizza? Create(PizzaBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pizza() + { + Id = model.Id, + PizzaName = model.PizzaName, + Price = model.Price, + PizzaComponents = model.PizzaComponents, + }; + } + + public void Update(PizzaBindingModel? model) + { + if (model == null) + { + return; + } + PizzaName = model.PizzaName; + Price = model.Price; + PizzaComponents = model.PizzaComponents; + } + + public PizzaViewModel GetViewModel => new() + { + Id = Id, + PizzaName = PizzaName, + Price = Price, + PizzaComponents = PizzaComponents + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj new file mode 100644 index 0000000..eef06e7 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + +