diff --git a/ProjectFlowerShop/FormComponents.Designer.cs b/ProjectFlowerShop/FormComponents.Designer.cs index 72236be..e3fffa7 100644 --- a/ProjectFlowerShop/FormComponents.Designer.cs +++ b/ProjectFlowerShop/FormComponents.Designer.cs @@ -123,7 +123,7 @@ Controls.Add(buttonChange); Controls.Add(buttonAdd); Controls.Add(dataGridView); - Name = "FormComponents"; + //Name = "FormComponents"; Text = "Компоненты"; Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/ProjectFlowerShop/FormCreateOrder.Designer.cs b/ProjectFlowerShop/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..12fc38e --- /dev/null +++ b/ProjectFlowerShop/FormCreateOrder.Designer.cs @@ -0,0 +1,45 @@ +namespace ProjectFlowerShop +{ + 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() + { + SuspendLayout(); + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(517, 193); + Name = "FormCreateOrder"; + Text = "Заказ"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormCreateOrder.cs b/ProjectFlowerShop/FormCreateOrder.cs new file mode 100644 index 0000000..0cd9a8e --- /dev/null +++ b/ProjectFlowerShop/FormCreateOrder.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class FormCreateOrder : Form + { + public FormCreateOrder() + { + InitializeComponent(); + } + } +} diff --git a/ProjectFlowerShop/FormCreateOrder.resx b/ProjectFlowerShop/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectFlowerShop/FormProduct.Designer.cs b/ProjectFlowerShop/FormProduct.Designer.cs new file mode 100644 index 0000000..1d8f653 --- /dev/null +++ b/ProjectFlowerShop/FormProduct.Designer.cs @@ -0,0 +1,242 @@ +namespace ProjectFlowerShop +{ + partial class FormProduct + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponent = new GroupBox(); + buttonRefresh = new Button(); + buttonRemove = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + Save = new Button(); + buttonCancel = new Button(); + Name = new DataGridViewTextBoxColumn(); + Component = new DataGridViewTextBoxColumn(); + idd = new DataGridViewTextBoxColumn(); + Numbers = new DataGridViewTextBoxColumn(); + groupBoxComponent.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(18, 18); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(18, 59); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(45, 20); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена"; + // + // textBoxName + // + textBoxName.Location = new Point(101, 15); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(204, 27); + textBoxName.TabIndex = 2; + textBoxName.TextChanged += textBox1_TextChanged; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(101, 56); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(204, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponent + // + groupBoxComponent.Controls.Add(buttonRefresh); + groupBoxComponent.Controls.Add(buttonRemove); + groupBoxComponent.Controls.Add(buttonChange); + groupBoxComponent.Controls.Add(buttonAdd); + groupBoxComponent.Controls.Add(dataGridView); + groupBoxComponent.Location = new Point(12, 144); + groupBoxComponent.Name = "groupBoxComponent"; + groupBoxComponent.Size = new Size(646, 294); + groupBoxComponent.TabIndex = 4; + groupBoxComponent.TabStop = false; + groupBoxComponent.Text = "Компоненты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(450, 173); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(190, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(450, 122); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(190, 29); + buttonRemove.TabIndex = 3; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonChange + // + buttonChange.Location = new Point(450, 74); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(190, 29); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(450, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(190, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, idd, Numbers }); + dataGridView.Location = new Point(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(432, 262); + dataGridView.TabIndex = 0; + dataGridView.CellContentClick += dataGridView_CellContentClick; + // + // Save + // + Save.Location = new Point(462, 446); + Save.Name = "Save"; + Save.Size = new Size(94, 29); + Save.TabIndex = 5; + Save.Text = "Сохранить"; + Save.UseVisualStyleBackColor = true; + Save.Click += Save_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(564, 446); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // Name + // + Name.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Name.HeaderText = "Компонент"; + Name.MinimumWidth = 6; + Name.Name = "Name"; + // + // Component + // + Component.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + // + // idd + // + idd.HeaderText = "idd"; + idd.MinimumWidth = 6; + idd.Name = "idd"; + idd.Visible = false; + idd.Width = 125; + // + // Numbers + // + Numbers.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Numbers.HeaderText = "Количество"; + Numbers.MinimumWidth = 6; + Numbers.Name = "Numbers"; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(670, 479); + Controls.Add(buttonCancel); + Controls.Add(Save); + Controls.Add(groupBoxComponent); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + // Name = "FormProduct"; + Text = "Изделие"; + Load += FormProduct_Load; + groupBoxComponent.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponent; + private Button buttonRefresh; + private Button buttonRemove; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + private Button Save; + private Button buttonCancel; + // private DataGridViewTextBoxColumn Id; + private DataGridViewTextBoxColumn Name; + private DataGridViewTextBoxColumn Number; + //private DataGridViewTextBoxColumn Id; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn idd; + private DataGridViewTextBoxColumn Numbers; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormProduct.cs b/ProjectFlowerShop/FormProduct.cs new file mode 100644 index 0000000..abc08d3 --- /dev/null +++ b/ProjectFlowerShop/FormProduct.cs @@ -0,0 +1,242 @@ +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class FormProduct : Form + { + private readonly ILogger _logger; + private readonly IFlowerLogic _logic; + private int? _id; + private Dictionary _flowerComponents; + public int Id { set { _id = value; } } + + public FormProduct(ILogger logger, IFlowerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _flowerComponents = new Dictionary(); + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + + } + + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new FlowerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.FlowerName; + textBoxPrice.Text = view.Price.ToString(); + _flowerComponents = view.FlowerComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_flowerComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _flowerComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName}- { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_flowerComponents.ContainsKey(form.Id)) + { + _flowerComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _flowerComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _flowerComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + _flowerComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName}- { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _flowerComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void Save_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_flowerComponents == null || _flowerComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new FlowerBindingModel + { + Id = _id ?? 0, + FlowerName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + FlowerComponents = _flowerComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _flowerComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/ProjectFlowerShop/FormProduct.resx b/ProjectFlowerShop/FormProduct.resx new file mode 100644 index 0000000..2a9bdfc --- /dev/null +++ b/ProjectFlowerShop/FormProduct.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file