sql server 数据分页显示。

时间:2023-12-18 16:39:44
 select [ID]
,[StockApplyCode]
,[RcCode]
,[LabCenterCode]
,[LabGroupCode]
,[LabGroupName]
,[Barcode]
,[TestSubItemCode]
,[TestSubItemName]
,[CreateDate]
,[CalcRule]
,[BomType]
,[BomConsume]
,[SingleConsumePredict]
,[SingleConsume]
,[BeginDate]
,[EndDate]
,[CostPrice]
into #tempRCUDCalc
from Financial.ReagentConsumablesUseDetailCalc
where StockApplyCode = @StockApplyCode declare @TotalRowCount INT -- 总行数
SET @TotalRowCount = (select COUNT() FROM #tempRCUDCalc) declare @temp int
set @temp=@PageSize*(@PageIndex - )
select top (select @PageSize)
[ID]
,[StockApplyCode]
,[RcCode]
,[LabCenterCode]
,[LabGroupCode]
,[LabGroupName]
,[Barcode]
,[TestSubItemCode]
,[TestSubItemName]
,[CreateDate]
,[CalcRule]
,[BomType]
,[BomConsume]
,[SingleConsumePredict]
,[SingleConsume]
,[BeginDate]
,[EndDate]
,[CostPrice]
--,@TotalRowCount TotalRowCount
from #tempRCUDCalc A
where NOT EXISTS (
SELECT from ( select top (select @temp) id from #tempRCUDCalc ORDER BY id) B where A.id = B.id
)
order by id --结果总行数
select COUNT() TotalRowCount FROM #tempRCUDCalc
public void LoadReagentConsumablesUseApplyEdit(string strApplyCode, int pageIndex, int pageSize, out int countTotal, out int allRowsCount)
{
countTotal = ;
allRowsCount = ;
try
{
if (pageIndex <= )
pageIndex = ; if (pageSize <= )
pageSize = ; Byte[] isData = ServiceExecuteMethod.ExecuteMethod<IFinancial>(Config.ReadValueByKey(CommonString.IFinancialUrl),
"LoadReagentConsumablesUseApplyEditByPage", new object[] { strApplyCode, pageIndex, pageSize }, Config.ReadValueByKey(CommonString.IFinancialBinding)) as Byte[]; if (pageIndex == )
{
_ReagentConsumablesUse = DataZipHelp.RetrieveDataSetDecompress(isData) as DSReagentConsumablesUse;
countTotal = _ReagentConsumablesUse.ReagentConsumablesUseDetailCalc.Count;
if (countTotal > )
allRowsCount = int.Parse(_ReagentConsumablesUse.Tables["TableInfo"].Rows[]["TotalRowCount"].ToString());
}
else
{
DSReagentConsumablesUse dsTemp = DataZipHelp.RetrieveDataSetDecompress(isData) as DSReagentConsumablesUse;
if (_ReagentConsumablesUse == null) return; countTotal = dsTemp.ReagentConsumablesUseDetailCalc.Count;
if (countTotal > )
allRowsCount = int.Parse(_ReagentConsumablesUse.Tables["TableInfo"].Rows[]["TotalRowCount"].ToString()); _ReagentConsumablesUse.ReagentConsumablesUseDetailCalc.Merge(dsTemp.ReagentConsumablesUseDetailCalc);
_ReagentConsumablesUse.AcceptChanges();
}
}
catch (Exception ex)
{
throw ex;
}
} private void RefreshReagentConsumablesUseDetailCalcData()
{
try
{
//弹出提示画面
new Thread((ThreadStart)delegate
{
WaitingDataRefreshing = new DevExpress.Utils.WaitDialogForm("请稍候...", "正在加载数据", new Size(, ));
Application.Run(WaitingDataRefreshing);
}).Start(); _Biz.LoadReagentConsumablesUseApplyEdit(StockApplyCode, ++pageIndex, pageSize, out countTotal, out allRowsCount);
// TempDS = CommonBiz.SplitDataSet(_Biz.ReagentConsumablesUse, TempDS, "ReagentConsumablesUseDetailCalc", ++pageIndex, pageSize, out countTotal, out allRowsCount);
//申请明细-分摊
_BSReagentConsumablesUseDetailCalc.DataSource = _Biz.ReagentConsumablesUse;
_BSReagentConsumablesUseDetailCalc.DataMember = "ReagentConsumablesUseDetailCalc"; grdcReagentConsumablesUseDetailCalc.EmbeddedNavigator.TextStringFormat = @"Record {0} of " + allRowsCount.ToString();
grdvReagentConsumablesUseDetailCalc.BestFitColumns(); //waitDialogForm.Close();
WaitingDataRefreshing.Invoke((EventHandler)delegate { WaitingDataRefreshing.Close(); });
}
catch (Exception ex)
{
XtraMessageBox.Show("数据加载失败!错误信息[" + ex.Message + "]");
}
} private void GrdvReagentConsumablesUseDetailCalc_TopRowChanged(object sender, EventArgs e)
{
try
{
if (grdvReagentConsumablesUseDetailCalc.IsRowVisible(grdvReagentConsumablesUseDetailCalc.RowCount - ) == RowVisibleState.Visible)
{
grdvReagentConsumablesUseDetailCalc.TopRowChanged -= GrdvReagentConsumablesUseDetailCalc_TopRowChanged;
if (countTotal == pageSize && allRowsCount > countTotal)
{
RefreshReagentConsumablesUseDetailCalcData();
grdvReagentConsumablesUseDetailCalc.TopRowChanged += GrdvReagentConsumablesUseDetailCalc_TopRowChanged;
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
}

使用代码