ASP complete pagination class instance utility

Source: Internet
Author: User
Tags min prev servervariables split table name xpage

<%


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=" &amp; Xmiddleindex)


' Response.Write ("&lt;br&gt;")


If xordertype = 1 Then '/ascending


If xpage=1 Then


getsqlstring = "SELECT Top" &amp; Xpagesize &amp; "&amp; Xfields &amp;" from "&amp; Xtablename &amp;" "&amp; Xwher E_ &amp; "ORDER BY" &amp; Xprimarykey &amp; "ASC"


Xflag = "11"


ElseIf 1 &lt; xPage and xPage &lt;= xmiddleindex Then


getsqlstring = "SELECT Top" &amp; Xpagesize &amp; "" &amp; Xfields &amp; "from" &amp; Xtablename &amp; "Where" &amp; Xprimarykey &amp; "&gt; (Select Max (" &amp; Xprimarykey &amp; ") from (select Top &amp; xpagesize* (xPage-1) &amp;" " &amp; Xprimarykey &amp; "from" &amp; Xtablename &amp; "&amp; Xwhere_ &amp;" ORDER BY "&amp; Xprimarykey &amp;" Asc ) TableA) and &amp; Xwhere &amp; "ORDER BY" &amp; Xprimarykey &amp; "ASC"


Xflag = "12"


ElseIf Xmiddleindex &lt; XPage and XPage &lt; Xpagecount Then


getsqlstring = "SELECT * from" (SELECT Top &amp; Xpagesize &amp; "" &amp; Xfields &amp; "from" &amp; Xtablename &amp; "Where" &amp; Xprimarykey &amp; "&lt; (select Min (" &amp; Xprimarykey &amp; ") from (select Top &amp; XRECORDCOUNT-XP) Agesize*xpage &amp; "" &amp; Xprimarykey &amp; "from" &amp; Xtablename &amp; "" &amp; Xwhere_ &amp; "ORDER BY" &amp; Xprimarykey &amp; "Desc) TableA) and" &amp; Xwhere &amp; "ORDER BY" &amp; Xprimarykey &amp; "Desc" TableB Order BY " &amp; Xprimarykey &amp; "ASC"


Xflag = "13"


ElseIf Xpage=xpagecount Then


getsqlstring = "SELECT * from" (SELECT Top &amp; xrecordcount-xpagesize* (xPageCount-1) &amp; "&amp; Xfields &amp;" Fr Om "&amp; Xtablename &amp;" "&amp; Xwhere_ &amp;" ORDER BY "&amp; Xprimarykey &amp;" Desc "TableA Order BY" &amp; X PrimaryKey &amp; "ASC"


Xflag = "14"


End If


Else '//Descending


If xpage=1 Then


getsqlstring = "SELECT Top" &amp; Xpagesize &amp; "&amp; Xfields &amp;" from "&amp; Xtablename &amp;" "&amp; Xwher E_ &amp; "ORDER BY" &amp; Xprimarykey &amp; "Desc"


Xflag = "21"


ElseIf 1 &lt; xPage and xPage &lt;= xmiddleindex Then


getsqlstring = "SELECT Top" &amp; Xpagesize &amp; "" &amp; Xfields &amp; "from" &amp; Xtablename &amp; "Where" &amp; Xprimarykey &amp; "&lt; (select Min (" &amp; Xprimarykey &amp; ") from (select Top &amp; xpagesize* (xPage-1) &amp;" " &amp; Xprimarykey &amp; "from" &amp; Xtablename &amp; "&amp; Xwhere_ &amp;" ORDER BY "&amp; Xprimarykey &amp;" Des c) TableA) and "&amp; Xwhere &amp;" ORDER BY "&amp; Xprimarykey &amp;" Desc "


Xflag = "22"


ElseIf Xmiddleindex &lt; XPage and XPage &lt; Xpagecount Then


getsqlstring = "SELECT * from" (SELECT Top &amp; Xpagesize &amp; "" &amp; Xfields &amp; "from" &amp; Xtablename &amp; "Where" &amp; Xprimarykey &amp; "&gt; (Select Max (" &amp; Xprimarykey &amp; ") from (select Top &amp; XRECORDCOUNT-XP) Agesize*xpage &amp; "" &amp; Xprimarykey &amp; "from" &amp; Xtablename &amp; "" &amp; Xwhere_ &amp; "ORDER BY" &amp; Xprimarykey &amp; "ASC) TableA) and" &amp; Xwhere &amp; "ORDER BY" &amp; Xprimarykey &amp; "ASC" TableB Order By "& Amp Xprimarykey &amp; "Desc"


