Browse Source

29.10.2022

master
vsa 3 years ago
parent
commit
aa3678e967
  1. 11
      Shop/Shop/Form1.cs
  2. 42
      Shop/Shop/Model/CShelf.cs
  3. 30
      Shop/Shop/Model/CShop.cs
  4. BIN
      Shop/Документ1.vsdx

11
Shop/Shop/Form1.cs

@ -43,14 +43,19 @@ namespace ShopWin
private void h_initShop() private void h_initShop()
{ {
_shop = new CShop("Shop1"); _shop = new CShop("Shop1");
_shop.ShelfList.Add(new CShelf("1")); _shop.ShelfList.Add(new CShelf("1", h_OnBreak));
_shop.ShelfList.Add(new CShelf("2")); _shop.ShelfList.Add(new CShelf("2", h_OnBreak));
_shop.FillTest(3); _shop.FillTest(3);
} }
private void h_OnBreak(CShelf pShelf)
{
//
}
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
{ {
_shop.Tick(); // _shop.Tick();
h_RefreshShop(); h_RefreshShop();
} }
} }

42
Shop/Shop/Model/CShelf.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
namespace ShopWin.Model namespace ShopWin.Model
@ -21,11 +22,41 @@ namespace ShopWin.Model
/// </summary> /// </summary>
public List<CProduct> ProductList; public List<CProduct> ProductList;
public CShelf(string number) private Action<CShelf> _OnBreak;
private bool m_isBroken;
/// <summary>
/// Свойство сломано ли
/// </summary>
public bool IsBroken
{
get { return m_isBroken; }
set
{
if (m_isBroken == value) return;
if (m_isBroken) return;
m_isBroken = value;
if (m_isBroken) {
if (_OnBreak != null) {
_OnBreak(this);
}
}
}
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="number"></param>
/// <param name="fnOnBreak"></param>
public CShelf(string number, Action<CShelf> fnOnBreak = null )
{ {
Number = number; Number = number;
MaxWeight = 1000; MaxWeight = 1000;
ProductList = new List<CProduct>(); ProductList = new List<CProduct>();
_OnBreak = fnOnBreak;
} }
public void FillTest(int iCount) public void FillTest(int iCount)
@ -43,9 +74,16 @@ namespace ShopWin.Model
iSumWeight += ProductList[ii].Weight; iSumWeight += ProductList[ii].Weight;
} }
IsBroken = iSumWeight > MaxWeight;
return iSumWeight > MaxWeight; return iSumWeight > MaxWeight;
} }
public void RemoveProduct()
{
if (ProductList.Count > 0) {
ProductList.RemoveAt(0);
}
}
} }
} }

30
Shop/Shop/Model/CShop.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
namespace ShopWin.Model namespace ShopWin.Model
{ {
@ -9,20 +10,43 @@ namespace ShopWin.Model
public class CShop public class CShop
{ {
private Random _random = new Random(); private Random _random = new Random();
private System.Threading.Timer _timer;
public string Title = ""; public string Title = "";
public List<CShelf> ShelfList = new List<CShelf>(); public List<CShelf> ShelfList = new List<CShelf>();
public CShop(string title) public CShop(string title)
{ {
Title = title; Title = title;
_timer = new Timer(h_tick, null,
new TimeSpan(0, 0, 0, 0, 1000),
new TimeSpan(0, 0, 0, 0, 1000)
);
}
private void h_tick(object state)
{
this.Tick();
} }
public void Tick() public void Tick()
{
h_ShelfBroke();
h_GoodsSold();
}
private void h_ShelfBroke()
{
for (int ii = 0; ii < ShelfList.Count; ii++) {
ShelfList[ii].CheckBrokenState();
}
}
private void h_GoodsSold()
{ {
if (_random.Next(0, 10) == 1) { if (_random.Next(0, 10) == 1) {
if (ShelfList[0].ProductList.Count > 0) { ShelfList[0].RemoveProduct();
ShelfList[0].ProductList.RemoveAt(0);
}
} }
} }

BIN
Shop/Документ1.vsdx

Binary file not shown.
Loading…
Cancel
Save