using DataEntity.Page;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Input;
|
using XCommon.Log;
|
using UserControl = System.Windows.Controls.UserControl;
|
|
namespace XHandler.View.Page
|
{
|
/// <summary>
|
/// 分页组件
|
/// </summary>
|
public partial class PagerToolsControl : UserControl
|
{
|
#region 变量
|
/// <summary>
|
/// 当前页改变时发生
|
/// </summary>
|
public event C_EventClass.OnPagerIndexChangedEventHandler PageCntChanged = null;
|
|
/// <summary>
|
/// 每页行数改变时发生
|
/// </summary>
|
public event C_EventClass.OnPagerNumChangedEventHandler OnePageRowCntChanged = null;
|
|
|
/// <summary>
|
/// 总页数
|
/// </summary>
|
public int Total
|
{
|
get { return nAllPageCnt; }
|
}
|
|
/// <summary>
|
/// 数据总数
|
/// </summary>
|
[Description("数据总数"), Browsable(false)]
|
public int DataCount
|
{
|
get { return nAllDataCount; }
|
set
|
{
|
nAllDataCount = value;
|
nAllPageCnt = ((nAllDataCount + nOnePageRowCnt - 1) / nOnePageRowCnt);
|
tBoxDataCnt.Text = aDataCountLable.Replace("#count", nAllDataCount.ToString());
|
UpdataTotal();
|
}
|
}
|
|
/// <summary>
|
/// 当前页数
|
/// </summary>
|
[Description("当前页"), Browsable(false)]
|
public int Current
|
{
|
get { return nCurrentPageNo; }
|
set
|
{
|
if (value < 1)
|
{
|
value = 1;
|
}
|
else if (value > nAllPageCnt)
|
{
|
value = nAllPageCnt;
|
}
|
|
nCurrentPageNo = value;
|
UpdataCurrent();
|
}
|
}
|
|
/// <summary>
|
/// 每页行数
|
/// </summary>
|
[Description("每页的行数"), Browsable(false)]
|
public int PagerNum
|
{
|
get { return nOnePageRowCnt; }
|
set
|
{
|
nOnePageRowCnt = value;
|
|
isTrigger = false;
|
/*更新完每页行数,要先更新总页数,再触发相关事件*/
|
nAllPageCnt = ((nAllDataCount + nOnePageRowCnt - 1) / nOnePageRowCnt);
|
UpdataTotal();
|
UpdataCurrent();
|
isTrigger = true;
|
|
OnPagerNumChanged();
|
}
|
}
|
|
/// <summary>
|
/// 是否触发事件
|
/// </summary>
|
[Description("控制分页组件是否响应事件,主要用于代码设置分页组件,而不触发事件"), Browsable(false)]
|
public bool IsTrigger
|
{
|
get { return isTrigger; }
|
set { isTrigger = value; }
|
}
|
|
[Description("设置或获取数据总数的显示消息内容;#count 为占位符,将自动替换成数据总数")]
|
public string DataCountLable
|
{
|
get
|
{
|
return aDataCountLable;
|
}
|
set
|
{
|
aDataCountLable = value;
|
}
|
}
|
|
private string aDataCountLable = "共 #count 行";
|
|
/// <summary>
|
/// 总页数
|
/// </summary>
|
private int nAllPageCnt = 0;
|
|
/// <summary>
|
/// 数据总数
|
/// </summary>
|
private int nAllDataCount = 0;
|
|
/// <summary>
|
/// 当前页数
|
/// </summary>
|
private int nCurrentPageNo = 0;
|
|
/// <summary>
|
/// 每页行数
|
/// </summary>
|
private int nOnePageRowCnt = PaginationDefaultParameter.PageSize;
|
|
/// <summary>
|
/// 每页行数列表
|
/// </summary>
|
private List<int> OnePageRowCntList = new List<int>(new int[] { 15, 30, 50, 70, 100 });
|
|
/// <summary>
|
/// 是否需要触发相关事件
|
/// </summary>
|
private bool isTrigger = true;
|
|
/// <summary>
|
/// 触发事件的当前页号,用来防止当前页改变时的二次触发
|
/// </summary>
|
private int nTriggerPageNo = 0;
|
#endregion
|
|
#region 构造函数
|
public PagerToolsControl()
|
{
|
InitializeComponent();
|
//Dock = DockStyle.Bottom;
|
tBoxDataCnt.Text = aDataCountLable;
|
isTrigger = false;
|
foreach (int iObj in OnePageRowCntList)
|
{
|
cBoxOnePageRowCnt.Items.Add(iObj);
|
}
|
cBoxOnePageRowCnt.SelectedIndex = 0;
|
isTrigger = true;
|
}
|
#endregion
|
|
#region 页面初始化
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
DataCount = 0;
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
#endregion
|
|
/// <summary>
|
/// 更新总页数
|
/// </summary>
|
private void UpdataTotal()
|
{
|
//tlab_total.Text = string.Format(tlab_total.Tag.ToString(), aTotal);
|
|
cBoxPageCnt.Items.Clear();
|
for (int i = 0; i < nAllPageCnt; i++)
|
{
|
cBoxPageCnt.Items.Add(i + 1);
|
}
|
cBoxPageCnt.SelectedIndex = 0;
|
|
if (nCurrentPageNo > nAllPageCnt)
|
Current = nAllPageCnt;
|
else
|
{
|
cBoxPageCnt.SelectedIndex = nCurrentPageNo - 1;
|
OnPagerIndexChanged();
|
UpdataView();
|
}
|
}
|
|
/// <summary>
|
/// 更新当前页
|
/// </summary>
|
private void UpdataCurrent()
|
{
|
tBoxCurrentPageNo.Text = nCurrentPageNo.ToString();
|
cBoxPageCnt.SelectedIndex = nCurrentPageNo - 1;
|
|
UpdataView();
|
OnPagerIndexChanged();
|
}
|
|
/// <summary>
|
/// 更新界面
|
/// </summary>
|
private void UpdataView()
|
{
|
if (nAllPageCnt == 0)
|
{
|
gridFirstPage.IsEnabled = gridLastPage.IsEnabled
|
= gridNextPage.IsEnabled = gridPreviousPage.IsEnabled
|
= tBoxCurrentPageNo.IsEnabled
|
= cBoxPageCnt.IsEnabled = false;
|
return;
|
}
|
|
if ((nCurrentPageNo == 1) && (nCurrentPageNo < nAllPageCnt))
|
{
|
gridFirstPage.IsEnabled = gridPreviousPage.IsEnabled = false;
|
|
gridLastPage.IsEnabled = gridNextPage.IsEnabled
|
= tBoxCurrentPageNo.IsEnabled
|
= cBoxPageCnt.IsEnabled = true;
|
}
|
else if ((nCurrentPageNo == 1) && (nCurrentPageNo == nAllPageCnt))
|
{
|
gridFirstPage.IsEnabled = gridPreviousPage.IsEnabled
|
= gridLastPage.IsEnabled = gridNextPage.IsEnabled
|
= false;
|
|
tBoxCurrentPageNo.IsEnabled
|
= cBoxPageCnt.IsEnabled = true;
|
}
|
else if ((nCurrentPageNo > 1) && (nCurrentPageNo < nAllPageCnt))
|
{
|
gridFirstPage.IsEnabled = gridPreviousPage.IsEnabled
|
= gridLastPage.IsEnabled = gridNextPage.IsEnabled
|
= tBoxCurrentPageNo.IsEnabled
|
= cBoxPageCnt.IsEnabled = true;
|
}
|
else if ((nCurrentPageNo > 1) && (nCurrentPageNo == nAllPageCnt))
|
{
|
gridLastPage.IsEnabled = gridNextPage.IsEnabled = false;
|
|
gridFirstPage.IsEnabled = gridPreviousPage.IsEnabled
|
= tBoxCurrentPageNo.IsEnabled
|
= cBoxPageCnt.IsEnabled = true;
|
}
|
}
|
|
/// <summary>
|
/// 更新每页行数
|
/// </summary>
|
private void UpdataPagerNum()
|
{
|
if ((cBoxOnePageRowCnt.SelectedItem != null) && (nOnePageRowCnt == ((int)cBoxOnePageRowCnt.SelectedItem)))
|
{
|
return;
|
}
|
|
foreach (object iItem in cBoxOnePageRowCnt.Items)
|
{
|
if (((int)iItem) == nOnePageRowCnt)
|
{
|
cBoxOnePageRowCnt.SelectedItem = iItem;
|
return;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 当前页改变时调用事件
|
/// </summary>
|
private void OnPagerIndexChanged()
|
{
|
if (!isTrigger) return;
|
//if (nTriggerPageNo == nCurrentPageNo) return;
|
if (PageCntChanged != null)
|
{
|
C_EventArgsClass iObj = new C_EventArgsClass();
|
iObj.CurrentPageNo = nCurrentPageNo;
|
iObj.Total = nAllPageCnt;
|
Mouse.OverrideCursor = Cursors.Wait;
|
PageCntChanged(this, iObj);
|
Mouse.OverrideCursor = null;
|
nTriggerPageNo = nCurrentPageNo;
|
}
|
}
|
|
/// <summary>
|
/// 每页行数改变时调用事件
|
/// </summary>
|
private void OnPagerNumChanged()
|
{
|
if (!isTrigger) return;
|
if (OnePageRowCntChanged != null)
|
{
|
C_EventArgsClass iObj = new C_EventArgsClass();
|
iObj.CurrentPageNo = nCurrentPageNo;
|
iObj.Total = nAllPageCnt;
|
iObj.PagerNum = nOnePageRowCnt;
|
Mouse.OverrideCursor = Cursors.Wait;
|
OnePageRowCntChanged(this, iObj);
|
Mouse.OverrideCursor = null;
|
}
|
}
|
|
/// <summary>
|
/// 首页
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnFirstPage_Click(object sender, RoutedEventArgs e)
|
{
|
Current = 1;
|
}
|
|
/// <summary>
|
/// 上一页
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnPreviousPage_Click(object sender, RoutedEventArgs e)
|
{
|
Current--;
|
}
|
|
/// <summary>
|
/// 尾页
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
|
private void btnLastPage_Click(object sender, RoutedEventArgs e)
|
{
|
Current = nAllPageCnt;
|
}
|
|
/// <summary>
|
/// 次页
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void btnNextPage_Click(object sender, RoutedEventArgs e)
|
{
|
Current++;
|
}
|
|
//private void tcomb_current_SelectedIndexChanged(object sender, EventArgs e)
|
//{
|
// //Current = tcomb_current.SelectedIndex + 1;
|
//}
|
|
/// <summary>
|
/// 页数变更
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void cBoxPageCnt_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
{
|
Current = cBoxPageCnt.SelectedIndex + 1;
|
}
|
|
/// <summary>
|
/// 每页行数变更
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void cBoxOnePageRowCnt_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
{
|
if (!isTrigger) return;
|
PagerNum = (int)cBoxOnePageRowCnt.SelectedItem;
|
}
|
|
#region Del
|
//private void ttxt_current_KeyPress(object sender, KeyPressEventArgs e)
|
//{
|
// //if (e.KeyChar == 13)
|
// //{
|
// // Current = int.Parse(ttxt_current.Text);
|
// //}
|
|
// //if (e.KeyChar != 8)//退格键
|
// //{
|
// // if ((e.KeyChar < '0') || (e.KeyChar > '9'))
|
// // e.Handled = true;
|
// //}
|
//}
|
|
//private void tcom_num_KeyPress(object sender, KeyPressEventArgs e)
|
//{
|
// //if (e.KeyChar == 13)
|
// //{
|
// // int ipagernum = int.Parse(tcom_num.Text);
|
// // if (!aPagerNumList.Contains(ipagernum))
|
// // {
|
// // aPagerNumList.Add(ipagernum);
|
// // tcom_num.Items.Add(ipagernum);
|
// // aIsTrigger = false;
|
// // tcom_num.SelectedItem = ipagernum;
|
// // aIsTrigger = true;
|
// // }
|
// // //UpdataPagerNum();
|
// // PagerNum = int.Parse(tcom_num.Text);
|
// //}
|
|
// //if (e.KeyChar != 8)//退格键
|
// //{
|
// // if ((e.KeyChar < '0') || (e.KeyChar > '9'))
|
// // e.Handled = true;
|
// //}
|
//}
|
#endregion
|
}
|
}
|