调整的代码:
private DataTable GetPagedDataTable(int APageIndex, int APageSize,bool ACheckPageCount=true)
{
string sSortField = OpDataGrid.SortField;
string sSortDirection = OpDataGrid.SortDirection;
if (sSortField != "")
{
sSortField = sSortField + " " + sSortDirection.ToLower();
}
else
{
sSortField = "WzBm";
}
string sSqlText = "Exec RY_PROC_WZZL_GetDataList_OnePage @APCount OUTPUT,@ARCount OUTPUT,@ASys_Where,@ASys_Order,"
+"@ASys_PageIndex,@ASys_PageSize,@FlID,@UseFor";
SqlParameter[] myParams = new SqlParameter[] {
new SqlParameter("APCount",0),
new SqlParameter("ARCount",0),
new SqlParameter("ASys_Where",""),
new SqlParameter("ASys_Order",sSortField),
new SqlParameter("ASys_PageIndex",APageIndex),
new SqlParameter("ASys_PageSize",APageSize),
new SqlParameter("FlID",_WzFlID),
new SqlParameter("UseFor","")
};
myParams[0].Direction = ParameterDirection.Output;
myParams[1].Direction = ParameterDirection.Output;
DataTable myTempTable = DbHelper.ExecuteDataTable(sSqlText, myParams);
//判断总页数,是否小于页索引
if (Convert.ToInt32(myParams[0].Value) < APageIndex && ACheckPageCount)
{
//若是,则进行第二次获取,且返回
return GetPagedDataTable(Convert.ToInt32(myParams[0].Value)-1, APageSize, false);
}
else
{
if (myParams[1].Value == DBNull.Value)
OpDataGrid.RecordCount = 0;
else
OpDataGrid.RecordCount = Convert.ToInt32(myParams[1].Value);
return myTempTable;
}
}
|