<%
Class Xuduopage
'************************************
' Variable definition
'************************************
' Xconn----Database Tutorial Connection
' XRs----recordset
' Xtmp-an array that holds the final record
' xcountsql----Query total record number SQL statement
' XSQL----Query SQL statements
' Xpagesize----Paging size
' XPage----Current page
' Xrecordcount----record number
' Xpagecount----Total pages
Private Xconn,xrs,xtmp,xtablename,xfields,xwhere,xorder,xref,xordertype,xprimarykey,xcountsql,xsql,xpagesize, Xpage,xrecordcount,xpagecount
Private Xflag,xmiddleindex,xbar,xi,xpagestart,xpageend
'************************************
' Class initialization
'************************************
Private Sub Class_Initialize ()
Xtablename = ""
Xfields = "*"
Xwhere = ""
Xordertype = 1
Xpagesize = 10
Xbar = 1
End Sub
'************************************
' Class end
'************************************
Private Sub Class_Terminate ()
End Sub
'************************************
' Setconn get a database connection www.111cn.net
'************************************
Public Property Let Setconn (value)
Set Xconn = value
End Property
'************************************
' TableName get the table name
'************************************
Public Property Let TableName (value)
Xtablename = value
End Property
'************************************
' Setfields get query field
'************************************
Public Property Let Setfields (value)
Xfields = value
End Property
'************************************
' Setwhere get other conditions
'************************************
Public Property Let Setwhere (value)
Xwhere = value
End Property
'************************************
' Setwhere get other conditions
'************************************
Public Property Let Setref (value)
XRef = value
End Property
'************************************
' Setorder get Sort type
'************************************
Public Property Let Setorder (value)
Xordertype = value
End Property
'************************************
' Setpkey get the primary key
'************************************
Public Property Let Setpkey (value)
Xprimarykey = value
End Property
'************************************
' GetPageSize get page paging size
'************************************
Public Property Let SetPageSize (value)
Xpagesize = value
End Property
'************************************
' Setbar get page paging size
'************************************
Public Property Let Setbar (value)
Xbar = value
End Property
'************************************
' Getreccount the total number of records
'************************************
Private Function Getreccount ()
If xwhere = "" Then
' Xcountsql = ' Select Count (*) from [& Xtablename &] '
Xcountsql = "Select Count (*) from" & Xtablename
Else
' Xcountsql = ' Select Count (*) from [& Xtablename &] Where ' & Xwhere
Xcountsql = "Select Count (*) from" & Xtablename & "Where" & Xwhere
End If
REM Response. Write (Xcountsql)
Getreccount = Xconn.execute (Xcountsql) (0)
End Function
'************************************
' Getpagecount the total number of pages
'************************************
Private Function Getpagecount (irecordcount)
If irecordcount Mod xpagesize = 0 Then
Getpagecount = Irecordcountxpagesize
Else
Getpagecount = irecordcountxpagesize+1
End If
End Function
'************************************
' Getmidpageindex calculates the page index of the middle page
'************************************
Private Function Getmidpageindex ()
Getmidpageindex = (xpagecount)-1
End Function
'************************************
' GetPage the current page
'************************************
Private Function getpage (ipagecount)
Dim IPage
IPage = Request ("page")
If ipage = "" Then xPage = "1"
If not IsNumeric (ipage) Then ipage = "1"
IPage = CLng (ipage)
If ipage > Ipagecount Then ipage = Ipagecount
If IPage < 1 Then ipage = 1
GetPage = IPage
End Function
'************************************
' Getorderstring get the sort statement
'************************************
Private Function getorderstring ()
If Xordertype = 1 Then
Getorderstring = "ORDER By" & Xprimarykey & "ASC"
ElseIf Xordertype = 2 Then
Getorderstring = "ORDER By" & Xprimarykey & "Desc"
Else
getorderstring = ""
End If
End Function
'************************************
' Getwherestring get conditional statement
'************************************
Private Function getwherestring ()
If xwhere <> "" Then
getwherestring = getwherestring & "Where" & Xwhere
Else
getwherestring = ""
End If
End Function
'************************************
' GetSqlString generates SQL
'************************************
Private Function getsqlstring ()
Dim Xwhere_,xmiddleindex
Xwhere_ = getwherestring () '//Generate conditional statement
Xmiddleindex = Getmidpageindex () '//Get Middle page index
' Response.Write ("xmiddleindex=" & Xmiddleindex)
' Response.Write ("<br>")
If xordertype = 1 Then '/ascending
If xpage=1 Then
getsqlstring = "SELECT Top" & Xpagesize & "& Xfields &" from "& Xtablename &" "& Xwher E_ & "ORDER BY" & Xprimarykey & "ASC"
Xflag = "11"
ElseIf 1 < xPage and xPage <= xmiddleindex Then
getsqlstring = "SELECT Top" & Xpagesize & "" & Xfields & "from" & Xtablename & "Where" & Xprimarykey & "> (Select Max (" & Xprimarykey & ") from (select Top & xpagesize* (xPage-1) &" " & Xprimarykey & "from" & Xtablename & "& Xwhere_ &" ORDER BY "& Xprimarykey &" Asc ) TableA) and & Xwhere & "ORDER BY" & Xprimarykey & "ASC"
Xflag = "12"
ElseIf Xmiddleindex < XPage and XPage < Xpagecount Then
getsqlstring = "SELECT * from" (SELECT Top & Xpagesize & "" & Xfields & "from" & Xtablename & "Where" & Xprimarykey & "< (select Min (" & Xprimarykey & ") from (select Top & XRECORDCOUNT-XP) Agesize*xpage & "" & Xprimarykey & "from" & Xtablename & "" & Xwhere_ & "ORDER BY" & Xprimarykey & "Desc) TableA) and" & Xwhere & "ORDER BY" & Xprimarykey & "Desc" TableB Order BY " & Xprimarykey & "ASC"
Xflag = "13"
ElseIf Xpage=xpagecount Then
getsqlstring = "SELECT * from" (SELECT Top & xrecordcount-xpagesize* (xPageCount-1) & "& Xfields &" Fr Om "& Xtablename &" "& Xwhere_ &" ORDER BY "& Xprimarykey &" Desc "TableA Order BY" & X PrimaryKey & "ASC"
Xflag = "14"
End If
Else '//Descending
If xpage=1 Then
getsqlstring = "SELECT Top" & Xpagesize & "& Xfields &" from "& Xtablename &" "& Xwher E_ & "ORDER BY" & Xprimarykey & "Desc"
Xflag = "21"
ElseIf 1 < xPage and xPage <= xmiddleindex Then
getsqlstring = "SELECT Top" & Xpagesize & "" & Xfields & "from" & Xtablename & "Where" & Xprimarykey & "< (select Min (" & Xprimarykey & ") from (select Top & xpagesize* (xPage-1) &" " & Xprimarykey & "from" & Xtablename & "& Xwhere_ &" ORDER BY "& Xprimarykey &" Des c) TableA) and "& Xwhere &" ORDER BY "& Xprimarykey &" Desc "
Xflag = "22"
ElseIf Xmiddleindex < XPage and XPage < Xpagecount Then
getsqlstring = "SELECT * from" (SELECT Top & Xpagesize & "" & Xfields & "from" & Xtablename & "Where" & Xprimarykey & "> (Select Max (" & Xprimarykey & ") from (select Top & XRECORDCOUNT-XP) Agesize*xpage & "" & Xprimarykey & "from" & Xtablename & "" & Xwhere_ & "ORDER BY" & Xprimarykey & "ASC) TableA) and" & Xwhere & "ORDER BY" & Xprimarykey & "ASC" TableB Order By "& Amp Xprimarykey & "Desc"
Xflag = "23"
ElseIf Xpage=xpagecount Then
getsqlstring = "SELECT * from" (SELECT Top & xrecordcount-xpagesize* (xPageCount-1) & "& Xfields &" Fr Om "& Xtablename &" "& Xwhere_ &" ORDER BY "& Xprimarykey &" ASC "as TableA Order BY" & Xprimarykey & "Desc"
Xflag = "24"
End If
End If
End Function
'************************************
' GetArray get an array of records
'************************************
Public Function GetArray ()
Set xRs = Server.CreateObject ("Adodb.recordset")
Xrecordcount = Getreccount () '//Calculate total record number
Xpagecount = Getpagecount (xrecordcount) '//Total number of pages calculated
XPage = GetPage (xpagecount) '//Calculate current page
XSQL = getsqlstring ()
Xrs.open xsql,xconn,1,1
If not xrs.eof Then
Xtmp = Xrs.getrows ()
Else
Xtmp = Null
End If
XRs.Close:Set XRs = Nothing
GetArray = xtmp
End Function
'************************************
' GetURL returns the current URL to ensure that the URL parameters are not faulted www.111cn.net
'************************************
Private Function GetURL ()
Dim pageurl,filenamestr,filename,oi,oj,pagestr,resulturl,tempurl,t
Pagestr = "Page="
Filenamestr = Request.ServerVariables ("Url")
Filenamestr = Split (Filenamestr, "/")
OI = Ubound (filenamestr,1)
filename = filenamestr (oI) ' Get current page filename
Pageurl = Trim (Request.ServerVariables ("query_string"))
'--Watermelon increased
If XRef and Cstr (request.form) <> "" Then pageurl = pageurl + Request.Form
'--end
If pageurl <> "" Then
If InStr (pageurl,pagestr) >0 Then
If InStr (Pageurl, "&") >0 Then
Tempurl = Split (Pageurl, "&")
Pageurl = ""
For T = 0 to Ubound (tempurl)
If InStr (Tempurl (T), pagestr) =0 Then
Pageurl = Pageurl & "&" & Tempurl (T)
End If
Next
Pageurl = Right (Pageurl,len (Pageurl)-1)
Resulturl = FileName & "?" & Pageurl & "&page="
Else
Resulturl = FileName & "? page="
End If
Else
Resulturl = FileName & "?" & Pageurl & "&page="
End If
Else
Resulturl = FileName & "? page="
End If
GetURL = Resulturl
End Function
'************************************
' CurrentPage returns the current page number
'************************************
Public Property Get CurrentPage
CurrentPage = XPage
End Property
'************************************
' Countpage return total pages
'************************************
Public Property Get Countpage
Countpage = Xpagecount
End Property
'************************************
' Countrecord returns the total number of records www.111cn.net
'************************************
Public Property Get Countrecord
Countrecord = Xrecordcount
End Property
Public Function Showbar ()
Dim xpagetmp,xpagestart,xpageend,xbarhtmls,xpageurl,xselected
xselected = ""
Xpageurl = GetURL ()
If xpagecount<10 and Xpagecount>0 Then
Xpagestart = 1
Xpageend = Xpagecount
Else
Xpagestart = xPage-5
Xpageend = xpage+4
If xpagestart<=0 Then
Xpagestart = 1
Xpageend = 10
End If
If Xpageend>=xpagecount Then
Xpagestart = xPageCount-10
Xpageend = Xpagecount
End If
End If
If xbar=1 Then
For XI = Xpagestart to Xpageend
If XI = XPage Then
xpagetmp = xpagetmp & "<font color= ' #999999 ' >" & XI & "</font>"
Else
xpagetmp = xpagetmp & "<a href=" & Xpageurl & XI & ">" & XI & "</a>"
End If
Next
XBARHTMLS = ""
xbarhtmls = xbarhtmls & "<table width= ' 100% ' align= ' right ' cellpadding= ' 0 ' >"
xbarhtmls = xbarhtmls & "<TBODY>"
xbarhtmls = xbarhtmls & "<TR>"
xbarhtmls = xbarhtmls & "<td width= ' 35% ' > Total &nbsp;" & xpagecount & "Page &nbsp;&nbsp;" & Xrec Ordcount & "Records &nbsp;&nbsp; current" & xPage & "Page &nbsp;&nbsp;&nbsp;</TD>"
xbarhtmls = xbarhtmls & "<td align= ' right ' ><a href= '" & Xpageurl & "1 ' > Home </a>"
If xpage>1 Then
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & xPage-1 & "' > Previous </a>"
Else
xbarhtmls = xbarhtmls & "<font color= ' #999999 ' > Prev </font>"
End If
xbarhtmls = xbarhtmls & xpagetmp
If Xpage<xpagecount Then
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & xpage+1 & "' > Next page </a>"
Else
xbarhtmls = xbarhtmls & "<font color= ' #999999 ' > Next </font>"
End If
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & Xpagecount & "' > Last </a> </TD>"
xbarhtmls = xbarhtmls & "<td align=right width=75><input ' name= ' pagenow ' text ' type= ' id= ' pageNow ' 3 ' ma Xlength= ' 4 ' value= ' "& XPage &" ' style= ' Width:25px;text-align:center; ' Onkeydown=if (event.keycode== ' 13 ') { Location= ' "& Xpageurl &" ' +document.getelementbyid (' Pagenow '). Value}><input type= ' button ' name= ' Submit ' value= ' Go ' onclick=location= ' & Xpageurl & ' +document.getelementbyid (' Pagenow '). value></td > "
xbarhtmls = xbarhtmls & "</TR>"
rem xbarhtmls = xbarhtmls & "<tr><td colspan=" "6" ">processed in" & Lib. Exetime (Startime) & "second (s) </TD></TR>"
xbarhtmls = xbarhtmls & "</TBODY>"
xbarhtmls = xbarhtmls & "</TABLE>"
ElseIf xbar=2 Then
For XI = Xpagestart to Xpageend
If XI = XPage Then
xpagetmp = xpagetmp & "<font color= ' #999999 ' >" & XI & "</font>"
Else
xpagetmp = xpagetmp & "<a href=" & Xpageurl & XI & ">" & XI & "</a>"
End If
Next
XBARHTMLS = ""
xbarhtmls = xbarhtmls & "<table width= ' 98% ' align= ' right ' cellpadding= ' 0 ' >"
xbarhtmls = xbarhtmls & "<TBODY>"
xbarhtmls = xbarhtmls & "<TR>"
xbarhtmls = xbarhtmls & "<td style=" "PADDING-BOTTOM:3PX; padding-top:5px "" ><span class= "Curpage" "title=" "Total" & Xrecordcount & "Records, Minutes" & xpagecount & "page "" >pages "& XPage &"/Total "& Xpagecount &" &nbsp;&nbsp; "& Xrecordcount &" Record ;/span> </TD> "
xbarhtmls = xbarhtmls & "<td align= ' right ' ><a href= '" & Xpageurl & "1 ' > Home </a>"
If xpage>1 Then
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & xPage-1 & "' > Previous </a>"
Else
xbarhtmls = xbarhtmls & "<font color= ' #999999 ' > Prev </font>"
End If
xbarhtmls = xbarhtmls & xpagetmp
If Xpage<xpagecount Then
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & xpage+1 & "' > Next page </a>"
Else
xbarhtmls = xbarhtmls & "<font color= ' #999999 ' > Next </font>"
End If
xbarhtmls = xbarhtmls & "<a href= '" & Xpageurl & Xpagecount & "' > Last </a> </TD>"
xbarhtmls = xbarhtmls & "<td align=right width=75><input ' name= ' pagenow ' text ' type= ' id= ' pageNow ' 3 ' ma Xlength= ' 4 ' value= ' "& XPage &" ' style= ' Width:25px;text-align:center; ' Onkeydown=if (event.keycode== ' 13 ') { Location= ' "& Xpageurl &" ' +document.getelementbyid (' Pagenow '). Value}><input type= ' button ' name= ' Submit ' value= ' Go ' onclick=location= ' & Xpageurl & ' +document.getelementbyid (' Pagenow '). value></td > "
xbarhtmls = xbarhtmls & "</TR>"
xbarhtmls = xbarhtmls & "</TBODY>"
xbarhtmls = xbarhtmls & "</TABLE>"
Else
XBARHTMLS = ""
xbarhtmls = xbarhtmls & "<table width= ' 99% ' border= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' >"
xbarhtmls = xbarhtmls & "<tr>"
xbarhtmls = xbarhtmls & "<td height= ' align= ' right ' > Current <span class= ' Text4 ' >" & xPage & "</s Pan> page &nbsp;&nbsp; total <span class= ' Text4 ' > ' & xpagecount & ' </span>&nbsp;&nbsp; page &nbsp;&nbsp;&nbsp;&nbsp; go to "
xbarhtmls = xbarhtmls & "<select name= ' select6 ' onchange=" "JavaScript Tutorials: location.href= '" & Xpageurl & "' + This.options[this.selectedindex].value "" > "
For Xi=1 to Xpagecount
If xPage = XI Then xselected = "Selected"
xbarhtmls = xbarhtmls & "<option value=" "& XI &" "& Xselected &" > "& XI &" </opti On> "
xselected = ""
Next
xbarhtmls = xbarhtmls & "</select>"
xbarhtmls = xbarhtmls & "Page </td>"
xbarhtmls = xbarhtmls & "</tr>"
xbarhtmls = xbarhtmls & "</table>"
End If
If Isnull (xtmp) Then xbarhtmls = ""
Showbar = xbarhtmls
End Function
End Class
%>