Database
Sub DeleteObject (ByRef obj)
Set obj = Nothing
obj = null
End Sub
Class CDB
private M_oconn, M_ors
private M_pageindex, M_pagesize, M_pagecount, M_recordcount
Private Strerror
Private M_querystring
private Sub class_initialize ()
m_oconn = null
m_ors = null
M_pageindex = 1
m_pagesize = 10
M_pagecount = 1
m_recordcount = 0
call Connect ()
End Sub
Private Property Get GetConnectionString ()
if InStr (LCase (Request.ServerVariables ("Script_name")), "/admin/") > 0 Then
getconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("DataBase \data.mdb ")
Else
getconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Admin\Da Tabase\data.mdb ")
End If
End Property
Public Property Let SetPageSize (num)
if not isnumeric (num) then Exit property
num = CInt (num)
if num > 0 Then m_pagesize = num
End Property
' object. Appendsearch (paraname) = Paravalue
Public Property Let Appendquerystring (Paraname, Paravalue)
m_querystring = m_querystring & "&" & paraname & "=" & Server.URLEncode (Paravalue)
End Property
Public Property Let Setpageindex (num)
if not isnumeric (num) then Exit property
num = CInt (num)
if num > 0 Then m_pageindex = num
End Property
Public default function toString ()
toString = strerror
End Function
Private Sub Connect ()
Set m_oconn = Server.CreateObject ("ADODB. Connection ")
m_oconn.connectionstring = getconnectionstring
M_oconn.open ()
If Err then
strerror = Err. Description
Response.Write ("Sorry, failed to connect database!")
Err. Clear ()
DeleteObject (m_oconn)
Response.End ()
End If
End Sub
Private Sub Close (ByRef dbobject)
if 1 = dbobject.state then call Dbobject.close ()
End Sub
Public Function ExecuteScalar (strSQL)
ExecuteScalar = M_oconn.execute (strSQL) (0)
End Function
Public Sub Execute (ByVal strSQL)
if (not IsObject (m_oconn)) then Exit Sub
M_oconn.execute (strSQL)
End Sub
Private Function Openrs ()
Openrs = False
if (not IsObject (m_oconn)) Or m_oconn.state = 0) Then Exit Function
if (IsObject (m_ors)) then
If 1 = m_ors.state then call M_ors.close ()
Else
Set m_ors = Server.CreateObject ("ADODB. RecordSet ")
End If
Openrs = True
End Function
Public Function GetData (ByVal strSQL)
If not Openrs () then
GetData = null
Exit Function
End If
Call M_ors.open (strSQL, M_oconn, 1, 1)
if M_ors.eof then
GetData = null
else
GetData = m_ors.getrows ()
End If
m_ors.close ()
End Function
Public Function Getmultpagedata (ByVal strSQL)
if not Openrs () then
Getmultpagedata = null
Exit Function
End If
Call M_ors.open (strSQL, M_oconn, 1, 1)
if M_ors.eof then
getmultpagedata = null
Else
M_ors.pagesize = M_pagesize
M_recordcount = M_ors.recordcount
M_pagecount = M_ors.pagecount
if (M_pageindex > M_pagecount) then M_pageindex = M_pagecount
m_ors.absolutepage = M_pageindex
getmultpagedata = m_ors.getrows (m_pagesize)
End If
Call M_ors.close ()
End Function
Public Function PageInfo (style)
Dim Shtml:set sHtml = new Stringbuild
shtml.setvalue = "<div id=" "Divpagenav" ">"
call Shtml.appendformat ("<label> total: {0} records, current:{1}/{2}:</label>", Array (M_recordcount, M_pageind EX, M_pagecount))
Select Case Style
Case 1:if 1 = M_pageindex then
call Shtml.append ("<span> home </span><span> prev </span>")
Else
call Shtml.appendformat ("<a href=" "Page=1{0}" "> Home </a><a href=" "? page= {1} {0} "" > Prev </a>, Array (m_querystring,m_pageindex-1))
End If
if M_pagecount = M_pageindex then
call Shtml.append ("<span> next page </span><span> last </span>")
Else
Call Shtml.appendformat ("<a href=" "Page={1}{0}" "> next page </a><a href=" "? Page={2}{0}" "> End </a>", Array (m_querystring, M_pageindex + 1, m_pagecount))
End If
case 2:dim interval, startpage, endpage, I
interval = 5
StartPage = M_pageindex-interval
if StartPage < 1 then startpage = 1
endpage = startpage + 2 * interval
if EndPage > m_pagecount then endpage = M_pagecount
StartPage = endPage-2 * Interval
if StartPage < 1 then startpage = 1
if 1 = M_pageindex then
Call Shtml.append ("<span style=" "Font-family:webdings;" " >9</span><span style= "" Font-family:webdings; "" >7</span> ")
Else
call Shtml.appendformat ("<a href=" "Page=1{0}" "Style=" "Font-family:webdings" " >9</a><a href= "" "Page={1}{0}" "Style=" "font-family:webdings;" >7</a> ", Array (m_querystring, CStr (m_pageindex-1))
End If
for i = StartPage to M_pageindex-1
call Shtml.appendformat ("<a href=" "Page={1}{0}" ">{1}</a>", Array (M_quer Ystring, CStr (i))
Next
Call Shtml.append ("<span>" & M_pageindex & "</span>")
for i = m_pageindex+1 to EndPage
call Shtml.appendformat ("<a href=" "Page={1}{0}" ">{1}</a>", Array (M_quer Ystring, CStr (i))
Next
if M_pagecount = M_pageindex then
shtml.append ("<span style=" "Font-family:webdings;" " >8</span><span style= "" Font-family:webdings; "" >:</span> ")
Else
Call Shtml.appendformat ("<a href=" "? Page={1}{0}" "Style=" "Font-family:webdings" " >8</a><a href= "" "Page={2}{0}" "Style=" "font-family:webdings;" >:</a> ", Array (m_querystring,m_pageindex+1,m_pagecount))
End If
End Select
call Shtml.append ("</div>")
PageInfo = sHtml
DeleteObject (sHtml)
End Function
private Sub class_terminate ()
Close (m_ors)
Close (m_oconn)
DeleteObject (m_ors)
DeleteObject (m_oconn)
End Sub
End Class
Dim i, ODB, arrdata:set ODB = new CDB
odb.setpagesize = 2
Odb.setpageindex = request.querystring ("page")
arrdata = Odb.getmultpagedata ("SELECT [TITLE] from [CLASS]")
for i = 0 To UBound (arrdata, 2)
Echo (arrdata (0, i) & "<br/>")
Next
Echo (Odb.pageinfo (1))
DeleteObject (ODB)