|
 |
资料搜索 |
|
|
|
|
|
|
|
 |
相关文章 |
|
|
|
|
|
|
|
|
|
|
| [ 来源:转载 | 作者:无从考证 | 时间:2005-12-19 13:18:32 | 浏览:人次 ] | |
|
} } public int PageCount { get { if(this.pageCount == -1) { string selCountStr = string.Format("Select count(*) from {0} {1}" ,this.theParas.TableName ,this.theParas.WhereStr) ; DataSet ds= this.adoBase.DoQuery(selCountStr) ; this.itemCount = int.Parse(ds.Tables[0].Rows[0][0].ToString()) ; this.pageCount = this.itemCount/this.theParas.PageSize ; if((this.itemCount%this.theParas.PageSize >0)) { ++ this.pageCount ; } } return this.pageCount ; } }
/// /// GetPage 取出指定的一页 /// public DataTable GetPage(int index) { if(index == this.curPageIndex) { return this.curPage ; }
if((index < 0) || (index >(this.PageCount-1))) { return null; }
DataTable dt = this.GetCachedObject(index) ;
if(dt == null) { string selectStr = this.ConstrutSelectStr(index) ; DataSet ds = this.adoBase.DoQuery(selectStr) ; dt = ds.Tables[0] ;
this.CacheObject(index ,dt) ; } this.curPage = dt ; this.curPageIndex = index ; return this.curPage ; }
private DataTable GetCachedObject(int index) { if(this.fixCacher == null) { return null ; } return (DataTable)this.fixCacher[index] ; }
private void CacheObject(int index ,DataTable page) { if(this.fixCacher != null) { this.fixCacher.PutIn(index ,page) ; } }
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) ; }
#endregion #endregion } 了解这个类的实现,可以从GetPage(int index)方法入手,另外私有方法ConstrutSelectStr()的实现说明了如何使用嵌套sql语句进行随机分页搜索。
最后,关于分页管理器,需要指出的是,搜索对应的表必须有一个名为"ID"的主键--这是唯一的要求。另外,分页管理器实现用到的数据访问低阶封装IADOBase定义于EnterpriseServerBase类库中。
使用分页管理器是很简单的,加上UI界面后,只要把返回的DataTable绑定到DataGrid就可以了。
|
|
|
|
|
|
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
|
|
|
|
|
栏目编辑: 设计风 |
责任编辑: 简若宁 |
|
|
原始作者: 无从考证 |
录入时间: 2005-12-19 13:18:32 |
|
|
信息来源: 转载 |
投稿信箱: Edu#chinaz.com |
|
|
|
| |
|