using
System;
using System.Collections.Generic;
using System.Text;
namespace Factory
... {
public delegate void PaginationHandler ( ref int page );
/**//// <summary>
/// 分页处理类
/// </summary>
public class Pagination
...{
private int _currentpage;
private int _pagetotal;
private ulong _recordtotal;
private int _pagesize;
/**//// <summary>
/// 当前页
/// </summary>
public int CurrentPage
...{
get ...{ return _currentpage; }
}
/**//// <summary>
/// 页总数
/// </summary>
public int PageTotal
...{
get
...{
decimal tmp_count = new decimal(_recordtotal);
decimal tmp_size = new decimal(_pagesize);
decimal tmp_page;
tmp_page = decimal.Divide(tmp_count , tmp_size);
if (decimal.Remainder(tmp_count , tmp_size) > 0)
tmp_page += 1;
tmp_page = decimal.Floor(tmp_page);
_pagetotal = decimal.ToInt32(tmp_page);
return _pagetotal;
}
}
/**//// <summary>
/// 记录总数
/// </summary>
public ulong RecordTotal
...{
get ...{ return _recordtotal; }
set ...{ _recordtotal = value; }
}
/**//// <summary>
/// 分页大小
/// </summary>
public int PageSize
...{
get
...{
if (_pagesize == 0)
...{
return 16;
}
return _pagesize;
}
set ...{ _pagesize = value; }
}
/**//// <summary>
/// 初始化分页实例
/// </summary>
/// <param name="recordTotal">记录总数</param>
/// <param name="pageSize">分页大小</param>
public Pagination ( ref ulong recordTotal, ref int pageSize )
...{
this._recordtotal = recordTotal;
this._pagesize = pageSize;
this._pagetotal = 0;
this._currentpage = 1;
}
private Pagination () ...{ }
/**//// <summary>
/// 下一页
/// </summary>
public void NextPage ()
...{
if (_currentpage < _pagetotal)
...{
_currentpage += 1;
OnNextPage(ref _currentpage);
}
}
/**//// <summary>
/// 上一页
/// </summary>
public void PreviousPage ()
...{
if (_currentpage > 1)
...{
_currentpage -= 1;
OnPreviousPage(ref _currentpage);
}
}
/**//// <summary>
/// 跳转到指定页面
/// </summary>
/// <param name="page">指定页面</param>
public void Go ( int page )
...{
if (page >= 0 && page <= _pagetotal && page != _currentpage)
...{
_currentpage = page;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 首页
/// </summary>
public void FirstPage ()
...{
if (_currentpage != 1)
...{
_currentpage = 1;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 尾页
/// </summary>
public void LastPage ()
...{
if (_currentpage != _pagetotal)
...{
_currentpage = _pagetotal;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 当跳转页面时
/// </summary>
public event PaginationHandler OnGo;
/**//// <summary>
/// 当到下一页时
/// </summary>
public event PaginationHandler OnNextPage;
/**//// <summary>
/// 当到上一页时
/// </summary>
public event PaginationHandler OnPreviousPage;
}
}
using System.Collections.Generic;
using System.Text;
namespace Factory
... {
public delegate void PaginationHandler ( ref int page );
/**//// <summary>
/// 分页处理类
/// </summary>
public class Pagination
...{
private int _currentpage;
private int _pagetotal;
private ulong _recordtotal;
private int _pagesize;
/**//// <summary>
/// 当前页
/// </summary>
public int CurrentPage
...{
get ...{ return _currentpage; }
}
/**//// <summary>
/// 页总数
/// </summary>
public int PageTotal
...{
get
...{
decimal tmp_count = new decimal(_recordtotal);
decimal tmp_size = new decimal(_pagesize);
decimal tmp_page;
tmp_page = decimal.Divide(tmp_count , tmp_size);
if (decimal.Remainder(tmp_count , tmp_size) > 0)
tmp_page += 1;
tmp_page = decimal.Floor(tmp_page);
_pagetotal = decimal.ToInt32(tmp_page);
return _pagetotal;
}
}
/**//// <summary>
/// 记录总数
/// </summary>
public ulong RecordTotal
...{
get ...{ return _recordtotal; }
set ...{ _recordtotal = value; }
}
/**//// <summary>
/// 分页大小
/// </summary>
public int PageSize
...{
get
...{
if (_pagesize == 0)
...{
return 16;
}
return _pagesize;
}
set ...{ _pagesize = value; }
}
/**//// <summary>
/// 初始化分页实例
/// </summary>
/// <param name="recordTotal">记录总数</param>
/// <param name="pageSize">分页大小</param>
public Pagination ( ref ulong recordTotal, ref int pageSize )
...{
this._recordtotal = recordTotal;
this._pagesize = pageSize;
this._pagetotal = 0;
this._currentpage = 1;
}
private Pagination () ...{ }
/**//// <summary>
/// 下一页
/// </summary>
public void NextPage ()
...{
if (_currentpage < _pagetotal)
...{
_currentpage += 1;
OnNextPage(ref _currentpage);
}
}
/**//// <summary>
/// 上一页
/// </summary>
public void PreviousPage ()
...{
if (_currentpage > 1)
...{
_currentpage -= 1;
OnPreviousPage(ref _currentpage);
}
}
/**//// <summary>
/// 跳转到指定页面
/// </summary>
/// <param name="page">指定页面</param>
public void Go ( int page )
...{
if (page >= 0 && page <= _pagetotal && page != _currentpage)
...{
_currentpage = page;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 首页
/// </summary>
public void FirstPage ()
...{
if (_currentpage != 1)
...{
_currentpage = 1;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 尾页
/// </summary>
public void LastPage ()
...{
if (_currentpage != _pagetotal)
...{
_currentpage = _pagetotal;
OnGo(ref _currentpage);
}
}
/**//// <summary>
/// 当跳转页面时
/// </summary>
public event PaginationHandler OnGo;
/**//// <summary>
/// 当到下一页时
/// </summary>
public event PaginationHandler OnNextPage;
/**//// <summary>
/// 当到上一页时
/// </summary>
public event PaginationHandler OnPreviousPage;
}
}