int PageCount{get ;} int CacherSize{get; set; } } 这个接口定义中,最主要的是GetPage()方法,实现了这个方法,其它的三个获取页面的方法CurrentPage、PrePage、NextPage也就非常容易了。另外,CacherSize属性可以让我们指定缓存页面的数量。如果不需要缓存,则设置其值<=0,如果需要无限缓存,则值为Int.MaxValue。
public DataTable CurrentPage() { return this.curPage ; }
public DataTable PrePage() { return this.GetPage((--this.curPageIndex)) ; }
public DataTable NextPage() { return this.GetPage((++this.curPageIndex)) ; }
private string ConstrutSelectStr(int pageIndex) { if(pageIndex == 0) { return string.Format("Select top {0} {1} from {2} {3} ORDER BY ID" ,this.theParas.PageSize ,this.fieldStrs ,this.theParas.TableName ,this.theParas.WhereStr) ; }
int innerCount = this.itemCount - this.theParas.PageSize*pageIndex ; string innerSelStr = string.Format("Select top {0} {1} from {2} {3} ORDER BY ID DESC " ,innerCount , this.fieldStrs ,this.theParas.TableName ,this.theParas.WhereStr) ; string outerSelStr = string.Format("Select top {0} * from ({1}) DERIVEDTBL ORDER BY ID" ,this.theParas.PageSize ,innerSelStr) ;
return outerSelStr ; }
#region Initialize public void Initialize(IDBAccesser accesser, int page_Size, string whereStr, string[] fields) { this.theParas = new DataPaginationParas(accesser.ConnectString ,accesser.DbTableName ,whereStr) ; this.theParas.Fields = fields ; this.theParas.PageSize = page_Size ;
this.fieldStrs = this.theParas.GetFiedString() ; this.adoBase = new SqlADOBase(this.theParas.ConnectString) ; }
public void Initialize(DataPaginationParas paras) { this.theParas = paras ; this.fieldStrs = this.theParas.GetFiedString() ; this.adoBase = new SqlADOBase(this.theParas.ConnectString) ; }