一、ado控件,缺點是速度慢:ide
procedure showViewData(PageSize,AbsolutePage : Integer);spa
varit
i : Integer;io
beginclass
trydate
adoPCustomer.Recordset.PageSize := PageSize;分頁
if adoPCustomer.RecordCount<1 then查詢
Exit;存儲過程
adoPCustomer.Recordset.AbsolutePage :=AbsolutePage;db
if adoPCustomer.Recordset.PageCount<> AbsolutePage then
grdTVCustomer.DataController.RecordCount := adoPCustomer.Recordset.PageSize
else
grdTVCustomer.DataController.RecordCount := adoPCustomer.RecordCount-adoPCustomer.Recordset.PageSize*(AbsolutePage-1);
adoPCustomer.First;
adoPCustomer.MoveBy((AbsolutePage-1)*adoPCustomer.Recordset.PageSize);
grdTVCustomer.BeginUpdate;
for i :=0 to grdTVCustomer.DataController.RecordCount-1 do
begin
grdTVCustomer.DataController.Values[i,0] := adoPCustomer.FieldbyName('編號').AsString;
grdTVCustomer.DataController.Values[i,1] := adoPCustomer.FieldbyName('客戶代碼').AsString;
grdTVCustomer.DataController.Values[i,2] := adoPCustomer.FieldbyName('客戶名稱').AsString;
adoPCustomer.Next;
end;
grdTVCustomer.EndUpdate;
grdTVCustomer.ApplyBestFit();
cxTextEdit1.Text := IntToStr(AbsolutePage);
except
on e:Exception do
raise Exception.Create('執行查詢時出錯!'+#13+'出錯緣由:'+e.Message);
end;
end;
二、SQL存儲過程分頁,缺點是每次都要查詢:
ALTER PROC [dbo].[P_Customer_QuerySaleCustomer_分頁]
(
@User NVARCHAR(10),
@PageSize INT, --顯示頁數
@CurrPage INT, --當前頁數
@RecordCount NVARCHAR(10) OUTPUT --總頁數
)
AS
BEGIN
SET @RecordCount=(SELECT COUNT(1) FROM dbo.T_Customer_Sale (NOLOCK) WHERE CardOwner=@User OR IsShared=0);
WITH CUSTOMER AS (
SELECT TOP (@PageSize * @CurrPage)
ROW_NUMBER() OVER (ORDER BY ID)ROWNUMBER ,CardCode 客戶代碼, CardName 客戶名稱
,CASE IsHot WHEN 0 THEN '是' ELSE '否' END 是否熱點
,CASE HotLev WHEN 0 THEN '低' WHEN 1 THEN '中' ELSE '高' END 熱點程度
,CASE HotType WHEN 0 THEN '新客戶' WHEN 1 THEN '老客戶' ELSE '新合做' END 熱點類型, HotNote 熱點說明
,CASE CreditLev WHEN 0 THEN '低' WHEN 1 THEN '中' ELSE '高' END 信用等級
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardType) 類型
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardIndustry) 行業
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardSource) 來源
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardCusLev) 關係等級
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardSize) 規模
,CardNote 備註, CardAddress 地址
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardProvince) 省份, CardCity 城市
,(SELECT DicName FROM dbo.T_Customer_Dictionary WHERE ID=CardArea) 區域, CardWeb 網址,ConRate 維護週期,
IsShared 是否共享,CardOwner 全部者
FROM dbo.T_Customer_Sale (NOLOCK)
WHERE CardOwner=@User OR IsShared=0
)
SELECT *
FROM CUSTOMER
WHERE ROWNUMBER > ((@CurrPage-1) *@PageSize)
--PRINT @RecordCount
END