ASP generic paging class 1.2.24

Source: Internet
Author: User
Tags servervariables

This ASP generic paging class is mainly easy to use. The speed depends on the actual application: the total number of records automatically used for cookies cache; if the Statistical Statement (strsqlcount attribute) is specified, it depends on the statistical efficiency of the statement; if the statistical statement is not specified, the value of the recordcount attribute is obtained based on the query statement specified by the user. Of course, when the homepage is displayed, the speed depends on the total number of records and the efficiency is not high. if you encounter problems in the application, use MSN to contact me: xiaoyuehen (AT) msn.com

Applicability:

1. For general paging requirements, you only need to specify the query statement and several other main parameters for ease of use.
2. The speed of paging depends on the efficiency of SQL statement execution.
3. You can specify statistical statements for the number of records to reduce the statistical time.
4. Automatically cache the number of records to speed up inter-page Jump.
5. If the keyword of the query statement changes frequently, it is set to not cached to avoid affecting the query result.
6. If you do not like the paging navigation generated by the class, you can obtain other attributes and set the navigation style by yourself.

Related attributes:

Strsql: Write only (required), query statement

Strpageurl: Write-only (required), redirection address

Strsqlcount: writable, number of records Statistical Statement

Intpagenow: readable/writeable (required) to obtain the current page/set the current page

Objconn: Write-only (required), an opened database connection object. You only need to set it once when it is used for multiple times.

Getarray: Read-only, used to obtain the current page record in the form of a two-dimensional array. It must be determined using the isarray () method.

Getrecordset: Read-Only. Get Record set object. The cursor is located on the current page.

Intpagemax: Read-only, get the total number of pages

Strpageinfo: Read-only, get the default paging Style

Intrecordcount: Read-only, get the total number of current records

Intcache: Indicates whether to cache the number of records (cookies) that can be written. The default value is cache. If no data is cached, it must be set to 0.

Strpagevar: writable. It sets page transfer parameters. The default value is "page"

Intpagesize: writable. The number of records per page is displayed. The default value is 20.

Class file:

<%
Rem *************************************** *********
Rem ** by xiaoyuehen)
Rem ** ASP generic paging class
Rem ** version: 1.2.24
Rem ** last modified: 2006-5-20
Rem ** contact Author: xiaoyuehen (AT) msn.com
Rem *************************************** *********

Class cls_pageview
Private sbooinitstate
Private sstrpageurl
Private sstrpagevar
Private sstrsql
Private sstrsqlcount
Private sintcache

Private sintrecordcount
Private sintpagesize
Private sintpagenow
Private sintpagemax

Private sobjconn

Private sstrpageinfo

Private sobjrs, sbooinitrecordset

Rem # SQL statements
Public property let strsql (value)
'When the value is assigned again, all parameters are reset.
Call clearvars ()
Sstrsql = Value
End Property

Rem # SQL statements
Public property let strsqlcount (value)
Sstrsqlcount = Value
End Property

Rem # redirection address
Public property let strpageurl (value)
Sstrpageurl = Value
End Property

Rem # Whether to cache the total number of records
Public property let intcache (value)
Sintcache = tonum (value, 1)
End Property

Rem # number of records displayed per page
Public property let intpagesize (value)
Sintpagesize = tonum (value, 20)
End Property

Rem # database connection object
Public property let objconn (value)
Set sobjconn = Value
End Property

Rem # set page Parameters
Public property let strpagevar (value)
Sstrpagevar = Value
End Property

Rem # set the current page
Public property let intpagenow (value)
Sintpagenow = tonum (value, 1)
End Property

Rem # obtain the current page
Public property get intpagenow ()
Intpagenow = sintpagenow
End Property

Rem # obtain the current page
Public property get intpagemax ()
Intpagemax = sintpagemax
End Property

Rem # obtain the total number of records
Public property get intrecordcount ()
Intrecordcount = sintrecordcount
End Property

Rem # default page information
Public property get strpageinfo ()
Strpageinfo = sstrpageinfo
End Property

Private sub class_initialize

End sub

Private sub class_terminate ()
Set sobjconn = nothing
End sub

Private sub clearvars ()
Sbooinitstate = false
Sstrpageurl = ""
Sstrpagevar = "page"
Sintcache = 1

Sintpagesize = 20
Sintpagenow = 1
Sintpagemax = 1
Sintrecordcount =-1
Sbooinitrecordset = false
End sub

Rem # initialize paging information
Private sub initpageinfo ()
If sintpagenow <= 0 then sintpagenow = 1
If sintrecordcount mod sintpagesize = 0 then
Sintpagemax = sintrecordcount/sintpagesize
Else
Sintpagemax = sintrecordcount/sintpagesize + 1
End if
If sintpagenow> sintpagemax then sintpagenow = sintpagemax

Sstrpageinfo = ""

Dim Surl
Surl = sstrpageurl
If Surl = "" Then exit sub

If instr (1, Surl ,"? ", 1)> 0 then
Surl = Surl & "&" & sstrpagevar & "="
Else
Surl = Surl &"? "& Sstrpagevar &" ="
End if

If sintpagenow <= 1 then
Sstrpageinfo = "homepage previous"
Else
Sstrpageinfo = sstrpageinfo & "<a href =" & Surl & "1"> homepage </a>"
Sstrpageinfo = sstrpageinfo & "<a href =" & Surl & (sintpagenow-1) & ""> previous page </a>"
End if

