Исправления статуса "Готов" и обнуления изделий.

This commit is contained in:
dasha 2023-03-07 21:28:41 +04:00
parent 6447cc832d
commit 1db299c9b1
3 changed files with 33 additions and 35 deletions

View File

@ -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);

View File

@ -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))
continue;
}
if (!AddSushiInShop(new() { Id = shop.Id }, model, temp))
{
_logger.LogWarning("AddSushi operation failed.");
_logger.LogWarning("При добавлении суши в магазины произошла ошибка");
return false;
}
count -= free;
}
else
{
if (!AddSushiInShop(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddSushiInShop operation failed.");
return false;
}
count = 0;
}
count -= temp;
if (count == 0)
{
return true;
}
}
_logger.LogWarning("AddSushi operation failed.");
return false;
return true;
}
public bool SellSushi(ISushiModel model, int count)

View File

@ -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