Xflag = "23"


ElseIf Xpage=xpagecount Then


getsqlstring = "SELECT * from" (SELECT Top &amp; xrecordcount-xpagesize* (xPageCount-1) &amp; "&amp; Xfields &amp;" Fr Om "&amp; Xtablename &amp;" "&amp; Xwhere_ &amp;" ORDER BY "&amp; Xprimarykey &amp;" ASC "as TableA Order BY" &amp; Xprimarykey &amp; "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) &lt;&gt; "" Then pageurl = pageurl + Request.Form


'--end


If pageurl &lt;&gt; "" Then


If InStr (pageurl,pagestr) &gt;0 Then


If InStr (Pageurl, "&amp;") &gt;0 Then


Tempurl = Split (Pageurl, "&amp;")


Pageurl = ""


For T = 0 to Ubound (tempurl)


If InStr (Tempurl (T), pagestr) =0 Then


Pageurl = Pageurl &amp; "&amp;" &amp; Tempurl (T)


End If


Next


Pageurl = Right (Pageurl,len (Pageurl)-1)


Resulturl = FileName &amp; "?" &amp; Pageurl &amp; "&amp;page="


Else


Resulturl = FileName &amp; "? page="


End If


Else


Resulturl = FileName &amp; "?" &amp; Pageurl &amp; "&amp;page="


End If


Else


Resulturl = FileName &amp; "? 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&lt;10 and Xpagecount&gt;0 Then


Xpagestart = 1


Xpageend = Xpagecount


Else


Xpagestart = xPage-5


Xpageend = xpage+4


If xpagestart&lt;=0 Then


Xpagestart = 1


Xpageend = 10


End If


If Xpageend&gt;=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 &amp; "&lt;font color= ' #999999 ' &gt;" &amp; XI &amp; "&lt;/font&gt;"


Else


xpagetmp = xpagetmp &amp; "&lt;a href=" &amp; Xpageurl &amp; XI &amp; "&gt;" &amp; XI &amp; "&lt;/a&gt;"


End If


Next


XBARHTMLS = ""


xbarhtmls = xbarhtmls &amp; "&lt;table width= ' 100% ' align= ' right ' cellpadding= ' 0 ' &gt;"


xbarhtmls = xbarhtmls &amp; "&lt;TBODY&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;TR&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td width= ' 35% ' &gt; Total &amp;nbsp;" &amp; xpagecount &amp; "Page &amp;nbsp;&amp;nbsp;" &amp; Xrec Ordcount &amp; "Records &amp;nbsp;&amp;nbsp; current" &amp; xPage &amp; "Page &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td align= ' right ' &gt;&lt;a href= '" &amp; Xpageurl &amp; "1 ' &gt; Home &lt;/a&gt;"


If xpage&gt;1 Then


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; xPage-1 &amp; "' &gt; Previous &lt;/a&gt;"


Else


xbarhtmls = xbarhtmls &amp; "&lt;font color= ' #999999 ' &gt; Prev &lt;/font&gt;"


End If


xbarhtmls = xbarhtmls &amp; xpagetmp


If Xpage&lt;xpagecount Then


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; xpage+1 &amp; "' &gt; Next page &lt;/a&gt;"


Else


xbarhtmls = xbarhtmls &amp; "&lt;font color= ' #999999 ' &gt; Next &lt;/font&gt;"


End If


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; Xpagecount &amp; "' &gt; Last &lt;/a&gt; &lt;/TD&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td align=right width=75&gt;&lt;input ' name= ' pagenow ' text ' type= ' id= ' pageNow ' 3 ' ma Xlength= ' 4 ' value= ' "&amp; XPage &amp;" ' style= ' Width:25px;text-align:center; ' Onkeydown=if (event.keycode== ' 13 ') { Location= ' "&amp; Xpageurl &amp;" ' +document.getelementbyid (' Pagenow '). Value}&gt;&lt;input type= ' button ' name= ' Submit ' value= ' Go ' onclick=location= ' &amp; Xpageurl &amp; ' +document.getelementbyid (' Pagenow '). value&gt;&lt;/td &gt; "


xbarhtmls = xbarhtmls &amp; "&lt;/TR&gt;"


rem xbarhtmls = xbarhtmls &amp; "&lt;tr&gt;&lt;td colspan=" "6" "&gt;processed in" &amp; Lib. Exetime (Startime) &amp; "second (s) &lt;/TD&gt;&lt;/TR&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/TBODY&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/TABLE&gt;"





ElseIf xbar=2 Then


For XI = Xpagestart to Xpageend


If XI = XPage Then


xpagetmp = xpagetmp &amp; "&lt;font color= ' #999999 ' &gt;" &amp; XI &amp; "&lt;/font&gt;"


Else


xpagetmp = xpagetmp &amp; "&lt;a href=" &amp; Xpageurl &amp; XI &amp; "&gt;" &amp; XI &amp; "&lt;/a&gt;"


End If


Next


XBARHTMLS = ""


xbarhtmls = xbarhtmls &amp; "&lt;table width= ' 98% ' align= ' right ' cellpadding= ' 0 ' &gt;"


xbarhtmls = xbarhtmls &amp; "&lt;TBODY&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;TR&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td style=" "PADDING-BOTTOM:3PX; padding-top:5px "" &gt;&lt;span class= "Curpage" "title=" "Total" &amp; Xrecordcount &amp; "Records, Minutes" &amp; xpagecount &amp; "page "" &gt;pages "&amp; XPage &amp;"/Total "&amp; Xpagecount &amp;" &amp;nbsp;&amp;nbsp; "&amp; Xrecordcount &amp;" Record ;/span&gt; &lt;/TD&gt; "


xbarhtmls = xbarhtmls &amp; "&lt;td align= ' right ' &gt;&lt;a href= '" &amp; Xpageurl &amp; "1 ' &gt; Home &lt;/a&gt;"


If xpage&gt;1 Then


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; xPage-1 &amp; "' &gt; Previous &lt;/a&gt;"


Else


xbarhtmls = xbarhtmls &amp; "&lt;font color= ' #999999 ' &gt; Prev &lt;/font&gt;"


End If


xbarhtmls = xbarhtmls &amp; xpagetmp


If Xpage&lt;xpagecount Then


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; xpage+1 &amp; "' &gt; Next page &lt;/a&gt;"


Else


xbarhtmls = xbarhtmls &amp; "&lt;font color= ' #999999 ' &gt; Next &lt;/font&gt;"


End If


xbarhtmls = xbarhtmls &amp; "&lt;a href= '" &amp; Xpageurl &amp; Xpagecount &amp; "' &gt; Last &lt;/a&gt; &lt;/TD&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td align=right width=75&gt;&lt;input ' name= ' pagenow ' text ' type= ' id= ' pageNow ' 3 ' ma Xlength= ' 4 ' value= ' "&amp; XPage &amp;" ' style= ' Width:25px;text-align:center; ' Onkeydown=if (event.keycode== ' 13 ') { Location= ' "&amp; Xpageurl &amp;" ' +document.getelementbyid (' Pagenow '). Value}&gt;&lt;input type= ' button ' name= ' Submit ' value= ' Go ' onclick=location= ' &amp; Xpageurl &amp; ' +document.getelementbyid (' Pagenow '). value&gt;&lt;/td &gt; "


xbarhtmls = xbarhtmls &amp; "&lt;/TR&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/TBODY&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/TABLE&gt;"


Else


XBARHTMLS = ""


xbarhtmls = xbarhtmls &amp; "&lt;table width= ' 99% ' border= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' &gt;"


xbarhtmls = xbarhtmls &amp; "&lt;tr&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;td height= ' align= ' right ' &gt; Current &lt;span class= ' Text4 ' &gt;" &amp; xPage &amp; "&lt;/s Pan&gt; page &amp;nbsp;&amp;nbsp; total &lt;span class= ' Text4 ' &gt; ' &amp; xpagecount &amp; ' &lt;/span&gt;&amp;nbsp;&amp;nbsp; page &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; go to "


xbarhtmls = xbarhtmls &amp; "&lt;select name= ' select6 ' onchange=" "JavaScript Tutorials: location.href= '" &amp; Xpageurl &amp; "' + This.options[this.selectedindex].value "" &gt; "


For Xi=1 to Xpagecount


If xPage = XI Then xselected = "Selected"


xbarhtmls = xbarhtmls &amp; "&lt;option value=" "&amp; XI &amp;" "&amp; Xselected &amp;" &gt; "&amp; XI &amp;" &lt;/opti On&gt; "


xselected = ""


Next


xbarhtmls = xbarhtmls &amp; "&lt;/select&gt;"


xbarhtmls = xbarhtmls &amp; "Page &lt;/td&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/tr&gt;"


xbarhtmls = xbarhtmls &amp; "&lt;/table&gt;"


End If


If Isnull (xtmp) Then xbarhtmls = ""


Showbar = xbarhtmls


End Function





End Class


%&gt;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.