using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Data;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid;
|
using Gs.DevApp.ToolBox;
|
|
namespace UserControls.Data
|
{
|
public partial class PageBar : UserControl
|
{
|
public delegate void GetPageDataEvents(int curPage, int pageSize);//定义委托
|
public event GetPageDataEvents williamPagerEvent;//定义事件
|
|
public PageBar()
|
{
|
InitializeComponent();
|
// UtilityHelper.SetFont(layoutControl1);
|
}
|
|
#region 定义属性
|
|
|
int _TotalPages;
|
/// <summary>
|
/// 总页数
|
/// </summary>
|
public int TotalPages
|
{
|
get { return _TotalPages; }
|
set
|
{
|
_TotalPages = value;
|
}
|
}
|
|
/// <summary>
|
/// 当前页
|
/// </summary>
|
public int CurrentPage
|
{
|
get; set;
|
}
|
|
/// <summary>
|
/// 每页条数
|
/// </summary>
|
public int RowsCount
|
{
|
get; set;
|
}
|
|
/// <summary>
|
/// 总记录数
|
/// </summary>
|
public int RecordCount
|
{
|
get; set;
|
}
|
#endregion
|
|
//选择每页显示条数
|
private void cbxRowCount_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
RowsCount = Convert.ToInt32(cbxRowCount.Text);
|
CurrentPage = 1;
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
|
//手动输入显示页面编号
|
private void tbxCurrentPage_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
int page = Convert.ToInt32(tbxCurrentPage.Text);
|
if (page < 1)
|
{
|
CurrentPage = 1;
|
}
|
else if (page > TotalPages)
|
{
|
CurrentPage = TotalPages;
|
}
|
else
|
{
|
CurrentPage = page;
|
}
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
}
|
|
|
//点击首页按钮
|
private void lbFirstPage_Click(object sender, EventArgs e)
|
{
|
if (CurrentPage == 1)
|
return;
|
CurrentPage = 1;
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
|
//点击上一页按钮
|
private void lbPrePage_Click(object sender, EventArgs e)
|
{
|
if (CurrentPage == 1)
|
return;
|
if (CurrentPage <= TotalPages)
|
{
|
CurrentPage -= 1;
|
}
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
|
//点击下一页按钮
|
private void lbNextPage_Click(object sender, EventArgs e)
|
{
|
if (CurrentPage == TotalPages)
|
return;
|
if (CurrentPage < TotalPages)
|
{
|
CurrentPage += 1;
|
}
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
|
//末页按钮
|
private void lbEnd_Click(object sender, EventArgs e)
|
{
|
if (CurrentPage == TotalPages)
|
return;
|
CurrentPage = TotalPages;
|
if (williamPagerEvent != null)
|
BtnEvents(sender, e);
|
}
|
|
private void BtnEvents(object sender, EventArgs e)
|
{
|
//setTxt();
|
williamPagerEvent(CurrentPage, RowsCount);
|
}
|
|
public void setTxt()
|
{
|
tbxCurrentPage.Text = CurrentPage.ToString();
|
lbTotalPages.Text = "共 " + TotalPages.ToString() + "页";
|
lbTotalRows.Text = "共 " + RecordCount.ToString() + " 条记录";
|
this.cbxRowCount.Text = this.RowsCount.ToString();
|
if (CurrentPage == 1)
|
lbFirstPage.Enabled = false;
|
else
|
lbFirstPage.Enabled = true;
|
if (CurrentPage == TotalPages)
|
lbEnd.Enabled = false;
|
else
|
lbEnd.Enabled = true;
|
if (CurrentPage == 1)
|
lbPrePage.Enabled = false;
|
else
|
lbPrePage.Enabled = true;
|
if (CurrentPage == TotalPages)
|
lbNextPage.Enabled = false;
|
else
|
lbNextPage.Enabled = true;
|
}
|
}
|
}
|