From 709214b6cd9999d5d12d501e87f500fd9274f787 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Mar 2023 13:47:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B0=D0=B6=D0=B8=20=D0=B8=D0=B7=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 57 +++++++++ .../FurnitureAssembly/FormMain.Designer.cs | 13 ++ .../FurnitureAssembly/FormMain.cs | 9 ++ .../FurnitureAssembly/FormSell.Designer.cs | 119 ++++++++++++++++++ .../FurnitureAssembly/FormSell.cs | 116 +++++++++++++++++ .../FurnitureAssembly/FormSell.resx | 60 +++++++++ .../FurnitureAssembly/Program.cs | 1 + .../ShopLogic.cs | 5 + .../BusinessLogicsContarcts/IShopLogic.cs | 2 +- .../StoragesContracts/IShopStorage.cs | 4 +- .../Implements/ShopStorage.cs | 5 + 11 files changed, 389 insertions(+), 2 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/FormSell.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormSell.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormSell.resx diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs index 19ff9c8..7b77cdc 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ShopStorage.cs @@ -83,5 +83,62 @@ namespace FurnitureAssemFileImplement.Implements } return null; } + + private int GetCountFurnitureAllShops(FurnitureBindingModel furniture) + { + int count = 0; + foreach (var shop in source.Shops) + { + if (shop.Furnitures.ContainsKey(furniture.Id)) + { + count += shop.Furnitures[furniture.Id].Item2; + } + } + return count; + } + + + public bool Sell(FurnitureBindingModel furniture, int count) + { + if (GetCountFurnitureAllShops(furniture) < count) + { + return false; + } + + + foreach (var shop in source.Shops) + { + if (shop.Furnitures.ContainsKey(furniture.Id)) + { + if (shop.Furnitures[furniture.Id].Item2 > count) + { + shop.Furnitures[furniture.Id] = (shop.Furnitures[furniture.Id].Item1, shop.Furnitures[furniture.Id].Item2 - count); + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + MaxCount = shop.MaxCount, + Furnitures = shop.Furnitures, + Address = shop.Address, + DateOpening = shop.DateOpening, + }); + break; + } + shop.Furnitures[furniture.Id] = (shop.Furnitures[furniture.Id].Item1, 0); + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + MaxCount = shop.MaxCount, + Furnitures = shop.Furnitures, + Address = shop.Address, + DateOpening = shop.DateOpening, + }); + count -= shop.Furnitures[furniture.Id].Item2; + } + } + source.SaveShops(); + return true; + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index f81c725..7d13b88 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonSell = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -152,11 +153,22 @@ this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ReplenishmentToolStripMenuItem_Click); // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(902, 324); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(150, 25); + this.buttonSell.TabIndex = 7; + this.buttonSell.Text = "Продажа мебели"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1065, 450); + this.Controls.Add(this.buttonSell); this.Controls.Add(this.ButtonRef); this.Controls.Add(this.ButtonIssuedOrder); this.Controls.Add(this.ButtonOrderReady); @@ -190,5 +202,6 @@ private ToolStripMenuItem изделияToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private Button buttonSell; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index e1304ee..983b5b3 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -207,5 +207,14 @@ namespace FurnitureAssembly } } } + + private void buttonSell_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSell)); + if (service is FormSell form) + { + form.ShowDialog(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormSell.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormSell.Designer.cs new file mode 100644 index 0000000..90b68eb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormSell.Designer.cs @@ -0,0 +1,119 @@ +namespace FurnitureAssembly +{ + partial class FormSell + { + /// + /// 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.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSell = new System.Windows.Forms.Button(); + this.labelNum = new System.Windows.Forms.Label(); + this.labelFurniture = new System.Windows.Forms.Label(); + this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(135, 84); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(160, 23); + this.textBoxCount.TabIndex = 14; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(332, 142); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(99, 29); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(196, 142); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(99, 29); + this.buttonSell.TabIndex = 12; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // + // labelNum + // + this.labelNum.AutoSize = true; + this.labelNum.Location = new System.Drawing.Point(48, 87); + this.labelNum.Name = "labelNum"; + this.labelNum.Size = new System.Drawing.Size(72, 15); + this.labelNum.TabIndex = 11; + this.labelNum.Text = "Количество"; + // + // labelFurniture + // + this.labelFurniture.AutoSize = true; + this.labelFurniture.Location = new System.Drawing.Point(48, 46); + this.labelFurniture.Name = "labelFurniture"; + this.labelFurniture.Size = new System.Drawing.Size(53, 15); + this.labelFurniture.TabIndex = 10; + this.labelFurniture.Text = "Изделие"; + // + // comboBoxFurniture + // + this.comboBoxFurniture.FormattingEnabled = true; + this.comboBoxFurniture.Location = new System.Drawing.Point(135, 43); + this.comboBoxFurniture.Name = "comboBoxFurniture"; + this.comboBoxFurniture.Size = new System.Drawing.Size(296, 23); + this.comboBoxFurniture.TabIndex = 9; + // + // FormSell + // + 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.buttonSell); + this.Controls.Add(this.labelNum); + this.Controls.Add(this.labelFurniture); + this.Controls.Add(this.comboBoxFurniture); + this.Name = "FormSell"; + this.Text = "Продажа мебели"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSell; + private Label labelNum; + private Label labelFurniture; + private ComboBox comboBoxFurniture; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormSell.cs b/FurnitureAssembly/FurnitureAssembly/FormSell.cs new file mode 100644 index 0000000..7a5fe9f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormSell.cs @@ -0,0 +1,116 @@ +using FurnitureAssemblyBusinessLogic; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +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 FurnitureAssembly +{ + public partial class FormSell : Form + { + private readonly IShopLogic _shopLogic; + private readonly List? _listFurnitures; + + public int Id + { + 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 FormSell(IShopLogic shopLogic, IFurnitureLogic furnitureLogic) + { + InitializeComponent(); + + _shopLogic = shopLogic; + + _listFurnitures = furnitureLogic.ReadList(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 buttonSell_Click(object sender, EventArgs e) + { + if (FurnitureModel == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (Count <= 0) + { + MessageBox.Show("Укажите количество изделия", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (!_shopLogic.Sell(new() { Id = FurnitureModel.Id }, Count)) + { + MessageBox.Show("Не удалось продать изделие " + FurnitureModel.FurnitureName, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + MessageBox.Show("Продажа прошла успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormSell.resx b/FurnitureAssembly/FurnitureAssembly/FormSell.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormSell.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/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index b3c3b98..eb114b8 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -53,6 +53,7 @@ namespace FurnitureAssembly 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 index 34a90e2..1aba06f 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ShopLogic.cs @@ -203,5 +203,10 @@ namespace FurnitureAssemblyBusinessLogic } return true; } + + public bool Sell(FurnitureBindingModel furnitureBindingModel, int count) + { + return _shopStorage.Sell(furnitureBindingModel, count); + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IShopLogic.cs index f9eb114..f2a0151 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IShopLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IShopLogic.cs @@ -17,7 +17,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContarcts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count); - bool AddFurnituresAtShops(FurnitureBindingModel furnitureModel, int count); + bool Sell(FurnitureBindingModel furnitureModel, int count); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs index cc4fa6a..5181245 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -12,6 +12,8 @@ namespace FurnitureAssemblyContracts.StoragesContracts ShopViewModel? GetElement(ShopSearchModel model); ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); - ShopViewModel? Delete(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + + bool Sell(FurnitureBindingModel furnitureBindingModel, int count); } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs index 65e0e2b..cd324d0 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -109,5 +109,10 @@ namespace FurnitureAssemblyListImplement.Implements } return null; } + + public bool Sell(FurnitureBindingModel furnitureBindingModel, int count) + { + throw new NotImplementedException(); + } } }