If sintpagemax-sintpagenow <1 then
Sstrpageinfo = sstrpageinfo & "last page of the next page"
Else
Sstrpageinfo = sstrpageinfo & "<a href =" & Surl & (sintpagenow + 1) & ""> next page </a>"
Sstrpageinfo = sstrpageinfo & "<a href =" & Surl & sintpagemax & ""> last page </a>"
End if

Sstrpageinfo = sstrpageinfo & "Page: <strong> <font color = "" #990000 ""> "& sintpagenow &" </font>/"& sintpagemax &" </strong>"
Sstrpageinfo = sstrpageinfo & "Total <strong>" & sintrecordcount & "</strong> records <strong>" & sintpagesize & "</strong> entries/page"
End sub

Rem # Long Integer Conversion
Private function tonum (S, default)
S = S &""
If S <> "" And isnumeric (s) then
Tonum = clng (s)
Else
Tonum = default
End if
End Function

Rem # retrieve record count cookies
Private function initrecordcountcache ()
Dim intrecordcount
Intrecordcount = tonum (request. Cookies ("sys_cls_pageview_record_count"), 0)
If intrecordcount> 0 then
Sintrecordcount = intrecordcount
End if
End Function

Rem # stored record count cookies
Rem # Run the command only when the source page is different from the current page
Private function setrecordcountcache ()
If (sintrecordcount> 0) then
Response. Cookies ("sys_cls_pageview_record_count") = sintrecordcount
End if
End Function

Rem # determine if different pages are from
Private function referpagewascurrentpage ()
Referpagewascurrentpage = true

Dim strrefer, strcurrent
Strrefer = request. servervariables ("http_referer ")
Strrefer = Replace (strrefer ,"/","/")
Strcurrent = request. servervariables ("script_name ")
If (strrefer <> "") and (instr (1, strrefer, strcurrent, 1)> 0) Then exit function

Referpagewascurrentpage = false
End Function

Rem ## class initialization
Private sub initclass ()
Sbooinitstate = true
If not (isobject (sobjconn) then
Sbooinitstate = false

Response. Write ("database connection not specified ")
Response. End ()
End if
If trim (sstrsql) = "" then
Sbooinitstate = false

Response. Write ("SQL statement not specified ")
Response. End ()
End if
Sintpagesize = tonum (sintpagesize, 20)
If (sintpagesize <1) or (sintpagesize> 100) then
Sbooinitstate = false

Response. Write ("the number of records per page is not set or does not comply with the rules (1-100 )")
Response. End ()
End if
Sintpagenow = tonum (sintpagenow, 1)
End sub

Rem # initialize record set object
Private sub initrecordset ()
Call initclass ()
If not sbooinitstate then
Response. Write ("Paging class initialization failed. Please check the parameters ")
Exit sub
End if

Total number of cache records read by Rem
Call initrecordcountcache ()

Dim RS, SQL, breferiscurrent
Breferiscurrent = referpagewascurrentpage ()
SQL = sstrsql

Set rs = server. Createobject ("ADODB. recordset ")

If REM transfers records from other pages or does not cache records, re-count
If (breferiscurrent = false) or (sintrecordcount <0) or (sintcache = 0) and (sstrsqlcount <> "") then
Rs. Open sstrsqlcount, sobjconn, 1, 1
If not (Rs. EOF or Rs. bof) then
Sintrecordcount = RS (0)
Else
Sintrecordcount = 0
End if
Rs. Close
End if

Rem # use client cursor
Rem ## if this statement is not added, if the last page contains only one record
Rem # Is not displayed ..
Rem # But the acceleration slows down n more ..:(
'Rs. cursorlocation = 3
Rs. Open SQL, sobjconn, 1, 1, 1

Rem is derived from the recordcount attribute of the record set if no record statistics statement is set and no total record count is set.
If sintrecordcount <0 then
Sintrecordcount = Rs. recordcount
End if
If sintrecordcount <0 then sintrecordcount = 0

'Generate paging information
Call initpageinfo ()

If not (Rs. EOF or Rs. bof) then
Rs. pagesize = sintpagesize
Rs. absolutepage = sintpagenow
Set sobjrs = rs
Else
Sobjrs = NULL
End if

Rem # Total number of cache records
If sintcache <> 0 then
Call setrecordcountcache ()
End if

Sbooinitrecordset = true
End sub

Public property get getrecordset ()
If sbooinitrecordset = false then
Call initrecordset ()
End if

If isnull (sobjrs) then
Getrecordset = NULL
Else
Set getrecordset = sobjrs
End if
End Property

Public property get getarray ()
If sbooinitrecordset = false then
Call initrecordset ()
End if

Rem # Release sobjrs when this attribute is obtained
If not isnull (sobjrs) then
If not (sobjrs. EOF or sobjrs. bof) then
Getarray = sobjrs. getrows (sintpagesize)
Else
Getarray = ""
End if
Sobjrs. Close
Set sobjrs = nothing

Rem # Set initialization indication no
Rem # so that when the user calls getrecordset again, It is null.
Sbooinitrecordset = false
Else
Getarray = ""
End if
End Property
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.