<script Language=vbscript runat=server>
'//----Cocoon_ Custom class _ Paging Optimization code----//'
Class Cc_db_pager
''--------------------------------
' Cocoon Db_pager Class (ver:1.02)
' Author: sunrise_chen (sunrise_chen@msn.com)
"Please keep this information, thank you."
''
' 2003/06 to fix an error, Description: If the ID is not unique, multiple duplicate records will result in errors.
"' 2003.5
''--------------------------------
'//--------------------define variable--------------------//'
Private stablename '/table name
Private ssqlstring '//Custom SQL statements
Private acondition () '//query criteria (array)
Private scondition '//query criteria (String)
Private ipage '//Current page number
Private ipagesize '//per page record number
Private Ipagecount '//Total pages
Private Ireccount '//number of records under current query conditions
Private Itotalreccount '//Total record number
Private sfields '//Output field name
Private Sorderby '//Sort string
Private sSQL '//Current query statement
Private Spkey '//PRIMARY key
Private oconn '//Connection object
Private idefpagesize '//default number of records displayed per page
Private sprojectname '/project name
Private sversion '/version number
Private Bshowerror '//Whether an error message is displayed
'//--------------------event, Method--------------------//'
'//Class initialization event
Private Sub Class_Initialize ()
ReDim acondition (-1)
IPage = 1
Ireccount = Null
Itotalreccount = Null
Ipagecount = Null
Bshowerror = True
Ipagesize = 10
Sfields = "*"
Spkey = "ID"
Scondition = ""
Sorderby = ""
ssqlstring = ""
Sprojectname = "Cocoon class Series Database paging Optimization"
Sversion = "1.02"
End Sub
'//Class End Event
Private Sub Class_Terminate ()
Set oconn = Nothing
End Sub
'//Error handling
Public Sub Doerror (s)
Dim STMP
STMP = CLng (Rnd () * 100)
Response.Write ("<div style=" Width:760;font-size:9pt;cursor:hand ' > ")
Response.Write ("<label onclick=" Errordiv "&sTmp&". style.display= (Errordiv "&sTmp&". style.display== "" ""? "" None "": "" "" ") ' > '
Response.Write ("<span style=" Background-color: #CCCC00; Color:white; " >〖cc_db_pager hint Information 〗</span><br></label> ")
Response.Write ("<div id=" Errordiv "&sTmp&" ' style= ' display:none; width:100%; ")
Response.Write ("border:1px SOLID #CCCC00; padding:5;overflow:hidden;text-overflow:ellipsis; " ><NOBR> ")
Response.Write ("<span style= ' color:red ' >description</span>:" & S & "<BR>")
Response.Write ("<span style= ' color:red ' >provider</span>:" & Sprojectname)
Response.Write ("<span style= ' color:red ' >version</span>:" & Sversion & "<BR>")
Response.Write ("</NOBR></DIV></DIV><BR>")
End Sub
'//Generate paging SQL statement
Public Function GetSQL ()
Dim IStart, Iend
Call Makecondition ()
IStart = (iPage-1) * ipagesize
Iend = IStart + ipagesize
GetSQL = "Select DISTINCT" & Sfields & "from [" &sTableName& "]" _
& Where ["&sPKey&"] not in ("_
& "Select Top" &iStart& "[" &sPKey& "] from [" &sTableName& "]" & Scondition & "" & Sorderby & "" _
& ")" _
& "and [" &sPKey& "] In (" _
& "Select Top" &iEnd& "[" &sPKey& "] from [" &sTableName& "]" & Scondition & "" & S By & "" _
& ")" _
& "" & Sorderby & ""
End Function
'//Generate condition String
Private Sub makecondition ()
If UBound (acondition) >=0 Then
Scondition = "Where" & Join (Acondition, "and")
End If
End Sub
"//Total number of records (with conditions)
Private Sub Caculatereccount ()
On Error Resume Next
Dim ORs
Call Makecondition ()
Set oRs = Oconn.execute ("Select COUNT ([&sPKey&]) from [" & sTableName & "]" & Scondition)
If ERR Then
Doerror Err.Description
Response.End ()
End If
Ireccount = ORs.Fields.Item (0). Value
Set ORs = Nothing
End Sub
"//Total number of records (without conditions)
Private Sub Caculatetotalreccount ()
On Error Resume Next
Dim ORs
Set oRs = Oconn.execute ("Select COUNT ([&sPKey&]) from [" & sTableName & "]")
If ERR Then
Doerror Err.Description
Response.End ()
End If
Itotalreccount = ORs.Fields.Item (0). Value
Set ORs = Nothing
End Sub
'//Count pages
Private Sub Caculatepagecount ()
If isNull (Ireccount) Then Caculatereccount ()
If ireccount = 0 Then ipagecount = 0:exit Sub
Ipagecount = Abs (Int (0-(ireccount/ipagesize)))
End Sub
'//Add condition
Public Sub addcondition (s)
If Len (s) <0 Then Exit Sub
ReDim Preserve acondition (UBound (acondition) +1)
Acondition (UBound (acondition)) = s
End Sub
'//Version information
Public Function information ()
Doerror "Coding by <a href= ' mailto:sunrise_chen@msn.com ' ' >Sunrise_Chen</A> @ <a href= ' http:// Www.ccopus.com ' >http://www.ccopus.com<;/A>. '
End Function
'//--------------------input attribute--------------------//'
'//Define Connection object
Public Property Set ActiveConnection (O)
Set oconn = O
End Property
'//Define query table name
Public Property Let TableName (s)
sTableName = S
End Property
'//define field names that need to be output
Public Property Let Fields (s)
Sfields = S
End Property
'//define primary key
Public Property Let Pkey (s)
Spkey = S
End Property
'//define Collation
Public Property Let (s)
Sorderby = "ORDER BY" & S & ""
End Property
"//define the number of record bars per page
Public Property Let PageSize (s)
Ipagesize = S
If not IsNumeric (ipagesize) Then ipagesize = idefaultpagesize
If CLng (ipagesize) <1 Then ipagesize = idefaultpagesize
End Property
'//define current page number
Public Property Let Page (s)
IPage = S
If not IsNumeric (ipage) Then ipage = 1
If CLng (ipage) <1 Then ipage = 1
Call Caculatepagecount ()
If CLng (ipage) >clng (ipagecount) and ipagecount>0 Then = IPage
End Property
'//Custom query statement
Public Property Let SQL (s)
Ssqlstring = S
End Property
'//--------------------output attribute--------------------//'
"//Get the number of records under current conditions
Public Property Get RecordCount
If isNull (Ireccount) Then Caculatereccount ()
RecordCount = Ireccount
End Property
'//Get current page number
Public Property Get Page
Page = IPage
End Property
'//Get current page number
Public Property Get AbsolutePage
AbsolutePage = IPage
End Property
'//Get the condition of the current query
Public Property Get Condition
If Len (scondition) <1 Then makecondition ()
Condition = Scondition
End Property
"//Total number of records obtained
Public Property Get Totalrecordcount
If isNull (Itotalreccount) Then Caculatetotalreccount ()
Totalrecordcount = Itotalreccount
End Property
"//Total number of pages made
Public Property Get PageCount
If isNull (Ipagecount) Then Caculatepagecount ()
PageCount = Ipagecount
End Property
'//Get the paging recordset
Public Property Get Recordset
On Error Resume Next
sSQL = GetSQL ()
Set Recordset = Oconn.execute (sSQL)
If ERR Then
If bshowerror Then Doerror Err.Description
If Len (ssqlstring) >0 Then
Set Recordset = Oconn.execute (ssqlstring)
If ERR Then
Doerror Err.Description
Response.End ()
End If
Else
Doerror Err.Description
End If
End If
Err.Clear ()
End Property
'//Version information
Public Property Get Version
Version = Sversion
End Property
End Class
</SCRIPT>