public int beginCount( String countSql, ObjectPage pager, EntityInfo entityInfo ) { String commandText = countSql; logger.Info( "[Page Record Count] " + commandText ); IDbCommand command = DataFactory.GetCommand( commandText, DbContext.getConnection( entityInfo ) ); pager.RecordCount = cvt.ToInt( command.ExecuteScalar() ); pager.computePageCount(); pager.resetCurrent(); return pager.getCurrent(); }
public int beginCount(String countSql, ObjectPage pager, EntityInfo entityInfo) { String commandText = countSql; logger.Info("[Page Record Count] " + commandText); IDbCommand command = DataFactory.GetCommand(commandText, DbContext.getConnection(entityInfo)); pager.RecordCount = cvt.ToInt(command.ExecuteScalar()); pager.computePageCount(); pager.resetCurrent(); return(pager.getCurrent()); }
public static DataPage <T> GetPage(List <T> list, int pageSize, int pageIndex = 0) { ObjectPage op = new ObjectPage(); if (pageSize <= 0) { pageSize = 20; } op.setSize(pageSize); op.RecordCount = list.Count; // 计算页数 op.computePageCount(); // 矫正当前页码 int currentPageNumber = CurrentRequest.getCurrentPage(); if (pageIndex > 0) { currentPageNumber = pageIndex; } op.setCurrent(currentPageNumber); op.resetCurrent(); currentPageNumber = op.getCurrent(); // 得到结果集 List <T> results = new List <T>(); int start = (currentPageNumber - 1) * pageSize; int count = 1; for (int i = start; i < list.Count; i++) { if (count > pageSize) { break; } results.Add(list[i]); count++; } // 填充分页数据 DataPage <T> page = new DataPage <T>(); page.Results = results; page.Current = currentPageNumber; page.Size = pageSize; page.RecordCount = list.Count; page.PageCount = op.PageCount; return(page); }