?? pages.asp
字號:
<!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312">-->
<%
Class PageClass
Private Connection '連接數據庫的外部Connection對象
Private Rs 'RecordSet對象
Private List_Fields '字段列表
Private Table_Name '表的名稱
Private Query_Where '查詢的條件語句
Private OrderBy_SQL '字段排序語句部分
Private Page_Count '返回當前查詢的記錄頁總數
Private Page_Size '設置一頁顯示多少條的記錄
Private Cur_Page '設置當前的頁碼
Private Record_Count '返回當前查詢的記錄總數
'/****************設置Connection對象****************************
Public Property Let Conn(ByRef ObjConn)
Set Connection=ObjConn
End Property
Public Property Get Conn()
Set Conn=Connection
End Property
'/****************End******************************************
'/****************設置查詢SQL語句*******************************
''查詢顯示字段
Public Property Let Fields(ByVal Value)
List_Fields=Value
End Property
Public Property Get Fields()
Fields=List_Fields
End Property
''查詢表名
Public Property Let TableName(ByVal Value)
Table_Name=Value
End Property
Public Property Get TableName()
TableName=Table_Name
End Property
''查詢條件
Public Property Let Condition(ByVal Value)
Query_Where=Value
End Property
Public Property Get Condition()
Condition=Query_Where
End Property
''*****************排序部分********************************************
''Value 語不用寫上Order By 。如: [object].OrderBy="ID Desc,PostTime Asc"
Public Property Let OrderBy(ByVal Value)
OrderBy_SQL=Value
End Property
Public Property Get OrderBy()
OrderBy=OrderBy_SQL
End Property
'/****************End******************************************
'/****************返回當前查詢結果的總頁數***********************
Public Property Get PageCount()
PageCount=Page_Count
End Property
Public Property Get RecordCount()
RecordCount=Record_Count
End Property
Public Property Get NextPage()
If Cur_Page<Page_Count Then
NextPage=Cur_Page+1
Else
NextPage=Page_Count
End If
End Property
Public Property Get PrePage()
If Cur_Page>1 Then
PrePage=Cur_Page-1
Else
PrePage=Cur_Page
End If
End Property
'/****************End******************************************
'/****************設置一頁顯示的記錄數***************************
Public Property Let PageSize(ByVal Value)
If Not IsNumeric(Value) Or Value="" Then
Value=10
Else
Value=Cint(Value)
End If
If Value<1 Then Value=10
Page_Size=Value
End Property
Public Property Get PageSize()
PageSize=Page_Size
End Property
''設置當前的頁碼數**************************
Public Property Let Page(ByVal Value)
If Not IsNumeric(Value) Or Value="" Then
Value=1
Else
Value=CInt(Value)
End If
If Value<1 Then Value=1
Cur_Page=Value
End Property
Public Property Get Page()
Page=Cur_Page
End Property
'/****************End******************************************
Private Sub Class_Initialize
'初始化RecordSet對象
Page_Size=10 '默認一頁為10條數據
CurPage=1 '默認當前為第一頁
Record_Count=0
Page_Count=0
End Sub
Private Sub Class_Terminate
Call CloseRecordSet
End Sub
'/***關閉數據庫的連接*******
Private Sub CloseRecordSet
On Error Resume Next
If IsObject(Rs) Then
Rs.Close
Set Rs=Nothing
End If
On Error Goto 0
End Sub
'/**********執行查詢返回對應頁碼的數據***********************************************
Public Function ExecuteBy(ByVal oTableName,ByVal oFields,ByVal oCondtion,ByVal oOrderBy)
Table_Name=oTableName
List_Fields=oFields
Query_Where=oCondtion
OrderBy_SQL=oOrderBy
Set ExecuteBy=Execute()
End Function
'查詢并返回當前CurPage的頁碼記錄
Public Function Execute()
Call CloseRecordSet
On Error Resume Next
Dim TSQL,TopMod,sWhere
'如果數據庫連接不存在,表名未知或排序方式未知,返回RS=Nothing
If Not IsObject(Connection) Or Table_Name="" Or OrderBy_SQL="" Then
Set Execute=Nothing
Record_Count=0
Page_Count=0
Exit Function
End If
'建立并插入查找串
If Trim(Query_Where)<>"" Then
sWhere="Where "&Query_Where
Else
sWhere=""
End If
TSQL="Select Count(*) From ["&Table_Name&"] "&sWhere
Record_Count=Connection.Execute(TSQL)(0) '獲取記錄總數
If Err Then
Err.Clear
Set Execute=Nothing
Record_Count=0
Page_Count=0
Exit Function
End If
If Record_Count<1 Then
Set Execute=Nothing
Record_Count=0
Page_Count=0
Exit Function
End If
'取得頁的總數
If Record_Count Mod Page_Size <>0 Then
TopMod=Record_Count Mod Page_Size
Page_Count=Fix(Record_Count/Page_Size)+1
If Cur_Page<Page_Count Then
TopMod=Page_Size
End If
Else
TopMod=Page_Size
Page_Count=Fix(Record_Count/Page_Size)
End If
If Cur_Page>Page_Count Then Cur_Page=Page_Count
If Cur_Page<1 Then Cur_Page=1
If Trim(List_Fields)="" Then List_Fields="*"
TSQL="Select * From (Select Top "&TopMod&" * From (Select Top "&(Cur_Page*Page_Size)&" "&List_Fields&" From ["&Table_Name&"] "&sWhere&" Order By "&OrderBy_SQL&") Order By "&TransformOrder(OrderBy_SQL)&")Order By "&OrderBy_SQL
Set Rs=Connection.Execute(TSQL)
If Err Then
Err.Clear
Set Execute=Nothing
Record_Count=0
Page_Count=0
Exit Function
End If
Set Execute=Rs
End Function
'轉換OrderBy的順序 ASC->DESC DESC->ASC
Private Function TransformOrder(ByVal Value)
If Value="" Then
TransformOrder=""
Exit Function
End If
Dim OrderArray,i,Result,ByString,Fields,InPos
OrderArray=Split(Value,",") '分解每個字段值
For i=0 To Ubound(OrderArray)
If OrderArray(i)<>"" Then
InPos=InStrRev(Trim(OrderArray(i))," ") '找出排序的順序
If InPos<1 Then '如果找不到則是ASC排序
ByString="ASC"
Fields=OrderArray(i)+" "
Else
ByString=Trim(Mid(OrderArray(i),InPos+1))
Fields=Left(OrderArray(i),InPos)
If ByString<>"" Then
ByString=UCase(ByString)
Else
ByString="ASC"
End If
End If
''轉換排序
If ByString="ASC" Then
ByString="DESC"
Else
ByString="ASC"
End If
Result=Result+Fields+ByString+","
End If
Next
If Result<>"" Then Result=Left(Result,Len(Result)-1)
TransformOrder=Result
End Function
''生成導航欄
Public Function GetPageBar(strURL)
dim strPageChoose
If InStr(strURL,"?")<>0 Then
strURL = strURL&"&Page="
Else
strURL = strURL&"?Page="
End If
if Page_Count = 1 then
GetPageBar = ""
exit function
end if
'如果不是第一頁
if Cur_Page > 1 then
strPageChoose = strPageChoose&"<a href='"&strURL&(Cur_Page-1)&"'>[上一頁]</a>"
end if
'計算頁選擇欄
for i=1 to Page_Count
if Cur_Page = i then
strPageChoose = strPageChoose&"<b>["&i&"]</b>"
else
strPageChoose = strPageChoose&"<a href='"&strURL&i&"'>["&i&"]</a>"
end if
next
if Cur_Page < Page_Count then
strPageChoose = strPageChoose&"<a href='"&strURL&(Cur_Page+1)&"'>[下一頁]</a>"
end if
strPageChoose = strPageChoose & "<Font color='#FFFFFF'>......</Font>"
GetPageBar = strPageChoose
End Function
End Class
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -