Допилил прверку при продаже изделий
This commit is contained in:
parent
7075168afa
commit
e1fb7b9ccb
@ -14,5 +14,6 @@ namespace SecuritySystemContracts.StoragesContracts
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellSecures(ISecureModel secureModel, int securesCount);
|
||||
bool CanSellSecures(ISecureModel secureModel, int securesCount);
|
||||
}
|
||||
}
|
||||
|
@ -78,32 +78,28 @@ namespace SecuritySystemFileImplement.Implements
|
||||
|
||||
public bool SellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
var car = source.Secures.FirstOrDefault(x => x.Id == secureModel.Id);
|
||||
var secure = source.Secures.FirstOrDefault(x => x.Id == secureModel.Id);
|
||||
|
||||
if (car == null)
|
||||
if (secure == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == secure.Id));
|
||||
|
||||
var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == car.Id));
|
||||
|
||||
int countStore = 0;
|
||||
|
||||
foreach (var it in shopSecures)
|
||||
countStore += it.Value.Item2;
|
||||
|
||||
if (securesCount > countStore)
|
||||
if (!CanSellSecures(secureModel, securesCount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
var cars = shop.ShopSecures;
|
||||
var secures = shop.ShopSecures;
|
||||
|
||||
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
|
||||
foreach (var c in secures.Where(x => x.Value.Item1.Id == secure.Id))
|
||||
{
|
||||
int min = Math.Min(c.Value.Item2, securesCount);
|
||||
cars[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||
secures[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||
securesCount -= min;
|
||||
|
||||
if (securesCount <= 0)
|
||||
@ -117,7 +113,7 @@ namespace SecuritySystemFileImplement.Implements
|
||||
Address = shop.Address,
|
||||
MaxSecuresCount = shop.MaxSecuresCount,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
ShopSecures = cars
|
||||
ShopSecures = secures
|
||||
});
|
||||
|
||||
source.SaveShops();
|
||||
@ -128,5 +124,18 @@ namespace SecuritySystemFileImplement.Implements
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private int GetSecuresCount(ISecureModel secureModel)
|
||||
{
|
||||
var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == secureModel.Id));
|
||||
// посчитаем количество изделий во всех магазинах
|
||||
return shopSecures.Select(x => x.Value.Item2).Sum();
|
||||
}
|
||||
|
||||
public bool CanSellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
return GetSecuresCount(secureModel) >= securesCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,5 +123,10 @@ namespace SecuritySystemListImplement.Implements
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CanSellSecures(ISecureModel secureModel, int securesCount)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,13 @@
|
||||
SecuresToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||
продатьИзделияToolStripMenuItem = new ToolStripMenuItem();
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
button4 = new Button();
|
||||
buttonRefresh = new Button();
|
||||
продатьИзделияToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -90,6 +90,13 @@
|
||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||
пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click;
|
||||
//
|
||||
// продатьИзделияToolStripMenuItem
|
||||
//
|
||||
продатьИзделияToolStripMenuItem.Name = "продатьИзделияToolStripMenuItem";
|
||||
продатьИзделияToolStripMenuItem.Size = new Size(143, 24);
|
||||
продатьИзделияToolStripMenuItem.Text = "Продать изделие";
|
||||
продатьИзделияToolStripMenuItem.Click += продатьИзделияToolStripMenuItem_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
@ -159,12 +166,6 @@
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// продатьИзделияToolStripMenuItem
|
||||
//
|
||||
продатьИзделияToolStripMenuItem.Name = "продатьИзделияToolStripMenuItem";
|
||||
продатьИзделияToolStripMenuItem.Size = new Size(143, 24);
|
||||
продатьИзделияToolStripMenuItem.Text = "Продать изделие";
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemView.Shop;
|
||||
|
||||
namespace SecuritySystemView
|
||||
{
|
||||
@ -154,5 +155,14 @@ namespace SecuritySystemView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void продатьИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using SecuritySystemBusinessLogic.BusinessLogics;
|
||||
using SecuritySystemContracts.BusinessLogicsContracts;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemFileImplement.Implements;
|
||||
using SecuritySystemView.Shop;
|
||||
|
||||
namespace SecuritySystemView
|
||||
{
|
||||
@ -51,6 +52,7 @@ namespace SecuritySystemView
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShopSupply>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user