using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using POSV.Entity.Pormotion; using POSV.MessageEvent; namespace POSV.Component { [ToolboxItem(true)] public partial class CouponListPanel : AbstractNotifyPanelEx { List _list = null; List _controlList = new List(); public CouponListPanel() { InitializeComponent(); PageNum = 1; MsgEvent.Receive(Constant.MEMBERCOUPON_CHANGE_NOTIFY, CouponChangedEventNotify); } protected void CouponChangedEventNotify(object sender, MsgEventArgs args) { var data = args.Data as Tuple; if(_list != null) { if (_list.Contains(data.Item1)) { foreach(var con in _controlList) { var elec = con.Tag as ElectronCoupon; if (elec.Code == data.Item1.Code) { con.RefreshView(elec); break; } } } } } public void RefreshCoupons(List coupons) { _list = coupons; this.PageSize = this.Height / 56; this.TotalPage = (coupons.Count + PageSize - 1) / PageSize; var result = ListPager(); _controlList = new List(); this.Controls.Clear(); for(int i =0; i < result.Count; i++) { ElectronCouponItemControl item = new ElectronCouponItemControl(); item.Width = this.Width - 3; item.RefreshView(result[i]); item.Tag = result[i]; item.ButtonClick += (o, args) => { this.OnButtonClick(args); }; if (i == 0) { item.Location = new Point(0, 0); } else { var lastItem = _controlList[i - 1]; item.Location = new Point(0, lastItem.Location.Y + lastItem.Height + 1); } _controlList.Add(item); this.Controls.Add(item); } this.Invalidate(); } private List ListPager() { var result = new List(); if(_list != null) { result.AddRange(_list.Skip(PageSize * (PageNum - 1)).Take(PageSize)); } return result; } private int PageSize; private int PageNum; private int TotalPage; public void PageUp() { if(this.PageNum > 1) { this.PageNum--; RefreshCoupons(_list); } else { this.PageNum = 1; } } public void PageDown() { if(this.PageNum < TotalPage) { this.PageNum++; RefreshCoupons(_list); } else { this.PageNum = TotalPage; } } } }