|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计算总页数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int GetPageCount()
|
|
|
|
|
{
|
|
|
|
|
int pageCount;
|
|
|
|
|
if (allcount % pageSize == 0)//取余为0
|
|
|
|
|
{
|
|
|
|
|
pageCount = allcount / pageSize;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pageCount = (allcount / pageSize) + 1;//不为0,所需页数加1
|
|
|
|
|
}
|
|
|
|
|
return pageCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 翻页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pageSizeparam">一页显示条数</param>
|
|
|
|
|
/// <param name="allCountparam">总条数</param>
|
|
|
|
|
/// <param name="curPageparam">当前页</param>
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 首页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void btnIndex_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (williamPagerEvent != null)
|
|
|
|
|
{
|
|
|
|
|
curPage = 1;
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void btnPre_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (williamPagerEvent != null)
|
|
|
|
|
{
|
|
|
|
|
if (curPage > 1)
|
|
|
|
|
curPage -= 1;
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下一页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void btnNext_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (williamPagerEvent != null)
|
|
|
|
|
{
|
|
|
|
|
if (curPage < GetPageCount())
|
|
|
|
|
curPage += 1;
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最后一页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void btnLast_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (williamPagerEvent != null)
|
|
|
|
|
{
|
|
|
|
|
curPage = GetPageCount();
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 每页记录数Change事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void cbxPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
curPage = 1;
|
|
|
|
|
int.TryParse(cbxPageSize.SelectedItem.ToString(), out pageSize);
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前页文本框回车事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void txtCurentPage_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyChar == (char)Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
int.TryParse(txtCurentPage.Text, out curPage);
|
|
|
|
|
williamPagerEvent(curPage, pageSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|