From d910cc89422c366673008bb00b63c5b66855889f Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 17 May 2024 01:03:22 +0400 Subject: [PATCH] done --- .gitignore | 2 + .../FormAddFurniture.Designer.cs | 151 ++++++++++++ .../FurnitureAssembly/FormAddFurniture.cs | 128 ++++++++++ .../FurnitureAssembly/FormAddFurniture.resx | 60 +++++ .../FurnitureAssembly/FormMain.Designer.cs | 232 +++++++++--------- .../FurnitureAssembly/FormMain.cs | 23 +- .../FurnitureAssembly/FormMain.resx | 62 ++++- .../FurnitureAssembly/FormShop.Designer.cs | 211 ++++++++++++++++ .../FurnitureAssembly/FormShop.cs | 133 ++++++++++ .../FurnitureAssembly/FormShop.resx | 120 +++++++++ .../FurnitureAssembly/FormShops.Designer.cs | 120 +++++++++ .../FurnitureAssembly/FormShops.cs | 118 +++++++++ .../FurnitureAssembly/FormShops.resx | 120 +++++++++ .../FurnitureAssembly/Program.cs | 5 + .../ShopLogic.cs | 202 +++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 ++ .../BusinessLogicsContracts/IShopLogic.cs | 27 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 26 ++ .../ViewModels/ShopViewModel.cs | 22 ++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 121 +++++++++ .../Models/Shop.cs | 61 +++++ 24 files changed, 1883 insertions(+), 112 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddFurniture.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddFurniture.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddFurniture.resx create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShop.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShop.resx create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShops.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShops.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormShops.resx create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs diff --git a/.gitignore b/.gitignore index 77e6200..27bb145 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ #mac file .DS_Store +ImplementationExtensions/ +/ImplementationExtensions/ # User-specific files *.rsuser diff --git a/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.Designer.cs new file mode 100644 index 0000000..104793d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.Designer.cs @@ -0,0 +1,151 @@ +namespace FurnitureAssemblyView +{ + partial class FormAddFurniture + { + /// + /// 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.labelFurniture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelShop = new System.Windows.Forms.Label(); + this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // labelFurniture + // + this.labelFurniture.AutoSize = true; + this.labelFurniture.Location = new System.Drawing.Point(28, 58); + this.labelFurniture.Name = "labelFurniture"; + this.labelFurniture.Size = new System.Drawing.Size(56, 15); + this.labelFurniture.TabIndex = 0; + this.labelFurniture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(28, 91); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(28, 23); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(57, 15); + this.labelShop.TabIndex = 2; + this.labelShop.Text = "Магазин:"; + // + // comboBoxFurniture + // + this.comboBoxFurniture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFurniture.FormattingEnabled = true; + this.comboBoxFurniture.Location = new System.Drawing.Point(149, 55); + this.comboBoxFurniture.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxFurniture.Name = "comboBoxFurniture"; + this.comboBoxFurniture.Size = new System.Drawing.Size(230, 23); + this.comboBoxFurniture.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(149, 88); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(209, 123); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + 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(297, 123); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(149, 23); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(230, 23); + this.comboBoxShop.TabIndex = 8; + // + // FormAddFurniture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 159); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxFurniture); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelFurniture); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormAddFurniture"; + this.Text = "Пополнение магазина"; + this.Load += new System.EventHandler(this.FormAddFurniture_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFurniture; + private Label labelCount; + private Label labelShop; + private ComboBox comboBoxFurniture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxShop; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.cs b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.cs new file mode 100644 index 0000000..7ff52b0 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.cs @@ -0,0 +1,128 @@ +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using Microsoft.Extensions.Logging; +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 FurnitureAssemblyView +{ + public partial class FormAddFurniture : Form + { + private readonly ILogger _logger; + private readonly IFurnitureLogic _logicI; + private readonly IShopLogic _logicS; + + public FormAddFurniture(ILogger logger, IFurnitureLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormAddFurniture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для пополнения"); + + try + { + var list = _logicI.ReadList(null); + + if (list != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = list; + comboBoxFurniture.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка списка магазинов для пополнения"); + try + { + var list = _logicS.ReadList(null); + + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Пополнение магазина"); + + try + { + var operationResult = _logicS.AddFurniture(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + + _logicI.ReadElement(new FurnitureSearchModel() + { + Id = Convert.ToInt32(comboBoxFurniture.SelectedValue) + })!, Convert.ToInt32(textBoxCount.Text)); + + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.resx b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddFurniture.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/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index 7ceebba..368489a 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -28,149 +28,159 @@ /// private void InitializeComponent() { - this.menuStrip1 = 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(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + заготовкиToolStripMenuItem = new ToolStripMenuItem(); + мебельToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ButtonCreateOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + ButtonOrderReady = new Button(); + ButtonIssuedOrder = new Button(); + ButtonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // menuStrip1 // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1631, 40); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + menuStrip1.ImageScalingSize = new Size(32, 32); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1631, 42); + menuStrip1.TabIndex = 0; + menuStrip1.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(184, 36); - this.справочникиToolStripMenuItem.Text = "Справочники"; + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, магазиныToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(184, 38); + справочникиToolStripMenuItem.Text = "Справочники"; // // заготовкиToolStripMenuItem // - this.заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; - this.заготовкиToolStripMenuItem.Size = new System.Drawing.Size(258, 44); - this.заготовкиToolStripMenuItem.Text = "Заготовки"; - this.заготовкиToolStripMenuItem.Click += new System.EventHandler(this.ЗаготовкиToolStripMenuItem_Click); + заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; + заготовкиToolStripMenuItem.Size = new Size(395, 44); + заготовкиToolStripMenuItem.Text = "Заготовки"; + заготовкиToolStripMenuItem.Click += ЗаготовкиToolStripMenuItem_Click; // // мебельToolStripMenuItem // - this.мебельToolStripMenuItem.Name = "мебельToolStripMenuItem"; - this.мебельToolStripMenuItem.Size = new System.Drawing.Size(258, 44); - this.мебельToolStripMenuItem.Text = "Мебель"; - this.мебельToolStripMenuItem.Click += new System.EventHandler(this.МебельToolStripMenuItem_Click); + мебельToolStripMenuItem.Name = "мебельToolStripMenuItem"; + мебельToolStripMenuItem.Size = new Size(395, 44); + мебельToolStripMenuItem.Text = "Мебель"; + мебельToolStripMenuItem.Click += МебельToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(395, 44); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(395, 44); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click; // // dataGridView // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 65); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersVisible = false; - this.dataGridView.RowHeadersWidth = 82; - this.dataGridView.RowTemplate.Height = 41; - this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(1237, 528); - this.dataGridView.TabIndex = 1; + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 65); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 82; + dataGridView.RowTemplate.Height = 41; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(1237, 528); + dataGridView.TabIndex = 1; // // ButtonCreateOrder // - this.ButtonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonCreateOrder.Location = new System.Drawing.Point(1266, 65); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(334, 46); - this.ButtonCreateOrder.TabIndex = 2; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonCreateOrder.Location = new Point(1266, 65); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(334, 46); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; // // ButtonTakeOrderInWork // - this.ButtonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(1266, 119); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(334, 46); - this.ButtonTakeOrderInWork.TabIndex = 3; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonTakeOrderInWork.Location = new Point(1266, 119); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(334, 46); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // ButtonOrderReady // - this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonOrderReady.Location = new System.Drawing.Point(1266, 196); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(334, 46); - this.ButtonOrderReady.TabIndex = 4; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonOrderReady.Location = new Point(1266, 196); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(334, 46); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; // // ButtonIssuedOrder // - this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonIssuedOrder.Location = new System.Drawing.Point(1266, 252); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(334, 46); - this.ButtonIssuedOrder.TabIndex = 5; - this.ButtonIssuedOrder.Text = "Заказ выдан"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonIssuedOrder.Location = new Point(1266, 252); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(334, 46); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; // // ButtonRef // - this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonRef.Location = new System.Drawing.Point(1266, 336); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(334, 46); - this.ButtonRef.TabIndex = 6; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(1266, 336); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(334, 46); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1631, 594); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "Сборка мебели"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1631, 594); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Сборка мебели"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -185,5 +195,7 @@ private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 0d5c3ee..812cd0a 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -97,7 +97,7 @@ namespace FurnitureAssemblyView try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{Id = id}); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { @@ -177,5 +177,26 @@ namespace FurnitureAssemblyView { LoadData(); } + + private void пополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddFurniture)); + + if (service is FormAddFurniture form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.resx b/FurnitureAssembly/FurnitureAssembly/FormMain.resx index 938108a..a0623c8 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.resx +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs new file mode 100644 index 0000000..12e9715 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs @@ -0,0 +1,211 @@ +namespace FurnitureAssemblyView +{ + partial class FormShop + { + /// + /// 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(); + labelAddress = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + groupBoxIceCreams = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ColumnFurnitureName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelDate = new Label(); + dateTimePickerDate = new DateTimePicker(); + groupBoxIceCreams.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(33, 21); + labelName.Margin = new Padding(6, 0, 6, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(125, 32); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(48, 66); + labelAddress.Margin = new Padding(6, 0, 6, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(85, 32); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес:"; + // + // textBoxName + // + textBoxName.Location = new Point(252, 14); + textBoxName.Margin = new Padding(6, 4, 6, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(557, 39); + textBoxName.TabIndex = 2; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(252, 66); + textBoxAddress.Margin = new Padding(6, 4, 6, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(557, 39); + textBoxAddress.TabIndex = 3; + // + // groupBoxIceCreams + // + groupBoxIceCreams.Controls.Add(dataGridView); + groupBoxIceCreams.Location = new Point(15, 172); + groupBoxIceCreams.Margin = new Padding(6, 4, 6, 4); + groupBoxIceCreams.Name = "groupBoxIceCreams"; + groupBoxIceCreams.Padding = new Padding(6, 4, 6, 4); + groupBoxIceCreams.Size = new Size(794, 439); + groupBoxIceCreams.TabIndex = 4; + groupBoxIceCreams.TabStop = false; + groupBoxIceCreams.Text = "Изделия"; + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnFurnitureName, ColumnCount }); + dataGridView.Location = new Point(9, 43); + dataGridView.Margin = new Padding(6, 4, 6, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(763, 388); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "ID"; + ID.MinimumWidth = 10; + ID.Name = "ID"; + ID.Visible = false; + // + // ColumnFurnitureName + // + ColumnFurnitureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnFurnitureName.HeaderText = "Изделие"; + ColumnFurnitureName.MinimumWidth = 6; + ColumnFurnitureName.Name = "ColumnFurnitureName"; + ColumnFurnitureName.Resizable = DataGridViewTriState.True; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Location = new Point(288, 619); + buttonSave.Margin = new Padding(6, 4, 6, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(231, 49); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(556, 619); + buttonCancel.Margin = new Padding(6, 4, 6, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(231, 46); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(15, 109); + labelDate.Margin = new Padding(6, 0, 6, 0); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(180, 32); + labelDate.TabIndex = 7; + labelDate.Text = "Дата открытия:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(497, 115); + dateTimePickerDate.Margin = new Padding(6); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(312, 39); + dateTimePickerDate.TabIndex = 9; + // + // FormShop + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(834, 681); + Controls.Add(dateTimePickerDate); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelDate); + Controls.Add(groupBoxIceCreams); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelAddress); + Controls.Add(labelName); + Margin = new Padding(6, 4, 6, 4); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxIceCreams.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private TextBox textBoxName; + private TextBox textBoxAddress; + private GroupBox groupBoxIceCreams; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label labelDate; + private DateTimePicker dateTimePickerDate; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnFurnitureName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.cs new file mode 100644 index 0000000..56c0e97 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.cs @@ -0,0 +1,133 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyListImplement.Models; +using Microsoft.Extensions.Logging; +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 FurnitureAssemblyView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopFurnitures; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopFurnitures = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePickerDate.Value = view.DateOpen; + _shopFurnitures = view.Furnitures ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_shopFurnitures != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopFurnitures) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.FurnitureName, element.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий в магазине"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePickerDate.Value.Date, + Furnitures = _shopFurnitures + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.resx b/FurnitureAssembly/FurnitureAssembly/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.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/FurnitureAssembly/FurnitureAssembly/FormShops.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormShops.Designer.cs new file mode 100644 index 0000000..0d1d087 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace FurnitureAssemblyView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(19, 19); + dataGridView.Margin = new Padding(6, 4, 6, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(825, 683); + dataGridView.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.Location = new Point(864, 51); + buttonAdd.Margin = new Padding(6, 4, 6, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(247, 55); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(864, 114); + buttonUpdate.Margin = new Padding(6, 4, 6, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(247, 50); + buttonUpdate.TabIndex = 3; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(864, 172); + buttonDelete.Margin = new Padding(6, 4, 6, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(247, 50); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(864, 233); + buttonRefresh.Margin = new Padding(6, 4, 6, 4); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(247, 49); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1133, 721); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(6, 4, 6, 4); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormShops.cs b/FurnitureAssembly/FurnitureAssembly/FormShops.cs new file mode 100644 index 0000000..f780b27 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.cs @@ -0,0 +1,118 @@ +using FurnitureAssembly; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +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 FurnitureAssemblyView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_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["Furnitures"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormShops.resx b/FurnitureAssembly/FurnitureAssembly/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.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/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 9e4462b..6b3b765 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -40,10 +40,12 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -52,6 +54,9 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..4b2f7bb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs @@ -0,0 +1,202 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + // Конструктор + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + // Вывод конкретного магазина + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + // Вывод отфильтрованного списка компонентов + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + + // list хранит весь список в случае, если model пришло со значением null на вход метода + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + // Пополнение магазина + public bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddFurniture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var shop = _shopStorage.GetElement(model); + + if (shop == null) + { + _logger.LogWarning("Add Furniture operation failed"); + + return false; + } + + if (!shop.Furnitures.ContainsKey(furniture.Id)) + { + shop.Furnitures[furniture.Id] = (furniture, count); + } + else + { + shop.Furnitures[furniture.Id] = (furniture, shop.Furnitures[furniture.Id].Item2 + count); + } + + _shopStorage.Update(new ShopBindingModel() + { + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + Furnitures = shop.Furnitures + }); + + return true; + } + + // Создание магазина + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + // Обновление магазина + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + // Удаление магазина + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + // Проверка входного аргумента для методов Insert, Update и Delete + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // При удалении передаём как параметр false + if (!withParams) + { + return; + } + + // Проверка на наличие названия магазина + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Отсутствует названия магазина", nameof(model.ShopName)); + } + + // Проверка на наличие адреса у магазина + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address)); + } + + _logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + + // Проверка на наличие такого же магазина в списке + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + + // Если элемент найден и его Id не совпадает с Id переданного объекта + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..991b72b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public string ShopName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } = DateTime.Now; + public Dictionary Furnitures { get; set; } = new(); + public int Id { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..b59c1d7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,27 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..254f7ab --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..562aea6 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,26 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..c8a9a6c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class ShopViewModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + public Dictionary Furnitures { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..efb17e1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary Furnitures { get; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs index 9ff6029..2e1e133 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Formats.Asn1.AsnWriter; namespace FurnitureAssemblyListImplement { @@ -13,12 +14,14 @@ namespace FurnitureAssemblyListImplement public List Workpieces { get; set; } public List Orders { get; set; } public List Furnitures { get; set; } + public List Shops { get; set; } private DataListSingleton() { Workpieces = new List(); Orders = new List(); Furnitures = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..1e6729e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -0,0 +1,121 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + + return null; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + + return result; + } + public List GetFullList() + { + var result = new List(); + + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + + return result; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + + var newShop = Shop.Create(model); + + if (newShop == null) + { + return null; + } + + _source.Shops.Add(newShop); + + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + + return shop.GetViewModel; + } + } + + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs new file mode 100644 index 0000000..ae46cf6 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs @@ -0,0 +1,61 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Models +{ + public class Shop : IShopModel + { + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpen { get; private set; } + + public int Id { get; private set; } + + public Dictionary Furnitures { get; private set; } = + new Dictionary(); + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Furnitures = model.Furnitures + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + Furnitures = model.Furnitures; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + Furnitures = Furnitures + }; + } +}