Пополнение магазина и проверка на наличие места
This commit is contained in:
parent
1cafb3ef98
commit
5ca5be9585
@ -107,8 +107,13 @@ namespace FurnitureAssembly
|
|||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||||
id);
|
int furnitureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["FurnitureId"].Value);
|
||||||
|
int furnitureCount = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value);
|
||||||
|
if (!_shopLogic.AddFurnituresAtShops(new FurnitureBindingModel { Id = furnitureId }, furnitureCount)) {
|
||||||
|
MessageBox.Show("Магазины переполнены. Пополнение невозможно", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
|
||||||
@ -116,6 +121,11 @@ namespace FurnitureAssembly
|
|||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
|
operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -109,6 +109,10 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет даты открытия магазина", nameof(model.DateOpening));
|
throw new ArgumentNullException("Нет даты открытия магазина", nameof(model.DateOpening));
|
||||||
}
|
}
|
||||||
|
if (model.MaxCount <= 0)
|
||||||
|
{
|
||||||
|
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);
|
_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 });
|
var element = _shopStorage.GetElement(new ShopSearchModel { ShopName = model.ShopName });
|
||||||
if (element != null && element.Id != model.Id)
|
if (element != null && element.Id != model.Id)
|
||||||
@ -126,6 +130,12 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GetCountFreePlaces(model.Id) < count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (shop.Furnitures.ContainsKey(furniture.Id))
|
if (shop.Furnitures.ContainsKey(furniture.Id))
|
||||||
{
|
{
|
||||||
int prev_count = shop.Furnitures[furniture.Id].Item2;
|
int prev_count = shop.Furnitures[furniture.Id].Item2;
|
||||||
@ -137,6 +147,7 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
}
|
}
|
||||||
model.Furnitures = shop.Furnitures;
|
model.Furnitures = shop.Furnitures;
|
||||||
model.DateOpening = shop.DateOpening;
|
model.DateOpening = shop.DateOpening;
|
||||||
|
model.MaxCount = shop.MaxCount;
|
||||||
model.Address = shop.Address;
|
model.Address = shop.Address;
|
||||||
model.ShopName = shop.ShopName;
|
model.ShopName = shop.ShopName;
|
||||||
if (_shopStorage.Update(model) == null)
|
if (_shopStorage.Update(model) == null)
|
||||||
@ -146,5 +157,51 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetCountFreePlaces(int ShopId)
|
||||||
|
{
|
||||||
|
var shop = ReadElement(new ShopSearchModel { Id = ShopId });
|
||||||
|
if (shop == null)
|
||||||
|
return 0;
|
||||||
|
int count = shop.MaxCount;
|
||||||
|
foreach (var f in shop.Furnitures)
|
||||||
|
{
|
||||||
|
count -= f.Value.Item2;
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetCountFreePlaces_All()
|
||||||
|
{
|
||||||
|
return _shopStorage.GetFullList().Select(x => GetCountFreePlaces(x.Id)).Sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddFurnituresAtShops(FurnitureBindingModel furnitureModel, int count)
|
||||||
|
{
|
||||||
|
if (GetCountFreePlaces_All() < count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
int countShop = GetCountFreePlaces(shop.Id);
|
||||||
|
if (countShop >= count)
|
||||||
|
{
|
||||||
|
AddFurniture(new() { Id = shop.Id }, furnitureModel, count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddFurniture(new() { Id = shop.Id }, furnitureModel, countShop);
|
||||||
|
}
|
||||||
|
count -= countShop;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContarcts
|
|||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count);
|
bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count);
|
||||||
|
|
||||||
|
bool AddFurnituresAtShops(FurnitureBindingModel furnitureModel, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user