Добавил поле с заполненностбю магазинов, баг так и не решил
This commit is contained in:
parent
131a107746
commit
d51c8ddcab
@ -192,7 +192,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics
|
|||||||
foreach (var shop in shops)
|
foreach (var shop in shops)
|
||||||
{
|
{
|
||||||
int shopFreeSpace = GetFreeSpace(shop.Id);
|
int shopFreeSpace = GetFreeSpace(shop.Id);
|
||||||
if (shopFreeSpace > 0)
|
if (shopFreeSpace > 0 && count > 0)
|
||||||
{
|
{
|
||||||
int min = Math.Min(count, shopFreeSpace);
|
int min = Math.Min(count, shopFreeSpace);
|
||||||
count -= min;
|
count -= min;
|
||||||
|
@ -12,6 +12,8 @@ namespace SecuritySystemContracts.ViewModels
|
|||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
[DisplayName("Вместимость")]
|
[DisplayName("Вместимость")]
|
||||||
public int MaxSecuresCount { get; set; }
|
public int MaxSecuresCount { get; set; }
|
||||||
|
[DisplayName("Заполненность")]
|
||||||
|
public int UsedSpace { get; set; }
|
||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime OpeningDate { get; set; }
|
public DateTime OpeningDate { get; set; }
|
||||||
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
public Dictionary<int, (ISecureModel, int)> ShopSecures { get; set; } = new();
|
||||||
|
@ -113,10 +113,9 @@ namespace SecuritySystemDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
shop.Update(model);
|
shop.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
if (model.ShopSecures.Count > 0)
|
|
||||||
{
|
shop.UpdateSecures(context, model);
|
||||||
shop.UpdateSecures(context, model);
|
|
||||||
}
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return shop.GetViewModel;
|
return shop.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ using SecuritySystemContracts.ViewModels;
|
|||||||
using SecuritySystemDataModels.Models;
|
using SecuritySystemDataModels.Models;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace SecuritySystemDatabaseImplement.Models
|
namespace SecuritySystemDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -21,14 +20,31 @@ namespace SecuritySystemDatabaseImplement.Models
|
|||||||
[ForeignKey("ShopId")]
|
[ForeignKey("ShopId")]
|
||||||
public virtual List<ShopSecure> Secures { get; set; } = new();
|
public virtual List<ShopSecure> Secures { get; set; } = new();
|
||||||
private Dictionary<int, (ISecureModel, int)>? _shopSecures = null;
|
private Dictionary<int, (ISecureModel, int)>? _shopSecures = null;
|
||||||
|
[NotMapped]
|
||||||
|
private int UsedSpace { get; set; }
|
||||||
|
[NotMapped]
|
||||||
public Dictionary<int, (ISecureModel, int)> ShopSecures
|
public Dictionary<int, (ISecureModel, int)> ShopSecures
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_shopSecures == null)
|
if (_shopSecures == null)
|
||||||
{
|
{
|
||||||
_shopSecures = Secures
|
// TODO
|
||||||
.ToDictionary(shopSecure => shopSecure.SecureId, shopSecure => (shopSecure.Secure as ISecureModel, shopSecure.Count));
|
try
|
||||||
|
{
|
||||||
|
_shopSecures = Secures
|
||||||
|
.ToDictionary(
|
||||||
|
shopSecure => shopSecure.SecureId,
|
||||||
|
shopSecure => (shopSecure.Secure as ISecureModel, shopSecure.Count)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
_shopSecures = new();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
UsedSpace = _shopSecures.Select(x => x.Value.Item2).Sum();
|
||||||
}
|
}
|
||||||
return _shopSecures;
|
return _shopSecures;
|
||||||
}
|
}
|
||||||
@ -63,17 +79,22 @@ namespace SecuritySystemDatabaseImplement.Models
|
|||||||
Address = Address,
|
Address = Address,
|
||||||
OpeningDate = OpeningDate,
|
OpeningDate = OpeningDate,
|
||||||
MaxSecuresCount = MaxSecuresCount,
|
MaxSecuresCount = MaxSecuresCount,
|
||||||
ShopSecures = ShopSecures
|
ShopSecures = ShopSecures,
|
||||||
|
UsedSpace = UsedSpace
|
||||||
|
|
||||||
};
|
};
|
||||||
public void UpdateSecures(SecuritySystemDatabase context, ShopBindingModel model)
|
public void UpdateSecures(SecuritySystemDatabase context, ShopBindingModel model)
|
||||||
{
|
{
|
||||||
var shopSecures = context.ShopSecures.Where(rec => rec.SecureId == model.Id).ToList();
|
// TODO
|
||||||
|
//context.ShopSecures.RemoveRange(context.ShopSecures.ToList());
|
||||||
|
//context.SaveChanges();
|
||||||
|
var shopSecures = context.ShopSecures.Where(shopSecure => shopSecure.SecureId == model.Id).ToList();
|
||||||
if (shopSecures != null && shopSecures.Count > 0)
|
if (shopSecures != null && shopSecures.Count > 0)
|
||||||
{
|
{
|
||||||
// удалили те, которых нет в модели
|
// удалили те, которых нет в модели
|
||||||
context.ShopSecures.RemoveRange(shopSecures.Where(rec => !model.ShopSecures.ContainsKey(rec.SecureId)));
|
context.ShopSecures.RemoveRange(shopSecures.Where(shopSecure => !model.ShopSecures.ContainsKey(shopSecure.SecureId) || shopSecure.Count == 0));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
shopSecures = context.ShopSecures.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
// обновили количество у существующих записей
|
// обновили количество у существующих записей
|
||||||
foreach (var updateSecure in shopSecures)
|
foreach (var updateSecure in shopSecures)
|
||||||
{
|
{
|
||||||
|
@ -34,13 +34,13 @@
|
|||||||
SecuresToolStripMenuItem = new ToolStripMenuItem();
|
SecuresToolStripMenuItem = new ToolStripMenuItem();
|
||||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||||
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
продатьПродукциюToolStripMenuItem = new ToolStripMenuItem();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
buttonCreateOrder = new Button();
|
buttonCreateOrder = new Button();
|
||||||
buttonTakeOrderInWork = new Button();
|
buttonTakeOrderInWork = new Button();
|
||||||
buttonOrderReady = new Button();
|
buttonOrderReady = new Button();
|
||||||
button4 = new Button();
|
button4 = new Button();
|
||||||
buttonRefresh = new Button();
|
buttonRefresh = new Button();
|
||||||
продатьПродукциюToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -65,21 +65,21 @@
|
|||||||
// ComponentsToolStripMenuItem
|
// ComponentsToolStripMenuItem
|
||||||
//
|
//
|
||||||
ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
|
ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
|
||||||
ComponentsToolStripMenuItem.Size = new Size(182, 26);
|
ComponentsToolStripMenuItem.Size = new Size(224, 26);
|
||||||
ComponentsToolStripMenuItem.Text = "Компоненты";
|
ComponentsToolStripMenuItem.Text = "Компоненты";
|
||||||
ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// SecuresToolStripMenuItem
|
// SecuresToolStripMenuItem
|
||||||
//
|
//
|
||||||
SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem";
|
SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem";
|
||||||
SecuresToolStripMenuItem.Size = new Size(182, 26);
|
SecuresToolStripMenuItem.Size = new Size(224, 26);
|
||||||
SecuresToolStripMenuItem.Text = "Изделия";
|
SecuresToolStripMenuItem.Text = "Изделия";
|
||||||
SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click;
|
SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// магазиныToolStripMenuItem
|
// магазиныToolStripMenuItem
|
||||||
//
|
//
|
||||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||||
магазиныToolStripMenuItem.Size = new Size(182, 26);
|
магазиныToolStripMenuItem.Size = new Size(224, 26);
|
||||||
магазиныToolStripMenuItem.Text = "Магазины";
|
магазиныToolStripMenuItem.Text = "Магазины";
|
||||||
магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
|
магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -90,6 +90,13 @@
|
|||||||
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
|
||||||
пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click;
|
пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// продатьПродукциюToolStripMenuItem
|
||||||
|
//
|
||||||
|
продатьПродукциюToolStripMenuItem.Name = "продатьПродукциюToolStripMenuItem";
|
||||||
|
продатьПродукциюToolStripMenuItem.Size = new Size(165, 24);
|
||||||
|
продатьПродукциюToolStripMenuItem.Text = "Продать продукцию";
|
||||||
|
продатьПродукциюToolStripMenuItem.Click += продатьПродукциюToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -159,13 +166,6 @@
|
|||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
buttonRefresh.Click += ButtonRefresh_Click;
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
//
|
//
|
||||||
// продатьПродукциюToolStripMenuItem
|
|
||||||
//
|
|
||||||
продатьПродукциюToolStripMenuItem.Name = "продатьПродукциюToolStripMenuItem";
|
|
||||||
продатьПродукциюToolStripMenuItem.Size = new Size(165, 24);
|
|
||||||
продатьПродукциюToolStripMenuItem.Text = "Продать продукцию";
|
|
||||||
продатьПродукциюToolStripMenuItem.Click += продатьПродукциюToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user