From d627ca6623c742129224b095823e9f5086eeefc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 12 Feb 2023 23:20:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=E2=84=961=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShop/FlowerShop/FlowerShop.csproj | 12 + FlowerShop/FlowerShop/Form1.Designer.cs | 39 --- FlowerShop/FlowerShop/Form1.cs | 10 - FlowerShop/FlowerShop/Form1.resx | 120 --------- FlowerShop/FlowerShop/FormBouquet.Designer.cs | 235 ++++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.cs | 222 +++++++++++++++++ FlowerShop/FlowerShop/FormBouquet.resx | 60 +++++ .../FormBouquetComponent.Designer.cs | 126 ++++++++++ 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/FormComponent.Designer.cs | 126 ++++++++++ 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 | 184 ++++++++++++++ FlowerShop/FlowerShop/FormMain.resx | 63 +++++ FlowerShop/FlowerShop/Program.cs | 39 ++- .../BusinessLogics/BouquetLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 29 +-- .../BindingModels/OrderBindingModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../FlowerShopDataModels/Enums/OrderStatus.cs | 10 +- .../Implements/OrderStorage.cs | 22 +- .../FlowerShopListImplement/Models/Order.cs | 5 - 33 files changed, 2490 insertions(+), 206 deletions(-) delete mode 100644 FlowerShop/FlowerShop/Form1.Designer.cs delete mode 100644 FlowerShop/FlowerShop/Form1.cs delete mode 100644 FlowerShop/FlowerShop/Form1.resx 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.Designer.cs 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.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.cs create mode 100644 FlowerShop/FlowerShop/FormComponent.resx create mode 100644 FlowerShop/FlowerShop/FormComponents.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.cs create mode 100644 FlowerShop/FlowerShop/FormComponents.resx create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.cs create mode 100644 FlowerShop/FlowerShop/FormCreateOrder.resx create mode 100644 FlowerShop/FlowerShop/FormMain.Designer.cs create mode 100644 FlowerShop/FlowerShop/FormMain.cs create mode 100644 FlowerShop/FlowerShop/FormMain.resx diff --git a/FlowerShop/FlowerShop/FlowerShop.csproj b/FlowerShop/FlowerShop/FlowerShop.csproj index b57c89e..ef0424f 100644 --- a/FlowerShop/FlowerShop/FlowerShop.csproj +++ b/FlowerShop/FlowerShop/FlowerShop.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Form1.Designer.cs b/FlowerShop/FlowerShop/Form1.Designer.cs deleted file mode 100644 index 1b52567..0000000 --- a/FlowerShop/FlowerShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FlowerShop -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Form1.cs b/FlowerShop/FlowerShop/Form1.cs deleted file mode 100644 index d0bd2d4..0000000 --- a/FlowerShop/FlowerShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FlowerShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FlowerShop/FlowerShop/Form1.resx b/FlowerShop/FlowerShop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/FlowerShop/FlowerShop/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/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.Designer.cs b/FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs new file mode 100644 index 0000000..7ef6205 --- /dev/null +++ b/FlowerShop/FlowerShop/FormBouquetComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace FlowerShop +{ + partial class FormBouquetComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(104, 6); + this.comboBoxComponent.Margin = new System.Windows.Forms.Padding(2); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(129, 23); + this.comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(104, 32); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(129, 23); + this.textBoxCount.TabIndex = 1; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(11, 11); + this.labelComponent.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(69, 15); + this.labelComponent.TabIndex = 2; + this.labelComponent.Text = "Компонент"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(11, 34); + 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 = 3; + this.labelCount.Text = "Количество "; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(102, 61); + 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 = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(184, 61); + 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 = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormBouquetComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(273, 97); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormBouquetComponent"; + this.Text = "Компонент букета"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/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.Designer.cs b/FlowerShop/FlowerShop/FormComponent.Designer.cs new file mode 100644 index 0000000..b37a218 --- /dev/null +++ b/FlowerShop/FlowerShop/FormComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace FlowerShop +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(135, 73); + this.buttonSave.Margin = new System.Windows.Forms.Padding(2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(78, 26); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(227, 73); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(78, 26); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(17, 8); + this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(17, 38); + this.labelCost.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(35, 15); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(76, 6); + this.textBoxName.Margin = new System.Windows.Forms.Padding(2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(208, 23); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(76, 35); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(208, 23); + this.textBoxCost.TabIndex = 5; + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(316, 110); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ 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..b175c4a --- /dev/null +++ b/FlowerShop/FlowerShop/FormMain.cs @@ -0,0 +1,184 @@ +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, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + _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, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + _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, + BouquetId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["BouquetId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + _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/FlowerShop/Program.cs b/FlowerShop/FlowerShop/Program.cs index 4757509..d80bfe5 100644 --- a/FlowerShop/FlowerShop/Program.cs +++ b/FlowerShop/FlowerShop/Program.cs @@ -1,17 +1,50 @@ +using FlowerShopContracts.StoragesContracts; +using Microsoft.Extensions.DependencyInjection; +using FlowerShopListImplement.Implements; +using FlowerShopBusinessLogic.BusinessLogics; +using FlowerShopContracts.BusinessLogicsContracts; +using NLog.Extensions.Logging; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + namespace FlowerShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs index 0f4c3fb..ada5b16 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/BouquetLogic.cs @@ -120,7 +120,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics var element = _bouquetStorage.GetElement(new BouquetSearchModel { BouquetName = model.BouquetName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("Букет с таким названием уже есть"); } } } diff --git a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs index d21bffe..4a72073 100644 --- a/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FlowerShop/FlowerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -38,13 +38,13 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model); - if (model.Status != OrderStatus.Unknown) + if (model.Status != OrderStatus.Неизвестен) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Accepted; + model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { @@ -59,17 +59,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Accepted) + if (model.Status != OrderStatus.Принят) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Processing; + model.Status = OrderStatus.Выполняется; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; @@ -78,17 +78,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Processing) + if (model.Status != OrderStatus.Выполняется) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Ready; + model.Status = OrderStatus.Готов; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; @@ -98,17 +98,18 @@ namespace FlowerShopBusinessLogic.BusinessLogics { CheckModel(model, false); - if (model.Status != OrderStatus.Ready) + if (model.Status != OrderStatus.Готов) { _logger.LogWarning("Invalid order status"); return false; } - model.Status = OrderStatus.Delivered; + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; - if (_orderStorage.Insert(model) == null) + if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Insert operation failed"); + _logger.LogWarning("Update operation failed"); } return true; diff --git a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs index 76cfd77..025d6ca 100644 --- a/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs +++ b/FlowerShop/FlowerShopContracts/BindingModels/OrderBindingModel.cs @@ -9,7 +9,7 @@ namespace FlowerShopContracts.BindingModels public int BouquetId { get; set; } public int Count { get; set; } public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Unknown; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } } diff --git a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs index 397a029..5feb9e8 100644 --- a/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs +++ b/FlowerShop/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -16,7 +16,7 @@ namespace FlowerShopContracts.ViewModels [DisplayName("Сумма")] public double Sum { get; set; } [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Unknown; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] diff --git a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs index a93420b..df31dea 100644 --- a/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs +++ b/FlowerShop/FlowerShopDataModels/Enums/OrderStatus.cs @@ -2,10 +2,10 @@ { public enum OrderStatus { - Unknown = -1, - Accepted = 0, - Processing = 1, - Ready = 2, - Delivered = 3 + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 } } diff --git a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs index 90302d3..6c470bb 100644 --- a/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs +++ b/FlowerShop/FlowerShopListImplement/Implements/OrderStorage.cs @@ -21,7 +21,7 @@ namespace FlowerShopListImplement.Implements foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(AttachBouquetName(order.GetViewModel)); } return result; @@ -40,7 +40,7 @@ namespace FlowerShopListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(AttachBouquetName(order.GetViewModel)); } } @@ -56,9 +56,9 @@ namespace FlowerShopListImplement.Implements foreach (var order in _source.Orders) { - if ((model.Id.HasValue && order.Id == model.Id)) + if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return AttachBouquetName(order.GetViewModel); } } @@ -84,7 +84,7 @@ namespace FlowerShopListImplement.Implements _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return AttachBouquetName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -94,7 +94,7 @@ namespace FlowerShopListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return AttachBouquetName(order.GetViewModel); } } @@ -109,11 +109,19 @@ namespace FlowerShopListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + 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/Order.cs b/FlowerShop/FlowerShopListImplement/Models/Order.cs index 55daa06..9bd45ed 100644 --- a/FlowerShop/FlowerShopListImplement/Models/Order.cs +++ b/FlowerShop/FlowerShopListImplement/Models/Order.cs @@ -41,12 +41,7 @@ namespace FlowerShopListImplement.Models return; } - Id = model.Id; - BouquetId = model.BouquetId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; }