private static IDataParameter[] BuildParams(DataBase db, PagedSettings pagedSettings, bool isTotal, int pageSize, int pageNumber) { if (isTotal) { return(new IDataParameter[] { db.BuildParameter("TableName", pagedSettings.TableName), db.BuildParameter("Fields", string.Empty), db.BuildParameter("SortField", string.Empty), db.BuildParameter("PageSize", DbType.AnsiString), db.BuildParameter("PageNumber", DbType.AnsiString), db.BuildParameter("IsTotalRecords", 1), db.BuildParameter("OrderType", DbType.AnsiString), db.BuildParameter("Where", pagedSettings.Where) }); } return(new IDataParameter[] { db.BuildParameter("TableName", pagedSettings.TableName), db.BuildParameter("Fields", pagedSettings.Fields), db.BuildParameter("SortField", pagedSettings.SortField), db.BuildParameter("PageSize", pageSize), db.BuildParameter("PageNumber", pageNumber), db.BuildParameter("IsTotalRecords", DbType.AnsiString), db.BuildParameter("OrderType", (int)pagedSettings.OrderType), db.BuildParameter("Where", pagedSettings.Where) }); }
public static BoolResult <PagedList <TEntity> > SPToPagedList <TEntity>(this DataBase db, PagedSettings pagedSettings, int pageNumber, int pageSize) where TEntity : class, new() { IDataParameter[] parameters = DataPaging.BuildParams(db, pagedSettings, true, pageSize, pageNumber); IDataParameter[] parameters2 = DataPaging.BuildParams(db, pagedSettings, false, pageSize, pageNumber); BoolResult <int> boolResult = db.SPScalar <int>("Proc_Paging", parameters); if (!boolResult.Success) { return(new BoolResult <PagedList <TEntity> >(null, boolResult.Errors.IsValid, "", boolResult.Errors)); } BoolResult <IList <TEntity> > result = db.RefSPToList <TEntity>("Proc_Paging", parameters2); PagedList <TEntity> item = new PagedList <TEntity>(pageNumber, pageSize, boolResult.Item, result.Item); boolResult.Errors.EachFull(delegate(string error) { result.Errors.Add(error); }); return(new BoolResult <PagedList <TEntity> >(item, result.Errors.IsValid, "", result.Errors)); }