From f5264d9fcdd4607ff6892d0bbd46677d576a29f2 Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Sat, 24 Feb 2024 09:40:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop.sln | 26 +- FlowerShop/FlowerShop/FlowerShop.csproj | 11 - FlowerShop/FlowerShop/FlowerShopView.csproj | 23 ++ .../FlowerShop/FormComponent.Designer.cs | 118 +++++++++ FlowerShop/FlowerShop/FormComponent.cs | 82 +++++++ FlowerShop/FlowerShop/FormComponent.resx | 120 ++++++++++ .../FlowerShop/FormComponents.Designer.cs | 114 +++++++++ FlowerShop/FlowerShop/FormComponents.cs | 104 ++++++++ FlowerShop/FlowerShop/FormComponents.resx | 120 ++++++++++ .../FlowerShop/FormCreateOrder.Designer.cs | 146 ++++++++++++ FlowerShop/FlowerShop/FormCreateOrder.cs | 111 +++++++++ FlowerShop/FlowerShop/FormCreateOrder.resx | 120 ++++++++++ FlowerShop/FlowerShop/FormFlower.Designer.cs | 223 ++++++++++++++++++ FlowerShop/FlowerShop/FormFlower.cs | 198 ++++++++++++++++ FlowerShop/FlowerShop/FormFlower.resx | 120 ++++++++++ .../FormFlowerComponent.Designer.cs | 119 ++++++++++ FlowerShop/FlowerShop/FormFlowerComponent.cs | 79 +++++++ .../FlowerShop/FormFlowerComponent.resx | 120 ++++++++++ FlowerShop/FlowerShop/FormFlowers.Designer.cs | 114 +++++++++ FlowerShop/FlowerShop/FormFlowers.cs | 105 +++++++++ FlowerShop/FlowerShop/FormFlowers.resx | 120 ++++++++++ FlowerShop/FlowerShop/FormMain.Designer.cs | 171 ++++++++++++++ FlowerShop/FlowerShop/FormMain.cs | 144 +++++++++++ FlowerShop/FlowerShop/FormMain.resx | 123 ++++++++++ FlowerShop/FlowerShop/Program.cs | 40 +++- FlowerShop/FlowerShop/nlog.config | 15 ++ .../BusinessLogics/ComponentLogic.cs | 110 +++++++++ .../BusinessLogics/FlowerLogic.cs | 111 +++++++++ .../BusinessLogics/OrderLogic.cs | 123 ++++++++++ .../FlowerShopBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 11 + .../BindingModels/FlowerBindingModel.cs | 17 ++ .../BindingModels/OrderBindingModel.cs | 17 ++ .../IComponentLogic.cs | 16 ++ .../BusinessLogicsContracts/IFlowerLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../FlowerShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/FlowerSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/IComponentStorage.cs | 17 ++ .../StoragesContracts/IFlowerStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 17 ++ .../ViewModels/ComponentViewModel.cs | 16 ++ .../ViewModels/FlowerViewModel.cs | 20 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../FlowerShopDataModels/Enums/OrderStatus.cs | 11 + .../FlowerShopDataModels.csproj | 9 + FlowerShop/FlowerShopDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 8 + .../Models/IFlowerModel.cs | 10 + .../Models/IOrderModel.cs | 15 ++ .../DataListSingleton.cs | 26 ++ .../FlowerShopListImplement.csproj | 14 ++ .../Implements/ComponentStorage.cs | 103 ++++++++ .../Implements/FlowerStorage.cs | 103 ++++++++ .../Implements/OrderStorage.cs | 112 +++++++++ .../Models/Component.cs | 42 ++++ .../FlowerShopListImplement/Models/Flower.cs | 49 ++++ .../FlowerShopListImplement/Models/Order.cs | 59 +++++ 60 files changed, 3938 insertions(+), 15 deletions(-) delete mode 100644 FlowerShop/FlowerShop/FlowerShop.csproj create mode 100644 FlowerShop/FlowerShop/FlowerShopView.csproj create mode 100644 FlowerShop/FlowerShop/FormComponent.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.resx create mode 100644 FlowerShop/FlowerShop/FormComponents.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.resx create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.resx create mode 100644 FlowerShop/FlowerShop/FormFlower.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormFlower.cs create mode 100644 FlowerShop/FlowerShop/FormFlower.resx create mode 100644 FlowerShop/FlowerShop/FormFlowerComponent.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormFlowerComponent.cs create mode 100644 FlowerShop/FlowerShop/FormFlowerComponent.resx create mode 100644 FlowerShop/FlowerShop/FormFlowers.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormFlowers.cs create mode 100644 FlowerShop/FlowerShop/FormFlowers.resx create mode 100644 FlowerShop/FlowerShop/FormMain.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormMain.cs create mode 100644 FlowerShop/FlowerShop/FormMain.resx create mode 100644 FlowerShop/FlowerShop/nlog.config create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/FlowerLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/FlowerBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/FlowerSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/FlowerViewModel.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs create mode 100644 FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj create mode 100644 FlowerShop/FlowerShopDataModels/IId.cs create mode 100644 FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/Models/IFlowerModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs create mode 100644 FlowerShop/FlowerShopListImplement/DataListSingleton.cs create mode 100644 FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj create mode 100644 FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/FlowerStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Component.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Flower.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Order.cs diff --git a/FlowerShop/FlowerShop.sln b/FlowerShop/FlowerShop.sln index f5d0cde..8ce8db0 100644 --- a/FlowerShop/FlowerShop.sln +++ b/FlowerShop/FlowerShop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShop", "FlowerShop\FlowerShop.csproj", "{30E60505-E2FD-419B-9B9F-60830D33C5A7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopView", "FlowerShop\FlowerShopView.csproj", "{30E60505-E2FD-419B-9B9F-60830D33C5A7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopDataModels", "FlowerShopDataModels\FlowerShopDataModels.csproj", "{CF89D78C-5CB4-4BA9-9541-50179C4687DB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopContracts", "FlowerShopContracts\FlowerShopContracts.csproj", "{10E0C82C-4ADA-48C8-AA4A-73F304C51939}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowerShopBusinessLogic", "FlowerShopBusinessLogic\FlowerShopBusinessLogic.csproj", "{4A1AD35C-5A5A-4DD8-85B1-B937FF1F5BAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerShopListImplement", "FlowerShopListImplement\FlowerShopListImplement.csproj", "{8B6B6E6D-442B-46F0-8F60-E3D91E8D0AB5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {30E60505-E2FD-419B-9B9F-60830D33C5A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {30E60505-E2FD-419B-9B9F-60830D33C5A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {30E60505-E2FD-419B-9B9F-60830D33C5A7}.Release|Any CPU.Build.0 = Release|Any CPU + {CF89D78C-5CB4-4BA9-9541-50179C4687DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF89D78C-5CB4-4BA9-9541-50179C4687DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF89D78C-5CB4-4BA9-9541-50179C4687DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF89D78C-5CB4-4BA9-9541-50179C4687DB}.Release|Any CPU.Build.0 = Release|Any CPU + {10E0C82C-4ADA-48C8-AA4A-73F304C51939}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10E0C82C-4ADA-48C8-AA4A-73F304C51939}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10E0C82C-4ADA-48C8-AA4A-73F304C51939}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10E0C82C-4ADA-48C8-AA4A-73F304C51939}.Release|Any CPU.Build.0 = Release|Any CPU + {4A1AD35C-5A5A-4DD8-85B1-B937FF1F5BAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A1AD35C-5A5A-4DD8-85B1-B937FF1F5BAE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A1AD35C-5A5A-4DD8-85B1-B937FF1F5BAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A1AD35C-5A5A-4DD8-85B1-B937FF1F5BAE}.Release|Any CPU.Build.0 = Release|Any CPU + {8B6B6E6D-442B-46F0-8F60-E3D91E8D0AB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B6B6E6D-442B-46F0-8F60-E3D91E8D0AB5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B6B6E6D-442B-46F0-8F60-E3D91E8D0AB5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B6B6E6D-442B-46F0-8F60-E3D91E8D0AB5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FlowerShop/FlowerShop/FlowerShop.csproj b/FlowerShop/FlowerShop/FlowerShop.csproj deleted file mode 100644 index b57c89e..0000000 --- a/FlowerShop/FlowerShop/FlowerShop.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FlowerShopView.csproj b/FlowerShop/FlowerShop/FlowerShopView.csproj new file mode 100644 index 0000000..5982ef1 --- /dev/null +++ b/FlowerShop/FlowerShop/FlowerShopView.csproj @@ -0,0 +1,23 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponent.Designer.cs b/FlowerShop/FlowerShop/FormComponent.Designer.cs new file mode 100644 index 0000000..b9bcc58 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace FlowerShopView +{ + 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() + { + label1 = new Label(); + textBoxName = new TextBox(); + label2 = new Label(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(27, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 3; + label1.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(92, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(213, 23); + textBoxName.TabIndex = 2; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(27, 44); + label2.Name = "label2"; + label2.Size = new Size(38, 15); + label2.TabIndex = 5; + label2.Text = "Цена:"; + // + // textBoxCost + // + textBoxCost.Location = new Point(92, 41); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(152, 23); + textBoxCost.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(169, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(250, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(342, 134); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label2); + Controls.Add(textBoxCost); + Controls.Add(label1); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBoxName; + private Label label2; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponent.cs b/FlowerShop/FlowerShop/FormComponent.cs new file mode 100644 index 0000000..d39300d --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Logging; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; + +namespace FlowerShopView +{ + 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(); + } + } + +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponent.resx b/FlowerShop/FlowerShop/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormComponents.Designer.cs b/FlowerShop/FlowerShop/FormComponents.Designer.cs new file mode 100644 index 0000000..d13ceb8 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace FlowerShopView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(240, 426); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(283, 24); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(103, 28); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(283, 58); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(103, 28); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(283, 92); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(103, 28); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(283, 126); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(103, 28); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(438, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + 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 buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponents.cs b/FlowerShop/FlowerShop/FormComponents.cs new file mode 100644 index 0000000..dd94bec --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.cs @@ -0,0 +1,104 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShopView +{ + 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 FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + 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 ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormComponents.resx b/FlowerShop/FlowerShop/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..37a7b62 --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace FlowerShopView +{ + 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() + { + label1 = new Label(); + comboBoxFlower = new ComboBox(); + label2 = new Label(); + textBoxCount = new TextBox(); + label3 = new Label(); + textBoxSum = new TextBox(); + buttonCancel = new Button(); + buttonAdd = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(8, 15); + label1.Name = "label1"; + label1.Size = new Size(45, 15); + label1.TabIndex = 4; + label1.Text = "Цветы:"; + // + // comboBoxFlower + // + comboBoxFlower.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFlower.FormattingEnabled = true; + comboBoxFlower.Location = new Point(88, 12); + comboBoxFlower.Name = "comboBoxFlower"; + comboBoxFlower.Size = new Size(250, 23); + comboBoxFlower.TabIndex = 3; + comboBoxFlower.SelectedIndexChanged += ComboBoxFlower_SelectedIndexChanged; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(7, 44); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 6; + label2.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(88, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(250, 23); + textBoxCount.TabIndex = 5; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(7, 73); + label3.Name = "label3"; + label3.Size = new Size(48, 15); + label3.TabIndex = 8; + label3.Text = "Сумма:"; + // + // textBoxSum + // + textBoxSum.BackColor = SystemColors.Control; + textBoxSum.Enabled = false; + textBoxSum.Location = new Point(88, 70); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(250, 23); + textBoxSum.TabIndex = 7; + // + // buttonCancel + // + buttonCancel.Location = new Point(281, 106); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 23); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(189, 106); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(86, 23); + buttonAdd.TabIndex = 9; + buttonAdd.Text = "Сохранить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonSave_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(379, 141); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(label3); + Controls.Add(textBoxSum); + Controls.Add(label2); + Controls.Add(textBoxCount); + Controls.Add(label1); + Controls.Add(comboBoxFlower); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private ComboBox comboBoxFlower; + private Label label2; + private TextBox textBoxCount; + private Label label3; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormCreateOrder.cs b/FlowerShop/FlowerShop/FormCreateOrder.cs new file mode 100644 index 0000000..80d5516 --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.cs @@ -0,0 +1,111 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IFlowerLogic _logicF; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IFlowerLogic logicF, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicF = logicF; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка цветов для заказа"); + try + { + var _list = _logicF.ReadList(null); + if (_list != null) + { + comboBoxFlower.DisplayMember = "FlowerName"; + comboBoxFlower.ValueMember = "Id"; + comboBoxFlower.DataSource = _list; + comboBoxFlower.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки цветов для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxFlower.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxFlower.SelectedValue); + var flower = _logicF.ReadElement(new FlowerSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (flower?.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 ComboBoxFlower_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxFlower.SelectedValue == null) + { + MessageBox.Show("Выберите цветы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + FlowerId = Convert.ToInt32(comboBoxFlower.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 ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormCreateOrder.resx b/FlowerShop/FlowerShop/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/FormFlower.Designer.cs b/FlowerShop/FlowerShop/FormFlower.Designer.cs new file mode 100644 index 0000000..0fddab2 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlower.Designer.cs @@ -0,0 +1,223 @@ +namespace FlowerShopView +{ + partial class FormFlower + { + /// + /// 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() + { + label2 = new Label(); + textBoxName = new TextBox(); + label1 = new Label(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + buttonCancel = new Button(); + buttonSave = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(17, 15); + label2.Name = "label2"; + label2.Size = new Size(62, 15); + label2.TabIndex = 5; + label2.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(95, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(250, 23); + textBoxName.TabIndex = 4; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(17, 44); + label1.Name = "label1"; + label1.Size = new Size(38, 15); + label1.TabIndex = 7; + label1.Text = "Цена:"; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(95, 41); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(145, 23); + textBoxPrice.TabIndex = 6; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(17, 70); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(653, 320); + groupBox1.TabIndex = 8; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(532, 136); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(103, 28); + buttonRef.TabIndex = 8; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(532, 102); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(103, 28); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(532, 68); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(103, 28); + buttonUpd.TabIndex = 6; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(532, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(103, 28); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(509, 292); + dataGridView.TabIndex = 0; + // + // buttonCancel + // + buttonCancel.Location = new Point(546, 410); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(104, 28); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(436, 410); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(104, 28); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // ColumnId + // + ColumnId.HeaderText = "ColumnId"; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnComponent + // + ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponent.HeaderText = "Компонент"; + ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // FormFlower + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(675, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBox1); + Controls.Add(label1); + Controls.Add(textBoxPrice); + Controls.Add(label2); + Controls.Add(textBoxName); + Name = "FormFlower"; + Text = "Цветы"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label2; + private TextBox textBoxName; + private Label label1; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormFlower.cs b/FlowerShop/FlowerShop/FormFlower.cs new file mode 100644 index 0000000..187200f --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlower.cs @@ -0,0 +1,198 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace FlowerShopView +{ + public partial class FormFlower : Form + { + private readonly ILogger _logger; + private readonly IFlowerLogic _logic; + private int? _id; + private Dictionary _FlowerComponents; + public int Id { set { _id = value; } } + public FormFlower(ILogger logger, IFlowerLogic logic) + { + InitializeComponent(); + dataGridView.AllowUserToAddRows = false; + _logger = logger; + _logic = logic; + _FlowerComponents = new Dictionary(); + } + private void FormFlower_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new FlowerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.FlowerName; + textBoxPrice.Text = view.Price.ToString(); + _FlowerComponents = view.FlowerComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_FlowerComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _FlowerComponents) + { + 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 void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFlowerComponent)); + if (service is FormFlowerComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_FlowerComponents.ContainsKey(form.Id)) + { + _FlowerComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _FlowerComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFlowerComponent)); + if (service is FormFlowerComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _FlowerComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName } - { Count}", form.ComponentModel.ComponentName, form.Count); + _FlowerComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента:{ ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _FlowerComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_FlowerComponents == null || _FlowerComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new FlowerBindingModel + { + Id = _id ?? 0, + FlowerName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + FlowerComponents = _FlowerComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения цветов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _FlowerComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FlowerShop/FlowerShop/FormFlower.resx b/FlowerShop/FlowerShop/FormFlower.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlower.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/FlowerShop/FlowerShop/FormFlowerComponent.Designer.cs b/FlowerShop/FlowerShop/FormFlowerComponent.Designer.cs new file mode 100644 index 0000000..c6d43a0 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowerComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace FlowerShopView +{ + partial class FormFlowerComponent + { + /// + /// 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(); + label1 = new Label(); + label2 = new Label(); + buttonAdd = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(88, 9); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(250, 23); + comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(88, 38); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(250, 23); + textBoxCount.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(10, 12); + label1.Name = "label1"; + label1.Size = new Size(72, 15); + label1.TabIndex = 2; + label1.Text = "Компонент:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(10, 41); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 3; + label2.Text = "Количество:"; + // + // buttonAdd + // + buttonAdd.Location = new Point(154, 80); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(86, 23); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Сохранить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(246, 80); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormFlowerComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(350, 115); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Name = "FormFlowerComponent"; + Text = "Компоненты цветов"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label label1; + private Label label2; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormFlowerComponent.cs b/FlowerShop/FlowerShop/FormFlowerComponent.cs new file mode 100644 index 0000000..d6c306a --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowerComponent.cs @@ -0,0 +1,79 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace FlowerShopView +{ + public partial class FormFlowerComponent : 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 FormFlowerComponent(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/FlowerShop/FlowerShop/FormFlowerComponent.resx b/FlowerShop/FlowerShop/FormFlowerComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowerComponent.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/FlowerShop/FlowerShop/FormFlowers.Designer.cs b/FlowerShop/FlowerShop/FormFlowers.Designer.cs new file mode 100644 index 0000000..6a1c82c --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowers.Designer.cs @@ -0,0 +1,114 @@ +namespace FlowerShopView +{ + partial class FormFlowers + { + /// + /// 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() + { + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRef + // + buttonRef.Location = new Point(283, 126); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(103, 28); + buttonRef.TabIndex = 9; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(283, 92); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(103, 28); + buttonDel.TabIndex = 8; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(283, 58); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(103, 28); + buttonUpd.TabIndex = 7; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(283, 24); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(103, 28); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(240, 426); + dataGridView.TabIndex = 5; + // + // FormFlowers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(407, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormFlowers"; + Text = "FormFlowers"; + Load += FormFlowers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormFlowers.cs b/FlowerShop/FlowerShop/FormFlowers.cs new file mode 100644 index 0000000..fa703b7 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowers.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; + +namespace FlowerShopView +{ + public partial class FormFlowers : Form + { + private readonly ILogger _logger; + private readonly IFlowerLogic _logic; + public FormFlowers(ILogger logger, IFlowerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormFlowers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FlowerComponents"].Visible = false; + dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFlower)); + if (service is FormFlower form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFlower)); + if (service is FormFlower form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление записи"); + try + { + if (!_logic.Delete(new FlowerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления записи"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormFlowers.resx b/FlowerShop/FlowerShop/FormFlowers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FlowerShop/FlowerShop/FormFlowers.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/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs new file mode 100644 index 0000000..f8b0d15 --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -0,0 +1,171 @@ +namespace FlowerShopView +{ + 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + ЦветыToolStripMenuItem = new ToolStripMenuItem(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(964, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // ЦветыToolStripMenuItem + // + ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem"; + ЦветыToolStripMenuItem.Size = new Size(145, 22); + ЦветыToolStripMenuItem.Text = "Цветы"; + ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(145, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(739, 411); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(775, 55); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(158, 32); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(775, 110); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(158, 34); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(775, 168); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(158, 34); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(775, 230); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(158, 34); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(775, 289); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(158, 34); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(964, 450); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Цветочный магазин"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ЦветыToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs new file mode 100644 index 0000000..3b92cbb --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -0,0 +1,144 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShopView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["FlowerId"].Visible = false; + dataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + 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(FormFlowers)); + if (service is FormFlowers form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormMain.resx b/FlowerShop/FlowerShop/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/FlowerShop/FlowerShop/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/FlowerShop/FlowerShop/Program.cs b/FlowerShop/FlowerShop/Program.cs index 4757509..d1c5842 100644 --- a/FlowerShop/FlowerShop/Program.cs +++ b/FlowerShop/FlowerShop/Program.cs @@ -1,9 +1,19 @@ -namespace FlowerShop +using FlowerShopBusinessLogic.BusinessLogics; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.StoragesContracts; +using FlowerShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace FlowerShopView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +21,31 @@ namespace FlowerShop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FlowerShop/FlowerShop/nlog.config b/FlowerShop/FlowerShop/nlog.config new file mode 100644 index 0000000..af70d20 --- /dev/null +++ b/FlowerShop/FlowerShop/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..cebafa7 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,110 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger 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/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/FlowerLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/FlowerLogic.cs new file mode 100644 index 0000000..5f004bb --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/FlowerLogic.cs @@ -0,0 +1,111 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class FlowerLogic : IFlowerLogic + { + private readonly ILogger _logger; + private readonly IFlowerStorage _flowerStorage; + public FlowerLogic(ILogger logger, IFlowerStorage flowerStorage) + { + _logger = logger; + _flowerStorage = flowerStorage; + } + public List? ReadList(FlowerSearchModel? model) + { + _logger.LogInformation("ReadList. FlowerName:{FlowerName}.Id:{Id}", model?.FlowerName, model?.Id); + var list = model == null ? _flowerStorage.GetFullList() : _flowerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public FlowerViewModel? ReadElement(FlowerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FlowerName:{FlowerName}.Id:{ Id}", model.FlowerName, model.Id); + var element = _flowerStorage.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(FlowerBindingModel model) + { + CheckModel(model); + if (_flowerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(FlowerBindingModel model) + { + CheckModel(model); + if (_flowerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(FlowerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_flowerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(FlowerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FlowerName)) + { + throw new ArgumentNullException("Нет названия цветка ", nameof(model.FlowerName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена цветка должна быть больше 0 ", nameof(model.Price)); + } + if (model.FlowerComponents.Count == 0) + { + throw new ArgumentNullException("Цветок должен быть из каких-либо компонентов ", nameof(model.FlowerName)); + } + _logger.LogInformation("Flower. FlowerName:{FlowerName}. Price:{Price}. Id: {Id}", model.FlowerName, model.Price, model.Id); + var element = _flowerStorage.GetElement(new FlowerSearchModel + { + FlowerName = model.FlowerName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Цветок с таким названием уже есть"); + } + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..12c6b6d --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,123 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.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) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выполняется); + } + public bool FinishOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Готов); + } + public bool DeliveryOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выдан); + } + + public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + + model.FlowerId = element.FlowerId; + model.DateCreate = element.DateCreate; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + + if (model.Status != orderStatus - 1) + { + _logger.LogWarning("Status update to " + orderStatus + " operation failed"); + return false; + } + model.Status = orderStatus; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество цветов должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Order. FlowerId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.FlowerId, model.Count, model.Sum, model.Id); + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj new file mode 100644 index 0000000..00938d3 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..917c68f --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/BindingModels/FlowerBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/FlowerBindingModel.cs new file mode 100644 index 0000000..e67112d --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/FlowerBindingModel.cs @@ -0,0 +1,17 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class FlowerBindingModel : IFlowerModel + { + public int Id { get; set; } + public string FlowerName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary FlowerComponents + { + get; + set; + } = new(); + + } +} diff --git a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..2f8b829 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using FlowerShopDataModels.Models; +using FlowerShopDataModels.Enums; + +namespace FlowerShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int FlowerId { 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; } + + } +} diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..1c656c1 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs new file mode 100644 index 0000000..b479b64 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IFlowerLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IFlowerLogic + { + List? ReadList(FlowerSearchModel? model); + FlowerViewModel? ReadElement(FlowerSearchModel model); + bool Create(FlowerBindingModel model); + bool Update(FlowerBindingModel model); + bool Delete(FlowerBindingModel model); + } +} diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..0449bf8 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj new file mode 100644 index 0000000..5192185 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/FlowerShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..37afe02 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/FlowerSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/FlowerSearchModel.cs new file mode 100644 index 0000000..82092c2 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/FlowerSearchModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopContracts.SearchModels +{ + public class FlowerSearchModel + { + public int? Id { get; set; } + public string? FlowerName { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..288271c --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace FlowerShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..37622b9 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs new file mode 100644 index 0000000..53552d3 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IFlowerStorage.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IFlowerStorage + { + List GetFullList(); + List GetFilteredList(FlowerSearchModel model); + FlowerViewModel? GetElement(FlowerSearchModel model); + FlowerViewModel? Insert(FlowerBindingModel model); + FlowerViewModel? Update(FlowerBindingModel model); + FlowerViewModel? Delete(FlowerBindingModel model); + } +} diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..0746eaf --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,17 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.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/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..2d1b5cb --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,16 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/FlowerViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/FlowerViewModel.cs new file mode 100644 index 0000000..fd80e8d --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/FlowerViewModel.cs @@ -0,0 +1,20 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class FlowerViewModel : IFlowerModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string FlowerName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary FlowerComponents + { + get; + set; + } = new(); + + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..5125252 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int FlowerId { get; set; } + [DisplayName("Изделие")] + public string FlowerName { 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; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..2095810 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace FlowerShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj b/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/FlowerShopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/FlowerShop/FlowerShopDataModels/IId.cs b/FlowerShop/FlowerShopDataModels/IId.cs new file mode 100644 index 0000000..91a0f82 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace FlowerShopDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs b/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..d0c5859 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopDataModels/Models/IFlowerModel.cs b/FlowerShop/FlowerShopDataModels/Models/IFlowerModel.cs new file mode 100644 index 0000000..5d76a2e --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IFlowerModel.cs @@ -0,0 +1,10 @@ +namespace FlowerShopDataModels.Models +{ + public interface IFlowerModel : IId + { + string FlowerName { get; } + double Price { get; } + Dictionary FlowerComponents { get; } + } + +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..e01f36b --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,15 @@ +using FlowerShopDataModels.Enums; + +namespace FlowerShopDataModels.Models +{ + public interface IOrderModel : IId + { + int FlowerId { 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/FlowerShop/FlowerShopListImplement/DataListSingleton.cs b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..4871a55 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Flowers { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Flowers = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj b/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj new file mode 100644 index 0000000..ca6fa62 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/FlowerShopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..805978d --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,103 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.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/FlowerShop/FlowerShopListImplement/Implements/FlowerStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/FlowerStorage.cs new file mode 100644 index 0000000..6a6f5c1 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/FlowerStorage.cs @@ -0,0 +1,103 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + public class FlowerStorage : IFlowerStorage + { + private readonly DataListSingleton _source; + public FlowerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var flower in _source.Flowers) + { + result.Add(flower.GetViewModel); + } + return result; + } + public List GetFilteredList(FlowerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.FlowerName)) + { + return result; + } + foreach (var flower in _source.Flowers) + { + if (flower.FlowerName.Contains(model.FlowerName)) + { + result.Add(flower.GetViewModel); + } + } + return result; + } + public FlowerViewModel? GetElement(FlowerSearchModel model) + { + if (string.IsNullOrEmpty(model.FlowerName) && !model.Id.HasValue) + { + return null; + } + foreach (var flower in _source.Flowers) + { + if ((!string.IsNullOrEmpty(model.FlowerName) && + flower.FlowerName == model.FlowerName) || + (model.Id.HasValue && flower.Id == model.Id)) + { + return flower.GetViewModel; + } + } + return null; + } + public FlowerViewModel? Insert(FlowerBindingModel model) + { + model.Id = 1; + foreach (var flower in _source.Flowers) + { + if (model.Id <= flower.Id) + { + model.Id = flower.Id + 1; + } + } + var newFlower = Flower.Create(model); + if (newFlower == null) + { + return null; + } + _source.Flowers.Add(newFlower); + return newFlower.GetViewModel; + } + public FlowerViewModel? Update(FlowerBindingModel model) + { + foreach (var flower in _source.Flowers) + { + if (flower.Id == model.Id) + { + flower.Update(model); + return flower.GetViewModel; + } + } + return null; + } + public FlowerViewModel? Delete(FlowerBindingModel model) + { + for (int i = 0; i < _source.Flowers.Count; ++i) + { + if (_source.Flowers[i].Id == model.Id) + { + var element = _source.Flowers[i]; + _source.Flowers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..03f9418 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,112 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.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(AttachFlowerName(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(AttachFlowerName(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 AttachFlowerName(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 AttachFlowerName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachFlowerName(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 AttachFlowerName(element.GetViewModel); + } + } + return null; + } + private OrderViewModel AttachFlowerName(OrderViewModel model) + { + foreach (var flower in _source.Flowers) + { + if (flower.Id == model.FlowerId) + { + model.FlowerName = flower.FlowerName; + return model; + } + } + return model; + } + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Component.cs b/FlowerShop/FlowerShopListImplement/Models/Component.cs new file mode 100644 index 0000000..f18535d --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Component.cs @@ -0,0 +1,42 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == 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/FlowerShop/FlowerShopListImplement/Models/Flower.cs b/FlowerShop/FlowerShopListImplement/Models/Flower.cs new file mode 100644 index 0000000..722a096 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Flower.cs @@ -0,0 +1,49 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Flower : IFlowerModel + { + public int Id { get; private set; } + public string FlowerName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary FlowerComponents + { + get; + private set; + } = new Dictionary(); + public static Flower? Create(FlowerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Flower() + { + Id = model.Id, + FlowerName = model.FlowerName, + Price = model.Price, + FlowerComponents = model.FlowerComponents + }; + } + public void Update(FlowerBindingModel? model) + { + if (model == null) + { + return; + } + FlowerName = model.FlowerName; + Price = model.Price; + FlowerComponents = model.FlowerComponents; + } + public FlowerViewModel GetViewModel => new() + { + Id = Id, + FlowerName = FlowerName, + Price = Price, + FlowerComponents = FlowerComponents + }; + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs new file mode 100644 index 0000000..6b97d91 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Order.cs @@ -0,0 +1,59 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int FlowerId { get; private set; } + public int Count { get; set; } + public double Sum { get; private set; } + public OrderStatus Status { get; set; } + public DateTime DateCreate { get; set; } + public DateTime? DateImplement { get; set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + FlowerId = model.FlowerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + FlowerId = model.FlowerId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + FlowerId = FlowerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +}