From 305b21c03ec0f3ebf3d300fefef84411cffd22cd Mon Sep 17 00:00:00 2001 From: kirinzx Date: Tue, 14 May 2024 12:40:56 +0400 Subject: [PATCH] all done --- .../FurnitureAssembly/ComponentForm.cs | 18 +- .../FurnitureAssembly/ComponentsForm.cs | 3 +- .../FurnitureAssembly/Form1.Designer.cs | 39 ---- FurnitureAssembly/FurnitureAssembly/Form1.cs | 10 - .../FurnitureAssembly/Form1.resx | 120 ------------ .../FormAddToShop.Designer.cs | 142 ++++++++++++++ .../FurnitureAssembly/FormAddToShop.cs | 142 ++++++++++++++ .../FurnitureAssembly/FormAddToShop.resx | 60 ++++++ .../FurnitureAssembly/FormShop.Designer.cs | 181 ++++++++++++++++++ .../FurnitureAssembly/FormShop.cs | 136 +++++++++++++ .../FurnitureAssembly/FormShop.resx | 69 +++++++ .../FurnitureAssembly/FormShops.Designer.cs | 114 +++++++++++ .../FurnitureAssembly/FormShops.cs | 109 +++++++++++ .../FurnitureAssembly/FormShops.resx | 60 ++++++ .../FurnitureAssembly/FurnitureAssembly.sln | 12 +- .../FurnitureAssemblyView.csproj | 1 - .../FurnitureAssembly/FurnitureForm.cs | 5 +- .../FurnituresForm.Designer.cs | 30 +-- .../FurnitureAssembly/FurnituresForm.cs | 1 - .../FurnitureAssembly/MainForm.Designer.cs | 28 ++- .../FurnitureAssembly/MainForm.cs | 57 +++++- .../FurnitureAssembly/OrderForm.cs | 5 +- .../FurnitureAssembly/Program.cs | 5 + .../BusinessLogics/OrderLogic.cs | 57 +++--- .../BusinessLogics/ShopLogic.cs | 150 +++++++++++++++ .../BindingModels/FurnitureBindingModel.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 1 + .../BindingModels/ShopBindingModel.cs | 21 ++ .../BusinessLogicsContracts/IShopLogic.cs | 21 ++ .../FurnitureAssemblyContracts.csproj | 1 - .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 17 ++ .../ViewModels/OrderViewModel.cs | 3 +- .../ViewModels/ShopViewModel.cs | 23 +++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../FurnitureAssemblyListImplement.csproj | 3 +- .../Implements/OrderStorage.cs | 23 +-- .../Implements/ShopStorage.cs | 113 +++++++++++ .../Models/Order.cs | 8 + .../Models/Shop.cs | 61 ++++++ 41 files changed, 1619 insertions(+), 264 deletions(-) delete mode 100644 FurnitureAssembly/FurnitureAssembly/Form1.Designer.cs delete mode 100644 FurnitureAssembly/FurnitureAssembly/Form1.cs delete mode 100644 FurnitureAssembly/FurnitureAssembly/Form1.resx create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddToShop.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddToShop.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormAddToShop.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/BusinessLogics/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/FurnitureAssembly/FurnitureAssembly/ComponentForm.cs b/FurnitureAssembly/FurnitureAssembly/ComponentForm.cs index 368a076..3569ae2 100644 --- a/FurnitureAssembly/FurnitureAssembly/ComponentForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/ComponentForm.cs @@ -24,7 +24,7 @@ namespace FurnitureAssembly { try { - _logger.LogInformation("Получение компонента"); + _logger.LogInformation(" "); var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value @@ -37,8 +37,8 @@ namespace FurnitureAssembly } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -49,10 +49,10 @@ namespace FurnitureAssembly { if (string.IsNullOrEmpty(textBoxName.Text)) { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение компонента"); + _logger.LogInformation(" "); try { var model = new ComponentBindingModel @@ -64,16 +64,16 @@ namespace FurnitureAssembly var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + throw new Exception(" . ."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/FurnitureAssembly/FurnitureAssembly/ComponentsForm.cs b/FurnitureAssembly/FurnitureAssembly/ComponentsForm.cs index 3d1ab9a..23dba84 100644 --- a/FurnitureAssembly/FurnitureAssembly/ComponentsForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/ComponentsForm.cs @@ -38,7 +38,8 @@ namespace FurnitureAssemblyView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка компонентов"); } diff --git a/FurnitureAssembly/FurnitureAssembly/Form1.Designer.cs b/FurnitureAssembly/FurnitureAssembly/Form1.Designer.cs deleted file mode 100644 index 83ebd63..0000000 --- a/FurnitureAssembly/FurnitureAssembly/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FurnitureAssembly -{ - 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/FurnitureAssembly/FurnitureAssembly/Form1.cs b/FurnitureAssembly/FurnitureAssembly/Form1.cs deleted file mode 100644 index c186dd4..0000000 --- a/FurnitureAssembly/FurnitureAssembly/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FurnitureAssembly -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/Form1.resx b/FurnitureAssembly/FurnitureAssembly/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/FurnitureAssembly/FurnitureAssembly/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/FurnitureAssembly/FurnitureAssembly/FormAddToShop.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.Designer.cs new file mode 100644 index 0000000..a805e07 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.Designer.cs @@ -0,0 +1,142 @@ +namespace FurnitureAssembly +{ + partial class FormAddToShop + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); + this.labelFurniture = new System.Windows.Forms.Label(); + this.labelNum = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(133, 18); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(296, 23); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(46, 21); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин"; + // + // comboBoxFurniture + // + this.comboBoxFurniture.FormattingEnabled = true; + this.comboBoxFurniture.Location = new System.Drawing.Point(133, 62); + this.comboBoxFurniture.Name = "comboBoxFurniture"; + this.comboBoxFurniture.Size = new System.Drawing.Size(296, 23); + this.comboBoxFurniture.TabIndex = 2; + // + // labelFurniture + // + this.labelFurniture.AutoSize = true; + this.labelFurniture.Location = new System.Drawing.Point(46, 65); + this.labelFurniture.Name = "labelFurniture"; + this.labelFurniture.Size = new System.Drawing.Size(53, 15); + this.labelFurniture.TabIndex = 4; + this.labelFurniture.Text = "Изделие"; + // + // labelNum + // + this.labelNum.AutoSize = true; + this.labelNum.Location = new System.Drawing.Point(46, 106); + this.labelNum.Name = "labelNum"; + this.labelNum.Size = new System.Drawing.Size(72, 15); + this.labelNum.TabIndex = 5; + this.labelNum.Text = "Количество"; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(194, 161); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(99, 29); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Пополнить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(330, 161); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(99, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(133, 103); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(160, 23); + this.textBoxCount.TabIndex = 8; + // + // FormReplenishmentShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(479, 214); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.labelNum); + this.Controls.Add(this.labelFurniture); + this.Controls.Add(this.comboBoxFurniture); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormReplenishmentShop"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private ComboBox comboBoxFurniture; + private Label labelFurniture; + private Label labelNum; + private Button buttonAdd; + private Button buttonCancel; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormAddToShop.cs b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.cs new file mode 100644 index 0000000..2930d1f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.cs @@ -0,0 +1,142 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using System; +using System.Collections; +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 FurnitureAssembly +{ + public partial class FormAddToShop : Form + { + + private readonly List? _listShops; + private readonly List? _listFurnitures; + + public int Id + { + get + { + return Convert.ToInt32(comboBoxShop.SelectedValue); + } + set + { + comboBoxShop.SelectedValue = value; + } + } + public IShopModel? ShopModel + { + get + { + if (_listShops == null) + { + return null; + } + foreach (var elem in _listShops) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int FurnitureId + { + get + { + return Convert.ToInt32(comboBoxFurniture.SelectedValue); + } + set + { + comboBoxFurniture.SelectedValue = value; + } + } + public IFurnitureModel? FurnitureModel + { + get + { + if (_listFurnitures == null) + { + return null; + } + foreach (var elem in _listFurnitures) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormAddToShop(IShopLogic shopLogic, IfurnitureLogic furnitureLogic) + { + InitializeComponent(); + _listShops = shopLogic.ReadList(null); + _listFurnitures = furnitureLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + if (_listFurnitures != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = _listFurnitures; + comboBoxFurniture.SelectedItem = null; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Укажите количество поступившего изделия", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormAddToShop.resx b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormAddToShop.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/FormShop.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs new file mode 100644 index 0000000..d7dc3a8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.Designer.cs @@ -0,0 +1,181 @@ +namespace FurnitureAssembly +{ + 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() + { + this.labelShopName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelAddress = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.FurnitureId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.FurnitureName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // labelShopName + // + this.labelShopName.AutoSize = true; + this.labelShopName.Location = new System.Drawing.Point(37, 45); + this.labelShopName.Name = "labelShopName"; + this.labelShopName.Size = new System.Drawing.Size(113, 15); + this.labelShopName.TabIndex = 0; + this.labelShopName.Text = "Название магазина"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(168, 42); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(282, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(168, 83); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(282, 23); + this.textBoxAddress.TabIndex = 3; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(37, 86); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 2; + this.labelAddress.Text = "Адрес"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(37, 128); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(87, 15); + this.labelDate.TabIndex = 4; + this.labelDate.Text = "Дата открытия"; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(168, 122); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(282, 23); + this.dateTimePicker.TabIndex = 6; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(382, 490); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(99, 28); + this.ButtonSave.TabIndex = 7; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(509, 490); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(99, 28); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.FurnitureId, + this.FurnitureName, + this.Count}); + this.dataGridView1.Location = new System.Drawing.Point(37, 177); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(571, 289); + this.dataGridView1.TabIndex = 9; + // + // FurnitureId + // + this.FurnitureId.HeaderText = "Id"; + this.FurnitureId.Name = "FurnitureId"; + this.FurnitureId.Visible = false; + // + // FurnitureName + // + this.FurnitureName.HeaderText = "Название"; + this.FurnitureName.Name = "FurnitureName"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(631, 530); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelShopName); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShopName; + private TextBox textBoxName; + private TextBox textBoxAddress; + private Label labelAddress; + private Label labelDate; + private DateTimePicker dateTimePicker; + private Button ButtonSave; + private Button ButtonCancel; + private DataGridView dataGridView1; + private DataGridViewTextBoxColumn FurnitureId; + private DataGridViewTextBoxColumn FurnitureName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.cs b/FurnitureAssembly/FurnitureAssembly/FormShop.cs new file mode 100644 index 0000000..1d10d32 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.cs @@ -0,0 +1,136 @@ +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using FurnitureAssemblyContracts.BusinessLogicsContracts; + +namespace FurnitureAssembly +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private Dictionary _shopFurnitures; + + private int? _id; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopFurnitures = new Dictionary(); + } + + + 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; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату открытия", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + 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(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение магазина"); + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePicker.Value = view.DateOpening; + _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) + { + dataGridView1.Rows.Clear(); + foreach (var pc in _shopFurnitures) + { + dataGridView1.Rows.Add(new object[] { pc.Key, pc.Value.Item1.FurnitureName, pc.Value.Item2 }); + } + + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormShop.resx b/FurnitureAssembly/FurnitureAssembly/FormShop.resx new file mode 100644 index 0000000..565a3a5 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ 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..ee13c0d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace FurnitureAssembly +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(-1, -1); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(559, 453); + this.dataGridView.TabIndex = 6; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(601, 223); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(105, 29); + this.ButtonRef.TabIndex = 13; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(601, 168); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(105, 29); + this.ButtonUpd.TabIndex = 12; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(601, 113); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(105, 29); + this.ButtonDel.TabIndex = 11; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(601, 59); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(105, 29); + this.ButtonAdd.TabIndex = 10; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(743, 451); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonRef; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormShops.cs b/FurnitureAssembly/FurnitureAssembly/FormShops.cs new file mode 100644 index 0000000..35fd60d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.cs @@ -0,0 +1,109 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + + +namespace FurnitureAssembly +{ + 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 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 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 ButtonUpd_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 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 ShopBindingModel{ 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/FurnitureAssembly/FurnitureAssembly/FormShops.resx b/FurnitureAssembly/FurnitureAssembly/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormShops.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/FurnitureAssembly.sln b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.sln index 531b474..bbabb70 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.sln +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.sln @@ -5,14 +5,14 @@ VisualStudioVersion = 17.1.32210.238 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyView", "FurnitureAssemblyView.csproj", "{459EB9DC-7D0D-46FB-825D-A6C9E3DF0C7A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDataModels", "..\AbstractFurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj", "{F93EF9EB-8A34-4174-B763-6881E65986F8}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyContracts", "..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj", "{8E5753AD-9093-4A95-BA85-4A7C382ED5BA}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLogic", "..\FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{BA9BCA19-0C5F-41C8-98ED-7AB8D3DF6CA8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplement", "..\FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj", "{2A965D1B-CA9F-4268-A157-8A7D539FBDD2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDataModels", "..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj", "{2DDAC375-59FB-4E1F-9685-C8839610AB94}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +23,10 @@ Global {459EB9DC-7D0D-46FB-825D-A6C9E3DF0C7A}.Debug|Any CPU.Build.0 = Debug|Any CPU {459EB9DC-7D0D-46FB-825D-A6C9E3DF0C7A}.Release|Any CPU.ActiveCfg = Release|Any CPU {459EB9DC-7D0D-46FB-825D-A6C9E3DF0C7A}.Release|Any CPU.Build.0 = Release|Any CPU + {F93EF9EB-8A34-4174-B763-6881E65986F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F93EF9EB-8A34-4174-B763-6881E65986F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F93EF9EB-8A34-4174-B763-6881E65986F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F93EF9EB-8A34-4174-B763-6881E65986F8}.Release|Any CPU.Build.0 = Release|Any CPU {8E5753AD-9093-4A95-BA85-4A7C382ED5BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8E5753AD-9093-4A95-BA85-4A7C382ED5BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E5753AD-9093-4A95-BA85-4A7C382ED5BA}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -35,10 +39,6 @@ Global {2A965D1B-CA9F-4268-A157-8A7D539FBDD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {2A965D1B-CA9F-4268-A157-8A7D539FBDD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {2A965D1B-CA9F-4268-A157-8A7D539FBDD2}.Release|Any CPU.Build.0 = Release|Any CPU - {2DDAC375-59FB-4E1F-9685-C8839610AB94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2DDAC375-59FB-4E1F-9685-C8839610AB94}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2DDAC375-59FB-4E1F-9685-C8839610AB94}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2DDAC375-59FB-4E1F-9685-C8839610AB94}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj index 122a0d8..6295619 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssemblyView.csproj @@ -17,7 +17,6 @@ - diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureForm.cs b/FurnitureAssembly/FurnitureAssembly/FurnitureForm.cs index a8a1e1c..cbcfbed 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureForm.cs @@ -70,7 +70,7 @@ namespace FurnitureAssemblyView dataGridView.Rows.Clear(); foreach (var pc in _furnitureComponents) { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + dataGridView.Rows.Add(new object[] { pc.Value.Item1.ComponentName, pc.Value.Item2 }); } textBoxPrice.Text = CalcPrice().ToString(); } @@ -116,7 +116,8 @@ namespace FurnitureAssemblyView var service = Program.ServiceProvider?.GetService(typeof(FurnitureComponentForm)); if (service is FurnitureComponentForm form) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; form.Count = _furnitureComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) diff --git a/FurnitureAssembly/FurnitureAssembly/FurnituresForm.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FurnituresForm.Designer.cs index ccad5da..9a2abb4 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnituresForm.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FurnituresForm.Designer.cs @@ -39,18 +39,20 @@ // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.DataGridView.Name = "DataGridView"; this.DataGridView.RowHeadersWidth = 62; this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.Size = new System.Drawing.Size(418, 328); + this.DataGridView.Size = new System.Drawing.Size(597, 547); this.DataGridView.TabIndex = 0; // // AddButton // - this.AddButton.Location = new System.Drawing.Point(430, 7); + this.AddButton.Location = new System.Drawing.Point(615, 12); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.AddButton.Name = "AddButton"; - this.AddButton.Size = new System.Drawing.Size(120, 23); + this.AddButton.Size = new System.Drawing.Size(171, 39); this.AddButton.TabIndex = 1; this.AddButton.Text = "Добавить"; this.AddButton.UseVisualStyleBackColor = true; @@ -58,9 +60,10 @@ // // ChangeButton // - this.ChangeButton.Location = new System.Drawing.Point(430, 66); + this.ChangeButton.Location = new System.Drawing.Point(615, 110); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.ChangeButton.Name = "ChangeButton"; - this.ChangeButton.Size = new System.Drawing.Size(120, 23); + this.ChangeButton.Size = new System.Drawing.Size(171, 39); this.ChangeButton.TabIndex = 2; this.ChangeButton.Text = "Изменить"; this.ChangeButton.UseVisualStyleBackColor = true; @@ -68,9 +71,10 @@ // // DeleteButton // - this.DeleteButton.Location = new System.Drawing.Point(430, 125); + this.DeleteButton.Location = new System.Drawing.Point(615, 209); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.DeleteButton.Name = "DeleteButton"; - this.DeleteButton.Size = new System.Drawing.Size(120, 23); + this.DeleteButton.Size = new System.Drawing.Size(171, 39); this.DeleteButton.TabIndex = 3; this.DeleteButton.Text = "Удалить"; this.DeleteButton.UseVisualStyleBackColor = true; @@ -78,9 +82,10 @@ // // UpdateButton // - this.UpdateButton.Location = new System.Drawing.Point(430, 186); + this.UpdateButton.Location = new System.Drawing.Point(615, 310); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.UpdateButton.Name = "UpdateButton"; - this.UpdateButton.Size = new System.Drawing.Size(120, 23); + this.UpdateButton.Size = new System.Drawing.Size(171, 39); this.UpdateButton.TabIndex = 4; this.UpdateButton.Text = "Обновить"; this.UpdateButton.UseVisualStyleBackColor = true; @@ -88,14 +93,15 @@ // // FurnituresForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(564, 338); + this.ClientSize = new System.Drawing.Size(805, 563); this.Controls.Add(this.UpdateButton); this.Controls.Add(this.DeleteButton); this.Controls.Add(this.ChangeButton); this.Controls.Add(this.AddButton); this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "FurnituresForm"; this.Text = "Изделия"; this.Load += new System.EventHandler(this.FurnituresForm_Load); diff --git a/FurnitureAssembly/FurnitureAssembly/FurnituresForm.cs b/FurnitureAssembly/FurnitureAssembly/FurnituresForm.cs index 946960b..aa4935c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnituresForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/FurnituresForm.cs @@ -114,7 +114,6 @@ namespace FurnitureAssemblyView LoadData(); } - private void FurnituresForm_Load(object sender, EventArgs e) { LoadData(); diff --git a/FurnitureAssembly/FurnitureAssembly/MainForm.Designer.cs b/FurnitureAssembly/FurnitureAssembly/MainForm.Designer.cs index 5daac66..fd97dc8 100644 --- a/FurnitureAssembly/FurnitureAssembly/MainForm.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/MainForm.Designer.cs @@ -38,6 +38,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); buttonReady = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); @@ -107,7 +109,8 @@ // this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.справочникиToolStripMenuItem}); + this.справочникиToolStripMenuItem, + this.пополнениеМагазинаToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1530, 33); @@ -118,7 +121,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -126,17 +130,31 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(218, 34); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); + // + // пополнениеМагазинаToolStripMenuItem + // + this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(210, 29); + this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.AddToShopToolStripMenuItem_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -172,5 +190,7 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/MainForm.cs b/FurnitureAssembly/FurnitureAssembly/MainForm.cs index ec37db9..d06b0dd 100644 --- a/FurnitureAssembly/FurnitureAssembly/MainForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/MainForm.cs @@ -19,13 +19,14 @@ namespace FurnitureAssemblyView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; + private readonly IShopLogic _shopLogic; - public MainForm(ILogger logger, IOrderLogic orderLogic) + public MainForm(ILogger logger, IOrderLogic orderLogic, IShopLogic shopLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; - + _shopLogic = shopLogic; } private void MainForm_Load(object sender, EventArgs e) @@ -94,6 +95,7 @@ namespace FurnitureAssemblyView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, FurnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value), + FurnitureName = dataGridView.SelectedRows[0].Cells["FurnitureName"].Value.ToString(), 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()), @@ -127,6 +129,7 @@ namespace FurnitureAssemblyView { Id = id, FurnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value), + FurnitureName = dataGridView.SelectedRows[0].Cells["FurnitureName"].Value.ToString(), 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()), @@ -160,6 +163,7 @@ namespace FurnitureAssemblyView { Id = id, FurnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value), + FurnitureName = dataGridView.SelectedRows[0].Cells["FurnitureName"].Value.ToString(), 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()), @@ -186,5 +190,54 @@ namespace FurnitureAssemblyView { LoadData(); } + + private void ShopToolStripMenuItem_Click(object sender, EventArgs e) + { + + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void AddToShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddToShop)); + if (service is FormAddToShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ShopModel == null || form.FurnitureModel == null) + { + return; + } + _logger.LogInformation("Добавление в магазин {ShopName} изделия: { FurnitureName}- { Count}", form.ShopModel.ShopName, form.FurnitureModel.FurnitureName, form.Count); + + var modelShop = new ShopBindingModel + { + Id = form.Id, + ShopName = form.ShopModel.ShopName, + Address = form.ShopModel.Address, + DateOpening = form.ShopModel.DateOpening, + }; + + var modelFurn = new FurnitureBindingModel + { + Id = form.FurnitureId, + FurnitureName = form.FurnitureModel.FurnitureName, + Price = form.FurnitureModel.Price, + FurnitureComponents = form.FurnitureModel.FurnitureComponents + }; + + var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count); + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + } + + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/OrderForm.cs b/FurnitureAssembly/FurnitureAssembly/OrderForm.cs index e28de03..787c9e2 100644 --- a/FurnitureAssembly/FurnitureAssembly/OrderForm.cs +++ b/FurnitureAssembly/FurnitureAssembly/OrderForm.cs @@ -35,9 +35,9 @@ namespace FurnitureAssemblyView var list = _logicP.ReadList(null); if (list != null) { - comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.DisplayMember = "Furniture"; comboBoxFurniture.ValueMember = "Id"; - comboBoxFurniture.DataSource = list; + comboBoxFurniture.DataSource = list.Select(c => c.FurnitureName).ToList(); comboBoxFurniture.SelectedItem = null; } @@ -97,6 +97,7 @@ namespace FurnitureAssemblyView var operationResult = _logicO.CreateOrder(new OrderBindingModel { FurnitureId = Convert.ToInt32(comboBoxFurniture.SelectedIndex)+1, + FurnitureName = comboBoxFurniture.SelectedValue.ToString(), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 7656364..6bef587 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -36,9 +36,11 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -46,6 +48,9 @@ namespace FurnitureAssembly services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs index 6d7ea5d..47090f0 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -38,38 +38,14 @@ namespace AbstractShopBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выдан); - } - - public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) - { - var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (viewModel == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (viewModel.Status + 1 != newStatus) - { - _logger.LogWarning("Change status operation failed"); - return false; - } - model.Status = newStatus; - model.FurnitureId = viewModel.FurnitureId; - model.Count = viewModel.Count; - model.Sum = viewModel.Sum; - model.DateCreate = viewModel.DateCreate; - if (model.Status == OrderStatus.Готов) - { - model.DateImplement = DateTime.Now; - } - else - { - model.DateImplement = viewModel.DateImplement; - } - CheckModel(model, false); + CheckModel(model); + if (model.Status != OrderStatus.Готов) return false; + + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) { - _logger.LogWarning("Change status operation failed"); + _logger.LogWarning("Update operation failed"); return false; } return true; @@ -77,7 +53,16 @@ namespace AbstractShopBusinessLogic.BusinessLogics public bool FinishOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Готов); + CheckModel(model); + if (model.Status != OrderStatus.Выполняется) return false; + + model.Status = OrderStatus.Готов; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } public List? ReadList(OrderSearchModel? model) @@ -95,7 +80,15 @@ namespace AbstractShopBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + CheckModel(model); + if (model.Status != OrderStatus.Принят) return false; + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..d380042 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,150 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IFurnitureStorage _furnitureStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, IFurnitureStorage furnitureStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _furnitureStorage = furnitureStorage; + } + 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); + 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 Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + 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)); + } + if (model.DateOpening.Equals(null)) + { + throw new ArgumentNullException("Нет даты открытия магазина", nameof(model.DateOpening)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}. Address:{ Address}. DateOpening:{ DateOpening}. Id: { Id}", model.ShopName, model.Address, model.DateOpening, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel { ShopName = model.ShopName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count) + { + var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.Id }); + var furniture = _furnitureStorage.GetElement(new FurnitureSearchModel { Id = furnitureModel.Id }); + + if (shop == null || furniture == null) + { + return false; + } + if (shop.Furnitures.ContainsKey(furniture.Id)) + { + int prev_count = shop.Furnitures[furniture.Id].Item2; + shop.Furnitures[furniture.Id] = (furniture, prev_count + count); + } + else + { + shop.Furnitures[furniture.Id] = (furniture, count); + } + model.Furnitures = shop.Furnitures; + model.DateOpening = shop.DateOpening; + model.Address = shop.Address; + model.ShopName = shop.ShopName; + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Replenishment operation failed"); + return false; + } + return true; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/FurnitureBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/FurnitureBindingModel.cs index f68be66..2b27044 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/FurnitureBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/FurnitureBindingModel.cs @@ -10,7 +10,7 @@ namespace FurnitureAssemblyContracts.BindingModels public class FurnitureBindingModel : IFurnitureModel { public int Id { get; set; } - public string FurnitureName { get; set; } = string.Empty; + public string FurnitureName { get; set; } //= string.Empty; public double Price { get; set; } public Dictionary FurnitureComponents {get; set;} = new(); } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs index 280e941..fd59c2a 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace FurnitureAssemblyContracts.BindingModels { public int Id { get; set; } public int FurnitureId { get; set; } + public string FurnitureName { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..379850c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,21 @@ +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 int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } + + public Dictionary Furnitures { get; set; } = new(); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..9a3e106 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,21 @@ +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.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(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj index c45b9a0..04f9955 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj +++ b/FurnitureAssembly/FurnitureAssemblyContracts/FurnitureAssemblyContracts.csproj @@ -8,7 +8,6 @@ - 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..1eb24c4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,17 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; + + +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/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index 423ecaf..373cab5 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -13,9 +13,10 @@ namespace FurnitureAssemblyContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int FurnitureId { get; set; } [DisplayName("Изделие")] - public string FurnitureName { get; set; } = string.Empty; + public string FurnitureName { get; set; } //= string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..0a738fc --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,23 @@ +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 : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } + + 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..bd5efbf --- /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 DateOpening { get; } + Dictionary Furnitures { get; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs index 1d358c2..720f3b7 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace FurnitureAssemblyListImplement public List Components { get; set; } public List Orders { get; set; } public List Furnitures { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Furnitures = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj index 00764bc..3481a48 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -9,7 +9,6 @@ - diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs index 1cf2889..7cf8b9f 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs @@ -26,7 +26,7 @@ namespace FurnitureAssemblyListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return GetViewModel(element); + return element.GetViewModel; } } return null; @@ -42,7 +42,7 @@ namespace FurnitureAssemblyListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return GetViewModel(order); + return order.GetViewModel; } } return null; @@ -59,7 +59,7 @@ namespace FurnitureAssemblyListImplement.Implements { if (order.Id == model.Id) { - result.Add(GetViewModel(order)); + result.Add(order.GetViewModel); } } return result; @@ -70,7 +70,7 @@ namespace FurnitureAssemblyListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(GetViewModel(order)); + result.Add(order.GetViewModel); } return result; } @@ -91,7 +91,7 @@ namespace FurnitureAssemblyListImplement.Implements return null; } _source.Orders.Add(newOrder); - return GetViewModel(newOrder); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -106,18 +106,5 @@ namespace FurnitureAssemblyListImplement.Implements } return null; } - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - foreach (var furniture in _source.Furnitures) - { - if (furniture.Id == order.FurnitureId) - { - viewModel.FurnitureName = furniture.FurnitureName; - break; - } - } - return viewModel; - } } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..65e0e2b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -0,0 +1,113 @@ +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 List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + 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 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 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/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index c71017c..fc97784 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -13,6 +13,7 @@ namespace FurnitureAssemblyListImplement.Models public class Order : IOrderModel { public int FurnitureId { get; private set; } + public string FurnitureName { get; private set; } public int Count { get; private set; } @@ -35,6 +36,7 @@ namespace FurnitureAssemblyListImplement.Models { Id = model.Id, FurnitureId = model.FurnitureId, + FurnitureName = model.FurnitureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -48,13 +50,19 @@ namespace FurnitureAssemblyListImplement.Models { return; } + FurnitureId = model.FurnitureId; + FurnitureName = model.FurnitureName; + Count = model.Count; + Sum = model.Sum; Status = model.Status; + DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, FurnitureId = FurnitureId, + FurnitureName = FurnitureName, Count = Count, Sum = Sum, Status = Status, diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs new file mode 100644 index 0000000..daec617 --- /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.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Furnitures { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Furnitures = model.Furnitures + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + Furnitures = model.Furnitures; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + Furnitures = Furnitures + }; + } +}