天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
6.1 KiB

#region 版权信息
/*---------------------------------------------------------------------*
// 项目 名称:《Winform分页控件》
// 文 件 名: Pager.cs
// 描 述: 分页控件
// 作 者:kwon yan
*----------------------------------------------------------------------*/
#endregion
using System;
using System.Configuration;
using System.Windows.Forms;
using QMFrameWork.Data;
namespace QMAPP.WinForm.Controls
{
/**/
/// <summary>
/// 申明委托
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
public delegate DataPage EventPagingHandler(EventPagingArg e);
/**/
/// <summary>
/// 分页控件呈现
/// </summary>
public partial class Pager : UserControl
{
public Pager()
{
InitializeComponent();
dataPage.PageIndex = 1;
dataPage.PageSize = 50;
}
public void Init()
{
this.DataPage = new DataPage();
this.DataPage.PageIndex = 1;
this.DataPage.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
}
public void Init(int pageSize)
{
this.DataPage = new DataPage();
this.DataPage.PageIndex = 1;
this.DataPage.PageSize = pageSize ;
}
public event EventPagingHandler EventPaging;
//定义分页参数
private DataPage dataPage = new DataPage();
public DataPage DataPage
{
get {
dataPage.Result = null;
if (dataPage.PageIndex <= 0)
{
dataPage.PageIndex = 1;
}
return dataPage;
}
set { dataPage = value;
Show();
}
}
//定义查询条件
private object oSearch;
public object OSearch
{
get { return oSearch; }
set { oSearch = value; }
}
/**/
/// <summary>
/// 翻页控件数据绑定的方法 关键是这步,都是调用这里
/// </summary>
public void Bind()
{
if (this.EventPaging != null)
{
this.DataPage = this.EventPaging(new EventPagingArg(this.dataPage));
}
}
private void Show()
{
if (this.dataPage.PageIndex > this.dataPage.PageCount)
{
this.dataPage.PageIndex = this.dataPage.PageCount;
}
if (this.dataPage.PageCount == 1)
{
this.dataPage.PageIndex = 1;
}
lblcurentpage.Text = dataPage.PageIndex.ToString();
lblRecordCount.Text = "共有 " + dataPage.RecordCount.ToString() + " 条记录";
lblPageCount.Text = " / " + dataPage.PageCount.ToString();
lblPageCount1.Text = "每页 " + dataPage.PageSize.ToString() + " 条,共 " + dataPage.PageCount.ToString() + " 页";
btnPrev.Enabled = true;
btnFirst.Enabled = true;
btnLast.Enabled = true;
btnNext.Enabled = true;
if (this.dataPage.PageIndex == 1)
{
this.btnPrev.Enabled = false;
this.btnFirst.Enabled = false;
}
if (this.dataPage.PageIndex == this.dataPage.PageCount)
{
this.btnLast.Enabled = false;
this.btnNext.Enabled = false;
}
if (this.dataPage.RecordCount == 0)
{
btnNext.Enabled = false;
btnLast.Enabled = false;
btnFirst.Enabled = false;
btnPrev.Enabled = false;
}
cmbPagecount.Items.Clear();
for (int i = 1; i <= dataPage.PageCount; i++)
cmbPagecount.Items.Add(i.ToString());
cmbPagecount.SelectedIndex = dataPage.PageIndex - 1;
}
/// <summary>
/// 首页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFirst_Click(object sender, EventArgs e)
{
dataPage.PageIndex = 1;
this.Bind();
}
//上一页
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPrev_Click(object sender, EventArgs e)
{
dataPage.PageIndex -= 1;
if (dataPage.PageIndex <= 0)
{
dataPage.PageIndex = 1;
}
this.Bind();
}
/// <summary>
/// 下一页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnNext_Click(object sender, EventArgs e)
{
this.dataPage.PageIndex += 1;
if (dataPage.PageIndex > dataPage.PageCount)
{
dataPage.PageIndex = dataPage.PageCount;
}
this.Bind();
}
/// <summary>
/// 最后页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLast_Click(object sender, EventArgs e)
{
dataPage.PageIndex = dataPage.PageCount;
this.Bind();
}
/// <summary>
/// 转到新页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void btnGo_Click(object sender, EventArgs e)
{
int pageSelect = 0;
if (Int32.TryParse(cmbPagecount.SelectedItem.ToString(), out pageSelect))
{
dataPage.PageIndex = pageSelect;
this.Bind();
}
}
}
/**/
/// <summary>
/// 自定义事件数据基类
/// </summary>
public class EventPagingArg : EventArgs
{
private DataPage _dataPage;
public EventPagingArg(DataPage DataPage)
{
_dataPage = DataPage;
}
}
}