一个简单的分页类

 

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;
 }

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值