From 1db299c9b16839e404b1f289ca7744a670e79f36 Mon Sep 17 00:00:00 2001 From: dasha Date: Tue, 7 Mar 2023 21:28:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=D0=B0=20"=D0=93=D0=BE=D1=82=D0=BE=D0=B2"=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D1=83=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormMain.Designer.cs | 32 ++++++++--------- .../BusinessLogics/ShopLogic.cs | 34 +++++++++---------- .../Implements/ShopStorage.cs | 2 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index c92d394..b5be1c6 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -51,7 +51,7 @@ this.справочникиToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(975, 24); + this.menuStrip.Size = new System.Drawing.Size(974, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; // @@ -88,10 +88,10 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(778, 237); + this.buttonUpdate.Location = new System.Drawing.Point(778, 212); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(170, 62); + this.buttonUpdate.Size = new System.Drawing.Size(170, 32); this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -99,10 +99,10 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(778, 171); + this.buttonSetToFinish.Location = new System.Drawing.Point(778, 176); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(170, 62); + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 32); this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; @@ -110,10 +110,10 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(778, 179); + this.buttonSetToDone.Location = new System.Drawing.Point(778, 140); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; - this.buttonSetToDone.Size = new System.Drawing.Size(170, 62); + this.buttonSetToDone.Size = new System.Drawing.Size(170, 32); this.buttonSetToDone.TabIndex = 10; this.buttonSetToDone.Text = "Заказ готов"; this.buttonSetToDone.UseVisualStyleBackColor = true; @@ -124,7 +124,7 @@ this.buttonSetToWork.Location = new System.Drawing.Point(778, 104); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; - this.buttonSetToWork.Size = new System.Drawing.Size(170, 62); + this.buttonSetToWork.Size = new System.Drawing.Size(170, 32); this.buttonSetToWork.TabIndex = 9; this.buttonSetToWork.Text = "Отдать на выполнение"; this.buttonSetToWork.UseVisualStyleBackColor = true; @@ -132,10 +132,10 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(778, 38); + this.buttonCreateOrder.Location = new System.Drawing.Point(778, 68); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(170, 62); + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 32); this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -150,15 +150,15 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(755, 426); + this.dataGridView.Size = new System.Drawing.Size(755, 358); this.dataGridView.TabIndex = 7; // // buttonAddSushiInShop // - this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 302); + this.buttonAddSushiInShop.Location = new System.Drawing.Point(778, 248); this.buttonAddSushiInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonAddSushiInShop.Name = "buttonAddSushiInShop"; - this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 62); + this.buttonAddSushiInShop.Size = new System.Drawing.Size(170, 32); this.buttonAddSushiInShop.TabIndex = 13; this.buttonAddSushiInShop.Text = "Добавить суши в магазин"; this.buttonAddSushiInShop.UseVisualStyleBackColor = true; @@ -166,10 +166,10 @@ // // buttonSellSushi // - this.buttonSellSushi.Location = new System.Drawing.Point(778, 367); + this.buttonSellSushi.Location = new System.Drawing.Point(778, 284); this.buttonSellSushi.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSellSushi.Name = "buttonSellSushi"; - this.buttonSellSushi.Size = new System.Drawing.Size(170, 62); + this.buttonSellSushi.Size = new System.Drawing.Size(170, 32); this.buttonSellSushi.TabIndex = 14; this.buttonSellSushi.Text = "Продать суши"; this.buttonSellSushi.UseVisualStyleBackColor = true; @@ -179,7 +179,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(975, 450); + this.ClientSize = new System.Drawing.Size(974, 382); this.Controls.Add(this.buttonSellSushi); this.Controls.Add(this.buttonAddSushiInShop); this.Controls.Add(this.buttonUpdate); diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs index 16156ed..13761bc 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ShopLogic.cs @@ -171,35 +171,33 @@ namespace SushiBarBusinessLogic.BusinessLogics { throw new ArgumentException("Количество суши должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddSushi. ShopName:{ShopName}. Id:{Id}", model.SushiName, model.Id); + var freePlaces = _shopStorage.GetFullList() + .Select(x => x.MaxCountSushi - x.ListSushi + .Select(p => p.Value.Item2).Sum()).Sum() - count; + if (freePlaces < 0) + { + _logger.LogInformation("AddSushi. Не удалось добавить изделия в магазины, они переполнены."); + return false; + } foreach (var shop in _shopStorage.GetFullList()) { - int free = shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum(); - if (free < count) + var temp = Math.Min(count, shop.MaxCountSushi - shop.ListSushi.Select(x => x.Value.Item2).Sum()); + if (temp <= 0) { - if (!AddSushiInShop(new() { Id = shop.Id }, model, free)) - { - _logger.LogWarning("AddSushi operation failed."); - return false; - } - count -= free; + continue; } - else + if (!AddSushiInShop(new() { Id = shop.Id }, model, temp)) { - if (!AddSushiInShop(new() { Id = shop.Id }, model, count)) - { - _logger.LogWarning("AddSushiInShop operation failed."); - return false; - } - count = 0; + _logger.LogWarning("При добавлении суши в магазины произошла ошибка"); + return false; } + count -= temp; if (count == 0) { return true; } } - _logger.LogWarning("AddSushi operation failed."); - return false; + return true; } public bool SellSushi(ISushiModel model, int count) diff --git a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs index 0e1161f..d8d5302 100644 --- a/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/ShopStorage.cs @@ -90,7 +90,7 @@ namespace SushiBarFileImplement.Implements int countInCurrentShop = shop.ListSushi[model.Id].Item2; if (countInCurrentShop <= count) { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); + shop.ListSushi.Remove(model.Id); count -= countInCurrentShop; } else