From 4c61c8bcaf9b79774df1304cfd2adddd9066251c Mon Sep 17 00:00:00 2001 From: Kamil Haliullov Date: Thu, 25 May 2023 23:50:41 +0400 Subject: [PATCH] lab1 --- FlowerShop/FlowerShop/Class1.cs | 7 - FlowerShop/FlowerShop/FormBouquet.Designer.cs | 235 ++++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.cs | 222 +++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.resx | 60 +++++ FlowerShop/FlowerShop/FormBouquetComponent.cs | 82 ++++++ .../FlowerShop/FormBouquetComponent.resx | 60 +++++ .../FlowerShop/FormBouquets.Designer.cs | 122 +++++++++ FlowerShop/FlowerShop/FormBouquets.cs | 111 +++++++++ FlowerShop/FlowerShop/FormBouquets.resx | 60 +++++ FlowerShop/FlowerShop/FormComponent.cs | 86 +++++++ FlowerShop/FlowerShop/FormComponent.resx | 60 +++++ .../FlowerShop/FormComponents.Designer.cs | 122 +++++++++ FlowerShop/FlowerShop/FormComponents.cs | 102 ++++++++ FlowerShop/FlowerShop/FormComponents.resx | 60 +++++ .../FlowerShop/FormCreateOrder.Designer.cs | 153 ++++++++++++ FlowerShop/FlowerShop/FormCreateOrder.cs | 126 ++++++++++ FlowerShop/FlowerShop/FormCreateOrder.resx | 60 +++++ FlowerShop/FlowerShop/FormMain.Designer.cs | 184 ++++++++++++++ FlowerShop/FlowerShop/FormMain.cs | 158 ++++++++++++ FlowerShop/FlowerShop/FormMain.resx | 63 +++++ .../BusinessLogics/BouquetLogic.cs | 127 ++++++++++ .../BusinessLogics/ComponentLogic.cs | 127 ++++++++++ .../BusinessLogics/OrderLogic.cs | 147 +++++++++++ .../FlowerShopBusinessLogic.csproj | 18 ++ .../BindingModels/BouquetBindingModel.cs | 12 + .../BindingModels/ComponentBindingModel.cs | 11 + .../BindingModels/OrderBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IBouquetLogic.cs | 15 ++ .../IComponentLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../FlowerShopContracts.csproj | 13 + .../SearchModels/ComponentSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/ProductSearchModel.cs | 8 + .../StoragesContracts/IBouquetStorage.cs | 16 ++ .../StoragesContracts/IComponentStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../ViewModels/BouquetViewModel.cs | 15 ++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/OrderViewModel.cs | 25 ++ .../FlowerShopDataModels/Enums/OrderStatus.cs | 11 + .../FlowerShopDataModels.csproj | 9 + FlowerShop/FlowerShopDataModels/IId.cs | 7 + .../Models/IBouquetModel.cs | 9 + .../Models/IComponentModel.cs | 8 + .../Models/IOrderModel.cs | 14 ++ .../DataListSingleton.cs | 29 +++ .../FlowerShopListImplement.csproj | 14 ++ .../Implements/BouquetStorage.cs | 119 +++++++++ .../Implements/ComponentStorage.cs | 119 +++++++++ .../Implements/OrderStorage.cs | 127 ++++++++++ .../FlowerShopListImplement/Models/Bouquet.cs | 50 ++++ .../Models/Component.cs | 47 ++++ .../FlowerShopListImplement/Models/Order.cs | 59 +++++ 54 files changed, 3389 insertions(+), 7 deletions(-) delete mode 100644 FlowerShop/FlowerShop/Class1.cs create mode 100644 FlowerShop/FlowerShop/FormBouquet.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormBouquet.cs create mode 100644 FlowerShop/FlowerShop/FormBouquet.resx create mode 100644 FlowerShop/FlowerShop/FormBouquetComponent.cs create mode 100644 FlowerShop/FlowerShop/FormBouquetComponent.resx create mode 100644 FlowerShop/FlowerShop/FormBouquets.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormBouquets.cs create mode 100644 FlowerShop/FlowerShop/FormBouquets.resx 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/FormMain.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormMain.cs create mode 100644 FlowerShop/FlowerShop/FormMain.resx create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs create mode 100644 FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.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/OrderSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs create mode 100644 FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.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/IBouquetModel.cs create mode 100644 FlowerShop/FlowerShopDataModels/Models/IComponentModel.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/BouquetStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Bouquet.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Component.cs create mode 100644 FlowerShop/FlowerShopListImplement/Models/Order.cs diff --git a/FlowerShop/FlowerShop/Class1.cs b/FlowerShop/FlowerShop/Class1.cs deleted file mode 100644 index 123ffc2..0000000 --- a/FlowerShop/FlowerShop/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace FlowerShop -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormBouquet.Designer.cs b/FlowerShop/FlowerShop/FormBouquet.Designer.cs new file mode 100644 index 0000000..a36ea10 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.Designer.cs @@ -0,0 +1,235 @@ +namespace FlowerShop +{ + partial class FormBouquet + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponent = new System.Windows.Forms.GroupBox(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxComponent.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(13, 11); + this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(13, 40); + this.labelPrice.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(73, 15); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(83, 10); + this.textBoxName.Margin = new System.Windows.Forms.Padding(2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(83, 37); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(106, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponent + // + this.groupBoxComponent.Controls.Add(this.buttonUpdate); + this.groupBoxComponent.Controls.Add(this.buttonDelete); + this.groupBoxComponent.Controls.Add(this.buttonChange); + this.groupBoxComponent.Controls.Add(this.buttonAdd); + this.groupBoxComponent.Controls.Add(this.dataGridView); + this.groupBoxComponent.Location = new System.Drawing.Point(10, 65); + this.groupBoxComponent.Margin = new System.Windows.Forms.Padding(2); + this.groupBoxComponent.Name = "groupBoxComponent"; + this.groupBoxComponent.Padding = new System.Windows.Forms.Padding(2); + this.groupBoxComponent.Size = new System.Drawing.Size(534, 198); + this.groupBoxComponent.TabIndex = 4; + this.groupBoxComponent.TabStop = false; + this.groupBoxComponent.Text = "Компоненты"; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(433, 122); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 30); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(433, 88); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 30); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(433, 54); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 30); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(433, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 30); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnComponent, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(18, 18); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(388, 169); + this.dataGridView.TabIndex = 0; + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.MinimumWidth = 8; + this.ColumnComponent.Name = "ColumnComponent"; + this.ColumnComponent.Width = 150; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 8; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 150; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(329, 267); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 25); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(420, 267); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 25); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormBouquet + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(560, 297); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxComponent); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquet"; + this.Text = "Букет"; + this.Load += new System.EventHandler(this.BouquetForm_Load); + this.groupBoxComponent.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponent; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormBouquet.cs b/FlowerShop/FlowerShop/FormBouquet.cs new file mode 100644 index 0000000..199e887 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.cs @@ -0,0 +1,222 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormBouquet : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logic; + private int? _id; + private Dictionary _bouquetComponents; + public int Id { set { _id = value; } } + + public FormBouquet(ILogger logger, IBouquetLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _bouquetComponents = new Dictionary(); + } + + private void BouquetForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Receving bouquet"); + try + { + var view = _logic.ReadElement(new BouquetSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.BouquetName; + textBoxPrice.Text = view.Price.ToString(); + _bouquetComponents = view.BouquetComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquet"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_bouquetComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _bouquetComponents) + { + dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquetComponent)); + if (service is FormBouquetComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_bouquetComponents.ContainsKey(form.Id)) + { + _bouquetComponents[form.Id] = (form.ComponentModel, form.Count); + } + + else + { + _bouquetComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + + LoadData(); + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquetComponent)); + if (service is FormBouquetComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _bouquetComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _bouquetComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _bouquetComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_bouquetComponents == null || _bouquetComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Saving bouquet"); + try + { + var model = new BouquetBindingModel + { + Id = _id ?? 0, + BouquetName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + BouquetComponents = _bouquetComponents + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Error during saving"); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during saving bouquet"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + + foreach (var elem in _bouquetComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FlowerShop/FlowerShop/FormBouquet.resx b/FlowerShop/FlowerShop/FormBouquet.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquet.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormBouquetComponent.cs b/FlowerShop/FlowerShop/FormBouquetComponent.cs new file mode 100644 index 0000000..07dbc61 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.cs @@ -0,0 +1,82 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShop +{ + public partial class FormBouquetComponent : 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 FormBouquetComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormBouquetComponent.resx b/FlowerShop/FlowerShop/FormBouquetComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormBouquets.Designer.cs b/FlowerShop/FlowerShop/FormBouquets.Designer.cs new file mode 100644 index 0000000..eb7fb08 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.Designer.cs @@ -0,0 +1,122 @@ +namespace FlowerShop +{ + partial class FormBouquets + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(321, 293); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(336, 15); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 25); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(336, 44); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 25); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.ChangeButton_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(336, 73); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 25); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.DeleteButton_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(336, 102); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 25); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormBouquets + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 293); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquets"; + this.Text = "Букеты"; + this.Load += new System.EventHandler(this.BouquetsForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormBouquets.cs b/FlowerShop/FlowerShop/FormBouquets.cs new file mode 100644 index 0000000..2dca392 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.cs @@ -0,0 +1,111 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormBouquets : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logic; + + public FormBouquets(ILogger logger, IBouquetLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["BouquetName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["BouquetComponents"].Visible = false; + } + + _logger.LogInformation("Receiving bouquets"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquets"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquet)); + + if (service is FormBouquet form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquet)); + + if (service is FormBouquet form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deleting bouquet"); + + try + { + if (!_logic.Delete(new BouquetBindingModel { Id = id })) + { + throw new Exception("Error during deleting bouquet"); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error deleting bouquet"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void BouquetsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormBouquets.resx b/FlowerShop/FlowerShop/FormBouquets.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquets.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponent.cs b/FlowerShop/FlowerShop/FormComponent.cs new file mode 100644 index 0000000..1f4fea1 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.cs @@ -0,0 +1,86 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormComponent : Form + { + + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Receiving component"); + + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving component"); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Saving component"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Error during saving"); + } + + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponent.resx b/FlowerShop/FlowerShop/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponents.Designer.cs b/FlowerShop/FlowerShop/FormComponents.Designer.cs new file mode 100644 index 0000000..9dfb315 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.Designer.cs @@ -0,0 +1,122 @@ +namespace FlowerShop +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(321, 293); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(336, 15); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(78, 25); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(337, 44); + this.buttonChange.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(78, 25); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(336, 73); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(78, 25); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(336, 102); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(78, 25); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 293); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormComponents.cs b/FlowerShop/FlowerShop/FormComponents.cs new file mode 100644 index 0000000..1bfbe37 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.cs @@ -0,0 +1,102 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Receiving components"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving components"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormComponents.resx b/FlowerShop/FlowerShop/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..b7086bf --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.Designer.cs @@ -0,0 +1,153 @@ +namespace FlowerShop +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxBouquet = new System.Windows.Forms.ComboBox(); + this.labelBouquet = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxBouquet + // + this.comboBoxBouquet.FormattingEnabled = true; + this.comboBoxBouquet.Location = new System.Drawing.Point(80, 8); + this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(2); + this.comboBoxBouquet.Name = "comboBoxBouquet"; + this.comboBoxBouquet.Size = new System.Drawing.Size(176, 23); + this.comboBoxBouquet.TabIndex = 0; + // + // labelBouquet + // + this.labelBouquet.AutoSize = true; + this.labelBouquet.Location = new System.Drawing.Point(8, 13); + this.labelBouquet.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelBouquet.Name = "labelBouquet"; + this.labelBouquet.Size = new System.Drawing.Size(56, 15); + this.labelBouquet.TabIndex = 1; + this.labelBouquet.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(8, 40); + this.labelCount.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(8, 72); + this.labelSum.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 3; + this.labelSum.Text = "Сумма:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(80, 38); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(176, 23); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(80, 69); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(176, 23); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(96, 97); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 25); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(178, 97); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 25); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(281, 124); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelBouquet); + this.Controls.Add(this.comboBoxBouquet); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.OrderForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxBouquet; + private Label labelBouquet; + private Label labelCount; + private Label labelSum; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormCreateOrder.cs b/FlowerShop/FlowerShop/FormCreateOrder.cs new file mode 100644 index 0000000..3b2e1fd --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.cs @@ -0,0 +1,126 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Diagnostics; + +namespace FlowerShop +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IBouquetLogic _logicBouquet; + private readonly IOrderLogic _logicOrder; + + public FormCreateOrder(ILogger logger, IBouquetLogic logicBouquet, IOrderLogic logicOrder) + { + InitializeComponent(); + _logger = logger; + _logicBouquet = logicBouquet; + _logicOrder = logicOrder; + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Receiving bouquets for order"); + + try + { + var list = _logicBouquet.ReadList(null); + if (list != null) + { + comboBoxBouquet.DisplayMember = "BouquetName"; + comboBoxBouquet.ValueMember = "Id"; + comboBoxBouquet.DataSource = list; + comboBoxBouquet.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving bouquets for order"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void OrderForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CalculateSum() + { + if (comboBoxBouquet.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxBouquet.SelectedValue); + var furniture = _logicBouquet.ReadElement(new BouquetSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + + textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString(); + + _logger.LogInformation("Calculating order's sum"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during calculating order's sum"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalculateSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxBouquet.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicOrder.CreateOrder(new OrderBindingModel + { + BouquetId = Convert.ToInt32(comboBoxBouquet.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + + if (!operationResult) + { + throw new Exception("Error during order creation"); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during order creation"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormCreateOrder.resx b/FlowerShop/FlowerShop/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FlowerShop/FlowerShop/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.Designer.cs b/FlowerShop/FlowerShop/FormMain.Designer.cs new file mode 100644 index 0000000..f962aca --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.Designer.cs @@ -0,0 +1,184 @@ +namespace FlowerShop +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonReady = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonToWork = new System.Windows.Forms.Button(); + this.buttonPut = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(891, 99); + this.buttonReady.Margin = new System.Windows.Forms.Padding(2); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(150, 30); + this.buttonReady.TabIndex = 3; + this.buttonReady.Text = "Заказ готов"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(6, 31); + this.dataGridView.Margin = new System.Windows.Forms.Padding(2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(859, 359); + this.dataGridView.TabIndex = 0; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(891, 31); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(2); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(150, 30); + this.buttonCreate.TabIndex = 1; + this.buttonCreate.Text = "Создать заказ"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonToWork + // + this.buttonToWork.Location = new System.Drawing.Point(891, 65); + this.buttonToWork.Margin = new System.Windows.Forms.Padding(2); + this.buttonToWork.Name = "buttonToWork"; + this.buttonToWork.Size = new System.Drawing.Size(150, 30); + this.buttonToWork.TabIndex = 2; + this.buttonToWork.Text = "Отдать на выполнение"; + this.buttonToWork.UseVisualStyleBackColor = true; + this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click); + // + // buttonPut + // + this.buttonPut.Location = new System.Drawing.Point(891, 133); + this.buttonPut.Margin = new System.Windows.Forms.Padding(2); + this.buttonPut.Name = "buttonPut"; + this.buttonPut.Size = new System.Drawing.Size(150, 30); + this.buttonPut.TabIndex = 4; + this.buttonPut.Text = "Заказ выдан"; + this.buttonPut.UseVisualStyleBackColor = true; + this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(891, 167); + this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(150, 30); + this.buttonRefresh.TabIndex = 5; + this.buttonRefresh.Text = "Обновить список"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); + this.menuStrip.Size = new System.Drawing.Size(1071, 24); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 22); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изделияToolStripMenuItem.Text = "Букеты"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1071, 401); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonPut); + this.Controls.Add(this.buttonReady); + this.Controls.Add(this.buttonToWork); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormMain"; + this.Text = "Цветочный магазин"; + this.Load += new System.EventHandler(this.MainForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreate; + private Button buttonToWork; + private Button buttonPut; + private Button buttonRefresh; + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private Button buttonReady; + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/FormMain.cs b/FlowerShop/FlowerShop/FormMain.cs new file mode 100644 index 0000000..63f690d --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -0,0 +1,158 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace FlowerShop +{ + 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 MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["BouquetId"].Visible = false; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during receiving orders"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void bouquetsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormBouquets)); + + if (service is FormBouquets form) + { + form.ShowDialog(); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonToWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Changing status to 'Processing'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Processing'"); + MessageBox.Show("Заказ должен быть в состоянии 'Принят'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Processing'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void buttonReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Changing status to 'Ready'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Ready'"); + MessageBox.Show("Заказ должен быть в состоянии 'Выполняется'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Ready'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void buttonPut_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Changing status to 'Delivered'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + + if (!operationResult) + { + _logger.LogError("Error during changing order's status to 'Delivered'"); + MessageBox.Show("Заказ должен быть в состоянии 'Готов'", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during changing order's status to 'Delivered'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FlowerShop/FlowerShop/FormMain.resx b/FlowerShop/FlowerShop/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs new file mode 100644 index 0000000..ada5b16 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs @@ -0,0 +1,127 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class BouquetLogic : IBouquetLogic + { + private readonly ILogger _logger; + private readonly IBouquetStorage _bouquetStorage; + + public BouquetLogic(ILogger logger, IBouquetStorage bouquetStorage) + { + _logger = logger; + _bouquetStorage = bouquetStorage; + } + + public List? ReadList(BouquetSearchModel? model) + { + _logger.LogInformation("ReadList. BouquetName: {BouquetName}. Id: {Id}", model?.BouquetName, model?.Id); + + var list = model == null ? _bouquetStorage.GetFullList() : _bouquetStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public BouquetViewModel? ReadElement(BouquetSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. BouquetName: {BouquetName}. Id: {Id}", model.BouquetName, model.Id); + + var element = _bouquetStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(BouquetBindingModel model) + { + CheckModel(model); + + if (_bouquetStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(BouquetBindingModel model) + { + CheckModel(model); + + if (_bouquetStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(BouquetBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_bouquetStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(BouquetBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.BouquetName)) + { + throw new ArgumentNullException("Нет названия букета", nameof(model.BouquetName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена букета должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Bouquet. BouquetName: {BouquetName}. Price: {Price}. Id: {Id}", model.BouquetName, model.Price, model.Id); + + var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Букет с таким названием уже есть"); + } + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..6874aae --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,127 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FlowerShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger 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/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..9ef4477 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,147 @@ +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. Id: {Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model, false); + + if (_orderStorage.GetElement(new OrderSearchModel { Id=model.Id })?.Status != OrderStatus.Принят) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Выполняется; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + + if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Готов; + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (order?.Status != OrderStatus.Готов) + { + _logger.LogWarning("Invalid order status"); + return false; + } + + model.Status = OrderStatus.Выдан; + model.DateImplement = order.DateImplement; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + } + + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. BouquetId: {BouquetId}", model.Id, model.Sum, model.BouquetId); + + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким идентификатором уже есть"); + } + } + } +} diff --git a/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj new file mode 100644 index 0000000..a2ee322 --- /dev/null +++ b/FlowerShop/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs new file mode 100644 index 0000000..6db7a88 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/BouquetBindingModel.cs @@ -0,0 +1,12 @@ +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class BouquetBindingModel : IBouquetModel + { + public int Id { get; set; } + public string BouquetName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary BouquetComponents { get; set; } = new(); + } +} \ No newline at end of file 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/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..025d6ca --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; + +namespace FlowerShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int BouquetId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs new file mode 100644 index 0000000..ce69ce4 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IBouquetLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IBouquetLogic + { + List? ReadList(BouquetSearchModel? model); + BouquetViewModel? ReadElement(BouquetSearchModel model); + bool Create(BouquetBindingModel model); + bool Update(BouquetBindingModel model); + bool Delete(BouquetBindingModel model); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..5913315 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using FlowerShopContracts.ViewModels; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; + +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); + } +} \ No newline at end of file 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/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/SearchModels/ProductSearchModel.cs b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs new file mode 100644 index 0000000..75debc3 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/SearchModels/ProductSearchModel.cs @@ -0,0 +1,8 @@ +namespace FlowerShopContracts.SearchModels +{ + public class BouquetSearchModel + { + public int? Id { get; set; } + public string? BouquetName { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs new file mode 100644 index 0000000..3243a87 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IBouquetStorage.cs @@ -0,0 +1,16 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IBouquetStorage + { + List GetFullList(); + List GetFilteredList(BouquetSearchModel model); + BouquetViewModel? GetElement(BouquetSearchModel model); + BouquetViewModel? Insert(BouquetBindingModel model); + BouquetViewModel? Update(BouquetBindingModel model); + BouquetViewModel? Delete(BouquetBindingModel model); + } +} diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..355796c --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +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); + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..c0f34d9 --- /dev/null +++ b/FlowerShop/FlowerShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +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/BouquetViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs new file mode 100644 index 0000000..2a7d6ed --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/BouquetViewModel.cs @@ -0,0 +1,15 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class BouquetViewModel : IBouquetModel + { + public int Id { get; set; } + [DisplayName("Название букета")] + public string BouquetName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary BouquetComponents { get; set; } = new(); + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..3a06a8f --- /dev/null +++ b/FlowerShop/FlowerShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using FlowerShopDataModels.Models; +using System.ComponentModel; + +namespace FlowerShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..5feb9e8 --- /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 BouquetId { get; set; } + [DisplayName("Букет")] + public string BouquetName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..df31dea --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace FlowerShopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} 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..dfec951 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace FlowerShopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs b/FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs new file mode 100644 index 0000000..29b973d --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IBouquetModel.cs @@ -0,0 +1,9 @@ +namespace FlowerShopDataModels.Models +{ + public interface IBouquetModel : IId + { + string BouquetName { get; } + double Price { get; } + Dictionary BouquetComponents { get; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs b/FlowerShop/FlowerShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..05b4348 --- /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; } + } +} diff --git a/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..416bc78 --- /dev/null +++ b/FlowerShop/FlowerShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using FlowerShopDataModels.Enums; + +namespace FlowerShopDataModels.Models +{ + public interface IOrderModel : IId + { + int BouquetId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/FlowerShop/FlowerShopListImplement/DataListSingleton.cs b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..59460c6 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/DataListSingleton.cs @@ -0,0 +1,29 @@ +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Bouquets { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Bouquets = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} \ No newline at end of file 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/BouquetStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs new file mode 100644 index 0000000..37f43f2 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/BouquetStorage.cs @@ -0,0 +1,119 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopListImplement.Models; + +namespace FlowerShopListImplement.Implements +{ + public class BouquetStorage : IBouquetStorage + { + private readonly DataListSingleton _source; + + public BouquetStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var bouquet in _source.Bouquets) + { + result.Add(bouquet.GetViewModel); + } + + return result; + } + + public List GetFilteredList(BouquetSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.BouquetName)) + { + return result; + } + + foreach (var bouquet in _source.Bouquets) + { + if (bouquet.BouquetName.Contains(model.BouquetName)) + { + result.Add(bouquet.GetViewModel); + } + } + + return result; + } + + public BouquetViewModel? GetElement(BouquetSearchModel model) + { + if (string.IsNullOrEmpty(model.BouquetName) && !model.Id.HasValue) + { + return null; + } + + foreach (var bouquet in _source.Bouquets) + { + if ((!string.IsNullOrEmpty(model.BouquetName) && bouquet.BouquetName == model.BouquetName) || (model.Id.HasValue && bouquet.Id == model.Id)) + { + return bouquet.GetViewModel; + } + } + + return null; + } + + public BouquetViewModel? Insert(BouquetBindingModel model) + { + model.Id = 1; + foreach (var bouquet in _source.Bouquets) + { + if (model.Id <= bouquet.Id) + { + model.Id = bouquet.Id + 1; + } + } + + var newBouquet = Bouquet.Create(model); + if (newBouquet == null) + { + return null; + } + + _source.Bouquets.Add(newBouquet); + + return newBouquet.GetViewModel; + } + + public BouquetViewModel? Update(BouquetBindingModel model) + { + foreach (var bouquet in _source.Bouquets) + { + if (bouquet.Id == model.Id) + { + bouquet.Update(model); + return bouquet.GetViewModel; + } + } + + return null; + } + + public BouquetViewModel? Delete(BouquetBindingModel model) + { + for (int i = 0; i < _source.Bouquets.Count; ++i) + { + if (_source.Bouquets[i].Id == model.Id) + { + var element = _source.Bouquets[i]; + _source.Bouquets.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..0006a6c --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,119 @@ +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/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..6c470bb --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,127 @@ +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(AttachBouquetName(order.GetViewModel)); + } + + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (model == null) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachBouquetName(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 AttachBouquetName(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 AttachBouquetName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachBouquetName(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 AttachBouquetName(element.GetViewModel); + } + } + + return null; + } + + private OrderViewModel AttachBouquetName(OrderViewModel model) + { + var bouquet = _source.Bouquets.Find(b => b.Id == model.BouquetId); + model.BouquetName = bouquet is null ? String.Empty : bouquet.BouquetName; + + return model; + } + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs b/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs new file mode 100644 index 0000000..c4fbad1 --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Bouquet.cs @@ -0,0 +1,50 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; + +namespace FlowerShopListImplement.Models +{ + public class Bouquet : IBouquetModel + { + public int Id { get; private set; } + public string BouquetName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary BouquetComponents { get; private set; } = new Dictionary(); + + public static Bouquet? Create(BouquetBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Bouquet() + { + Id = model.Id, + BouquetName = model.BouquetName, + Price = model.Price, + BouquetComponents = model.BouquetComponents + }; + } + + public void Update(BouquetBindingModel? model) + { + if (model == null) + { + return; + } + + BouquetName = model.BouquetName; + Price = model.Price; + BouquetComponents = model.BouquetComponents; + } + + public BouquetViewModel GetViewModel => new() + { + Id = Id, + BouquetName = BouquetName, + Price = Price, + BouquetComponents = BouquetComponents + }; + } +} diff --git a/FlowerShop/FlowerShopListImplement/Models/Component.cs b/FlowerShop/FlowerShopListImplement/Models/Component.cs new file mode 100644 index 0000000..e49ccfa --- /dev/null +++ b/FlowerShop/FlowerShopListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +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/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs new file mode 100644 index 0000000..9bd45ed --- /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 BouquetId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Order() + { + Id = model.Id, + BouquetId = model.BouquetId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + BouquetId = BouquetId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file