<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' PageDiv.asp
''
'' Version: 1.0 Last-Modified: 2004-10-28 10:16
'' Copyright: Xinsoft@newX.org ( CTO of UnionIT.org )
''
'' 分页类(通用)
''
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
<%
Class ListDiv
Public Flag ' as Integer
Private RecordSet ' as ADODB.RecordSet
Private Connection ' as ADODB.Connection
Public DivNum ' as Integer
Public PageN ' as Integer
Public CurN ' as Integer
Public CurPage ' as Integer
Public IdxColType ' as String ' -- char
' -- int
Public IndexSQL ' as String
Public ListSQLB ' as String
Public ListSQLE ' as String
Public RecN ' as Integer
Public RowA,RowN ' A pair of Array
Public LinkStrB ' as String
Public LinkStrE ' as String
Public LinkStyle ' as String
Property Let Conn(objConn)
Connection.ConnectionString=objConn.ConnectionString
End Property
Property Get Conn()
Conn=Connection.ConnectionString
End Property
Private Sub Class_Initialize
Flag=1
DivNum=10
PageN=0
CurN=0
CurPage=1
IdxColType="char"
LinkStyle="default"
Set RecordSet=Server.CreateObject("ADODB.RecordSet")
Set Connection=Server.CreateObject("ADODB.Connection")
End Sub
Private Sub Class_Terminate
Set RecordSet=Nothing
Set Connection=Nothing
End Sub
Public Sub Exec()
If Not IsNumeric(CurPage) Then CurPage=1
If CurPage<1 Then CurPage=1
'' 获取索引字段值列表
Dim RecA,i,N
Connection.Open
RecordSet.Open IndexSQL,Connection,1,1
RecN=RecordSet.RecordCount
If RecN>0 Then
RecA=RecordSet.GetRows
Else
Flag=0
Exit sub
End if
RecordSet.Close
'' 计算页数
PageN=Int(RecN / DivNum)+1
If DivNum*(PageN-1)=RecN Then
PageN=PageN-1
End if
If CurPage>PageN Then CurPage=PageN
If PageN>1 Then
If CurPage=PageN Then
CurN=RecN-(CurPage-1)*DivNum
Else
CurN=DivNum
End if
Else
CurN=RecN
End If
'' 索引数组
Dim IdxA
ReDim IdxA(CurN)
For i=0 To CurN-1
IdxA(i)=RecA(0,(CurPage-1)*DivNum+i)
Next
Dim DotChar
Select Case LCase(IdxColType)
Case "int" : DotChar=""
Case "char" : DotChar="'"
Case Else : DotChar="'"
End select
IdxStr=""
If CurN>0 Then
IdxStr=DotChar& IdxA(0) &DotChar
If CurN>1 Then
For i=1 To CurN-1
IdxStr=IdxStr&","&DotChar&IdxA(i)&DotChar
Next
End if
End If
'' 获取实际列表
RecordSet.Open ListSQLB &IdxStr& ListSQLE,Connection,1,1
RowN=RecordSet.RecordCount
If RowN>0 Then
RowA=RecordSet.GetRows
Else
Flag=0
Exit sub
End if
RecordSet.Close
Connection.Close
End Sub
Public Function GetPageDivBar()
Dim Str
Dim i
Str=""
If CurPage>1 Then
Str=Str&"<a href="""& LinkStrB & CStr(CurPage-1) & LinkStrE &""">上一页</a>"
Else
Str=Str&"上一页"
End If
Str=Str&" 第"&CurPage&"页/共"&PageN&"页,每页"&DivNum&"条记录,共"&RecN&"条记录 "
If CurPage<PageN Then
Str=Str & "<a href="""&LinkStrB&CStr(CurPage+1)&LinkStrE&""">下一页</a>"
Else
Str=Str & "下一页"
End if
GetPageDivBar=Str
End Function
End Class
%>
1、获取了两次记录集,但是这两个记录集满足了实现分页操作所需的最小记录集;
2、IndexSQL是用来获取获取索引字段值列表的SQL语句;
3、IdxStr无需赋值;
4、ListSQLB、ListSQLE赋值举例如下:
调用的例子:
<%
Dim objListDiv
Set objListDiv=New ListDiv
With objListDiv
.Conn=Conn
.IdxColType="int"
.IndexSQL="Select PeriodID From Xiworld Where Flag=1 Order by PeriodID Desc"
.ListSQLB="Select PeriodID,YearVal,YearPid,DocURL From Xiworld Where PeriodID in ("
.ListSQLE=") Order by PeriodID Desc"
.DivNum=15
.CurPage=CurPage
.LinkStrB="list.asp?page="
.LinkStrE=""
End With
objListDiv.Exec
%>