using DevExpress.XtraEditors; using System; using System.Drawing; using System.Windows.Forms; namespace ZJ_BYD.UserControls { public partial class GridPage : XtraUserControl { private int allcount = 0;//总条数 private int pageSize = 30;//每页显示条数 private int curPage = 1;//当前页 public delegate void GetPageDataEvents(int curPage, int pageSize);//定义委托 public event GetPageDataEvents williamPagerEvent;//定义事件 public GridPage() { InitializeComponent(); } /// /// 计算总页数 /// /// public int GetPageCount() { int pageCount; if (allcount % pageSize == 0)//取余为0 { pageCount = allcount / pageSize; } else { pageCount = (allcount / pageSize) + 1;//不为0,所需页数加1 } return pageCount; } /// /// 翻页 /// /// 一页显示条数 /// 总条数 /// 当前页 public void RefreshPager(int pageSizeparam, int allCountparam, int curPageparam) { this.allcount = allCountparam; this.pageSize = pageSizeparam; this.curPage = curPageparam; this.lblDesc.Font = new Font("宋体", 9, FontStyle.Regular); this.lblDesc.Text = string.Format("(共{0}条记录,每页{1}条,共{2}页)", allcount, pageSize, GetPageCount()); this.txtCurentPage.Text = curPage.ToString(); this.cbxPageSize.Text = pageSize.ToString(); if (curPage == 0) { if (GetPageCount() > 0) { curPage = 1; williamPagerEvent(curPage, pageSize); } } if (curPage > GetPageCount()) { curPage = GetPageCount();//输入页码大于总页数,取最大页数码 williamPagerEvent(curPage, pageSize); } } /// 首页 /// /// /// private void btnIndex_Click(object sender, EventArgs e) { if (williamPagerEvent != null) { curPage = 1; williamPagerEvent(curPage, pageSize); } } /// /// 上一页 /// /// /// private void btnPre_Click(object sender, EventArgs e) { if (williamPagerEvent != null) { if (curPage > 1) curPage -= 1; williamPagerEvent(curPage, pageSize); } } /// /// 下一页 /// /// /// private void btnNext_Click(object sender, EventArgs e) { if (williamPagerEvent != null) { if (curPage < GetPageCount()) curPage += 1; williamPagerEvent(curPage, pageSize); } } /// /// 最后一页 /// /// /// private void btnLast_Click(object sender, EventArgs e) { if (williamPagerEvent != null) { curPage = GetPageCount(); williamPagerEvent(curPage, pageSize); } } /// /// 每页记录数Change事件 /// /// /// private void cbxPageSize_SelectedIndexChanged(object sender, EventArgs e) { curPage = 1; int.TryParse(cbxPageSize.SelectedItem.ToString(), out pageSize); williamPagerEvent(curPage, pageSize); } /// /// 当前页文本框回车事件 /// /// /// private void txtCurentPage_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { int.TryParse(txtCurentPage.Text, out curPage); williamPagerEvent(curPage, pageSize); } } } }