ASP paging class (supports multi-style conversion)

Source: Internet
Author: User


This page uses a 0 cursor, that is, Rs. Open SQL, Conn, 0, 1. But it cannot be much faster. The paging time of 0.1 million pieces of data is between 300 and Hao seconds. CopyCode The Code is as follows: <%
'******************************
'Name: Paging class
'Date: 2005/12/3
'Author: xilou Leng Yue
'URL: www.xilou.net | www.chinacms.org
'Description: None
'Copyright: reprinted, please note the source of the name, author
'******************************
Class page
Private currpage
Private pagen
Private urlstr
Private tempstr
Private errinfo
Private iserr
Private totalrecord
Private totalpage
Public pagers
Private Tempa (11)
Private tempb (8)
'------------------------------------------------------------
Private sub class_initialize ()
Currpage = 1' // by default, the current page is displayed as the first page
Pagen = 10' // 10 data entries per page by default
Urlstr = "#"
Tempstr = ""
Errinfo = "errinfo :"
Iserr = false
End sub
Private sub class_terminate ()
If isobject (pagers) then
Pagers. Close
Set pagers = nothing
End if
Erase Tempa
Erase tempb
End sub
'----------------------------------------------------------
'// Obtain the current page number
Public property let currentpage (VAL)
Currpage = Val
End Property
Public property get currentpage ()
Currentpage = currpage
End Property
'// Obtain the number of entries displayed per page
Public property let pagenum (VAL)
Pagen = Val
End Property
Public property get pagenum ()
Pagenum = pagen
End Property
'// Obtain the URL
Public property let URL (VAL)
Urlstr = Val
End Property
Public property get URL ()
Url = urlstr
End Property
'// Obtain the Template
Public property let temp (VAL)
Tempstr = Val
End Property
Public property get temp ()
Temp = tempstr
End Property
'------------------------------------------------------------
Public sub exec (SQL, connobj)
On Error resume next
Set pagers = server. Createobject ("ADODB. recordset ")
Pagers. cursorlocation = 3' using client cursors improves efficiency
Pagers. pagesize = pagen' defines the number of records displayed on each page in a paging record set.
Pagers. Open SQL, connobj, 0, 1
If err. Number <> 0 then
Err. Clear
Pagers. Close
Set pagers = nothing
Errinfo = errinfo & "An error occurred while creating or opening a record set ..."
Iserr = true
Response. Write errinfo
Response. End
End if
Totalrecord = pagers. recordcount '// What if it is 0?
If totalrecord> = 1 then
'---------------------------------------------------------------------------- Start
'// Calculate the total number of pages and PS. Why not use pagers. pagecount?
'If totalrecord mod pagen = 0 then
'Totalpage = pagers. recordcount \ pagen
'Else
'Totalpage = pagers. recordcount \ pagen
'Totalpage = ABS (INT (totalpage ))
'End if
Totalpage = pagers. pagecount
'// Process the current received page number. The default value is 1. Therefore, all numbers are 1.
If isnumeric (currpage) then
Currpage = clng (currpage)
If currpage <1 then currpage = 1
If currpage> totalpage then currpage = totalpage
Else
'// Dim M: M = "": isnumeric (m) = true
Currpage = 1
End if
'--------------------------------------------------------------------------- End
Else
Totalpage = 0
Currpage = 1
End if
'//
Pagers. absolutepage = currpage 'absolutepage: sets the pointer to start with a page.
Pagers. pagesize = pagen
End sub
Private sub Init ()
'Private Tempa (10)
Tempa (1) = "{N1}" '// Home Page
Tempa (2) = "{N2}" '// Previous Page
Tempa (3) = "{N3}" '// next page
Tempa (4) = "{N4}" '// last page
Tempa (5) = "{N5}" '// current page number
Tempa (6) = "{N6}" '// total page number
Tempa (7) = "{N7}" '// number of entries per page
Tempa (8) = "{n8 }"'// Article Total
Tempa (9) = "{L}" '// cycle label starts
Tempa (10) = "{n}" '// single tag in the Loop: page number
Tempa (11) = "{L/}" '// loop label ends
'Private tempb (8)
Tempb (1) = "Homepage"
Tempb (2) = "Previous Page"
Tempb (3) = "next page"
Tempb (4) = "last page"
Tempb (5) = currpage '// current page number
Tempb (6) = totalpage '// total page number
Tempb (7) = pagen' // number of entries per page
Tempb (8) = totalrecord '// total number of articles
End sub
Public sub show (style)
If iserr = true then
Response. Write errinfo
Exit sub
End if
Call Init ()
Select case style
Case 1
Response. Write stylea ()
Case 2
Response. Write styleb ()
Case 3
Response. Write stylec ()
Case 4
Response. Write styled ()
Case else
Errinfo = errinfo & "the current style does not exist ..."
Response. Write errinfo
End select
End sub
Public Function showstyle (style)
If iserr = true then
Showstyle = errinfo
Exit Function
End if
Call Init ()
Select case style
Case 1
Showstyle = stylea ()
Case 2
Showstyle = styleb ()
Case else
Errinfo = errinfo & "the current style does not exist ..."
Showstyle = errinfo
End select
End Function
Private function stylea ()
'Homepage previous page next page last page this page is page 1/20, 20 pages in total, 10 per page, 200 articles in total
'// Paging example: [homepage] [Previous Page] [Next Page] [last page] [page times: 4/5 page] [86 articles, 20 articles/Page] Go: _ page
'// Tag: {N1} {N2} {N3} {N4} | Total: {n8} records {N6} page is currently {N5} page {N7}
If isempty (tempstr) then
Errinfo = errinfo & "the template is empty ..."
Styleb = errinfo
Exit Function
End if
Dim m
If totalpage> 1 then
If currpage> 1 then
M = "<a href = '" & urlstr & "page = 1'>" & "Homepage" & "</a>"
Tempstr = Replace (tempstr, "{N1}", m)
M = "<a href = '" & urlstr & "page =" & CurrPage-1 & "'>" & "Previous Page" & "</a>"
Tempstr = Replace (tempstr, "{N2}", m)
If currpage <totalpage then
M = "<a href = '" & urlstr & "page =" & currpage + 1 & "'>" & "Next" & "</a>"
Tempstr = Replace (tempstr, "{N3}", m)
M = "<a href = '" & urlstr & "page =" & totalpage & "'>" & "last page" & "</a>"
Tempstr = Replace (tempstr, "{N4}", m)
Else
Tempstr = Replace (tempstr, "{N3}", "Next page ")
Tempstr = Replace (tempstr, "{N4}", "Last page ")
End if
Else
Tempstr = Replace (tempstr, "{N1}", "Homepage ")
Tempstr = Replace (tempstr, "{N2}", "Previous Page ")
M = "<a href = '" & urlstr & "page =" & currpage + 1 & "'>" & "Next" & "</a>"
Tempstr = Replace (tempstr, "{N3}", m)
M = "<a href = '" & urlstr & "page =" & totalpage & "'>" & "last page" & "</a>"
Tempstr = Replace (tempstr, "{N4}", m)
End if
Else
Tempstr = Replace (tempstr, "{N1}", "Homepage ")
Tempstr = Replace (tempstr, "{N2}", "Previous Page ")
Tempstr = Replace (tempstr, "{N3}", "Next page ")
Tempstr = Replace (tempstr, "{N4}", "Last page ")
End if
T = tempstr
T = Replace (T, "{n8}", totalrecord)
T = Replace (T, "{N6}", totalpage)
T = Replace (T, "{N5}", currpage)
T = Replace (T, "{N7}", pagen)
Tempstr = T
Stylea = tempstr
End Function
Private function styleb ()
'Homepage | <1 2 3 4 5 6 7> | last page
'// Tag: {N1} {N2} {L} {n} {L/} {N3} {N4}
If isempty (tempstr) then
Errinfo = errinfo & "the template is empty ..."
Styleb = errinfo
Exit Function
End if
Dim forcenum, backnum' // number of front and back displays on the current page
Forcenum = 5
Backnum = 4
Dim m
'// Homepage
M = "<a href = '" & urlstr & "page = 1'>" & tempb (1) & "</a>"
Tempstr = Replace (tempstr, "{N1}", m)
'// End page
M = "<a href = '" & urlstr & "page =" & tempb (6) & "'>" & tempb (4) & "</a>"
Tempstr = Replace (tempstr, "{N4}", m)
'// Previous Page
M = "| <"
If CurrPage-1> = 1 then
M = "<a href = '" & urlstr & "page =" & CurrPage-1 & "'>" & "| <" & "</a>"
End if
Tempstr = Replace (tempstr, "{N2}", m)
'// The next page
M = "> |"
If currpage + 1 <= totalpage then
M = "<a href = '" & urlstr & "page =" & currpage + 1 & "'>" & "> |" & "</a>"
End if
Tempstr = Replace (tempstr, "{N3}", m)
'// Retrieve the cyclic tag
Dim N1, N2, N3, N4, N5, N6
If instr (tempstr, "{L}")> 0 then
N1 = instr (tempstr, "{L }")
End if
If instr (tempstr, "{L/}")> 0 then
N2 = instr (tempstr, "{L /}")
End if
If N2 <= N1 then
Errinfo = errinfo & "loop tag error ..."
Styleb = errinfo
Exit Function
End if
N3 = mid (tempstr, N1, N2-N1 + 4) '// store the template containing {L} {L/} loop labels
N4 = Replace (N3, "{L}", "") '// store templates that do not contain {L} {L/} loop tags
N4 = Replace (n4, "{L /}","")
'// Page number list
Dim firstpagenum, lastpagenum
If currpage-forcenum <= 1 then
Firstpagenum = 1
Pagelist = ""
Else
Firstpagenum = currpage-forcenum
Pagelist = "......"
End if
If currpage + backnum> = totalpage then
Lastpagenum = totalpage
Pagelist_2 = ""
Else
Lastpagenum = currpage + backnum
Pagelist_2 = "......"
End if
Dim I
For I = firstpagenum to lastpagenum
If I = currpage then
N5 = Replace (n4, "{n}", "<B>" & I & "</B> ")
N6 = N6 & N5
Else
M = "<a href = '" & urlstr & "page =" & I & "'>" & I & "</a>"
N5 = Replace (n4, "{n}", m)
N6 = N6 & N5
End if
Next
Tempstr = Replace (tempstr, N3, N6)
Styleb = tempstr
End Function
Private function stylec ()
'Homepage | <1 2 3 4 5 6 7> | last page
'// This style is modified on the basis of styleb. Two labels are added: 10 {N10} pages on {tags}
'// Tag: {N1} {N2} {region} {L} {n} {L/} {N10} {N3} {N4}
Dim t
T = styleb ()
'// Top 10
M = "| <"
If CurrPage-10> = 1 then
M = "<a href = '" & urlstr & "page =" & CurrPage-10 & "'>" & "| <" & "</a>"
End if
T = Replace (T, "{replacement}", m)
M = ">>|"
If currpage + 10 <= totalpage then
M = "<a href = '" & urlstr & "page =" & currpage + 10 & "'>" & ">>|" &" </a>"
End if
T = Replace (T, "{N10}", m)
Stylec = T
End Function
Private function styled ()
'// This style is modified based on stylec
'// {N8} records {N6} page {N5} page {N7}
'// Homepage | <1 2 3 4 5 6 7> | last page
'// Tag: {N1} {N2} {region} {L} {n} {L/} {N10} {N3} {N4}
Dim t
T = stylec ()
T = Replace (T, "{n8}", totalrecord)
T = Replace (T, "{N6}", totalpage)
T = Replace (T, "{N5}", currpage)
T = Replace (T, "{N7}", pagen)
Styled = T
End Function
End Class
%>
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.