diff --git a/Shop/Shop/Form1.cs b/Shop/Shop/Form1.cs index dfbe3fb..a0199ba 100644 --- a/Shop/Shop/Form1.cs +++ b/Shop/Shop/Form1.cs @@ -43,14 +43,19 @@ namespace ShopWin private void h_initShop() { _shop = new CShop("Shop1"); - _shop.ShelfList.Add(new CShelf("1")); - _shop.ShelfList.Add(new CShelf("2")); + _shop.ShelfList.Add(new CShelf("1", h_OnBreak)); + _shop.ShelfList.Add(new CShelf("2", h_OnBreak)); _shop.FillTest(3); } + private void h_OnBreak(CShelf pShelf) + { + // + } + private void timer1_Tick(object sender, EventArgs e) { - _shop.Tick(); + // _shop.Tick(); h_RefreshShop(); } } diff --git a/Shop/Shop/Model/CShelf.cs b/Shop/Shop/Model/CShelf.cs index 98ccc28..892b5ec 100644 --- a/Shop/Shop/Model/CShelf.cs +++ b/Shop/Shop/Model/CShelf.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading; namespace ShopWin.Model @@ -21,11 +22,41 @@ namespace ShopWin.Model /// public List ProductList; - public CShelf(string number) + private Action _OnBreak; + + private bool m_isBroken; + /// + /// Свойство сломано ли + /// + 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); + } + } + } + } + + + /// + /// Конструктор + /// + /// + /// + public CShelf(string number, Action fnOnBreak = null ) { Number = number; MaxWeight = 1000; ProductList = new List(); + _OnBreak = fnOnBreak; } public void FillTest(int iCount) @@ -43,9 +74,16 @@ namespace ShopWin.Model iSumWeight += ProductList[ii].Weight; } + IsBroken = iSumWeight > MaxWeight; return iSumWeight > MaxWeight; } + public void RemoveProduct() + { + if (ProductList.Count > 0) { + ProductList.RemoveAt(0); + } + } } } diff --git a/Shop/Shop/Model/CShop.cs b/Shop/Shop/Model/CShop.cs index 2243aaa..0548b8d 100644 --- a/Shop/Shop/Model/CShop.cs +++ b/Shop/Shop/Model/CShop.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; namespace ShopWin.Model { @@ -9,20 +10,43 @@ namespace ShopWin.Model public class CShop { private Random _random = new Random(); + private System.Threading.Timer _timer; + + public string Title = ""; public List ShelfList = new List(); public CShop(string 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() + { + 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 (ShelfList[0].ProductList.Count > 0) { - ShelfList[0].ProductList.RemoveAt(0); - } + ShelfList[0].RemoveProduct(); } } diff --git a/Shop/Документ1.vsdx b/Shop/Документ1.vsdx new file mode 100644 index 0000000..26f1f53 Binary files /dev/null and b/Shop/Документ1.vsdx differ