'// ---- Cocoon_ Custom Class_Froand Page 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 Correct a bug, description: If the ID is not unique, a plurierage of multiple repeat records will be generated.
'2003.5
'--------------------------------
'// -------------------------------------- //'
Private stablename '// Name
PRIVATE SSQLSTRING '// Custom SQL Statement
Private acondition () '// Query Conditions (arrays)
Private scondition '// Query Conditions (String)
Private ipage '// Current page number
Private ipageSize '// Per page record number
Private ipagecount '// Total Page
Private IRECcount '// Records under current query conditions
Private itotalreccount '// total record number
PRIVATE SFIELDS '// Field Name
Private sorderby '// Sort string
PRIVATE SSQL '// Current Query Statement
Private spkey '// primary key
Private Oconn '// Connection Object
Private IDefpagesize '// Number of records displayed by default
Private SPROJECTNAME '/ Project Name
Private sversion '/ version number
PRIVATE BSHOWEROR '/ / Whether to display an error message
'// ---------------------------------- //'
'// class initialization event
Private sub coplass_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 database turn page optimization"
sversion = "1.02"
End Sub
'// class end event
Private sub coplass_terminate ()
Set Oconn = Nothing
End Sub
'// error handling
Public Sub Doerror (s)
DIM STMP
STMP = CLNG (RND () * 100) Response.write ("
Response.write ("
Response.write ("
Response.write (" Description span>:" & s & "
")
Response.write (" provider span>:" & sprojectname)
Response.write (" version span>:" & SVERSION & "
")
Response.write (" nobr> div> div>
")
End Sub
'// Generate SQL statement
Public function getSQL ()
DIM ISTART, IEND
Call makecondition ()
iStart = (ipage - 1) * ipageSize
IEND = iStart ipageSize
Getsql = "Select Distinct" & Sfields & "& stablename &"] "_
& "Where [" & spkey & "] not in (" _ _ _ _
& "SELECT TOP" & ISTART & "& SPKEY &"] "& STABLENAME &" & SCONS & SCONDIT & "& Sorderby &" _ & ")" _
& "And" & spkey & "] in (" _ _ _
& "SELECT TOP" & IEND & "[" & SPKEY & "]" & STABLENAME & "]" & SCONDITION & "& SORDERBY &" _
& ")" _
& "& Sorderby &" "
END FUNCTION
'// Generate condition string
Private subecondition ()
IF ubound (acondition)> = 0 THEN
SCONDITION = "Where" & join (acondition, "and")
END IF
End Sub
'// Calculate total record number (with conditions)
Private sub caaculatectureReccount ()
ON Error ResMe next
DIM ORS
Call makecondition ()
SET ORS = Oconn.execute ("Select Count ([" & SPKEY & "]" & STABLENAME & "& SCONDITION)
IF Err THEN
Doerror Err.Description
Response.end ()
END IF
Ireccount = ips.fields.Item (0) .value
SET ORS = Nothing
End Sub
'// Calculate total record number (without conditions)
Private sub caaculateTotaReccount ()
ON Error ResMe 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
'// calculation page number
Private sub caaculatePageCount ()
If isnull (IRECcount) Then CaculateReccount ()
IRECcount = 0 Then ipagecount = 0: EXIT SUB
ipageCount = ABS (int (0 - (IRECcount / ipageSize))))
End Sub
'// increase conditions
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
END FUNCTION
'// -------------------- Enter the properties ------------------ //'
'// Define the connection object
Public Property Set ActiveConnection (O)
Set Oconn = O
End Property
'// Define the query table name
Public Property Let TableName (s)
Stablename = S
End Property
'// Define the field name that needs to be output
Public property Let Fields (s)
Sfields = s
End Property
'// Define the primary key
Public Property Let Pkey (S)
Spkey = s
End Property
'// Define Sort Rules
Public property let Orderby (s)
Sorderby = "Order by" & S & ""
End Property
'// Define the number of records 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 the 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 = ipagecount
End Property
'// Custom Query Statement
Public Property Let SQL (S)
SSQLString = S
End Property
'// --------------------------------------- //'
'// Number of records under current conditions
Public property Get Recordcount
If isnull (IRECcount) Then CaculateReccount ()
Recordcount = IRECCANT
End Property
'// get the current page number
Public Property Get Page
Page = ipage
End Property
'// get the current page number
Public property Get AbsolutePage
AbsolutePage = ipage
End Property
'// Conditions to get the current query
Public property Get Condition
If len (scondition) <1 Then makecondition ()
Condition = SCONDITION
End Property
'// Number of total records
Public property Get TotalRecordcount
If ISNULL (ITOTALRECCOUNT) THEN CACLATALRECCVOUNT ()
TotalRecordcount = itotalReccount
End Property
'// Number of points
Public Property Get PageCount
If isnull (ipagecount) Then CaculatePageCount ()
PageCount = ipagecount
End Property
'// Get the recording set after paging
Public property Get Recordset
ON Error ResMe next
SSQL = getSQL ()
Set recordset = Oconn.execute (SSQL)
IF Err THEN
IF bshowError damtion 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>