You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.5 KiB
C#

9 months ago
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<ElectronCoupon> _list = null;
List<ElectronCouponItemControl> _controlList = new List<ElectronCouponItemControl>();
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<ElectronCoupon, bool>;
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<ElectronCoupon> coupons)
{
_list = coupons;
this.PageSize = this.Height / 56;
this.TotalPage = (coupons.Count + PageSize - 1) / PageSize;
var result = ListPager();
_controlList = new List<ElectronCouponItemControl>();
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<ElectronCoupon> ListPager()
{
var result = new List<ElectronCoupon>();
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;
}
}
}
}