ASP + Oracle paging program class (xdownpage2.0)

Source: Internet
Author: User

Original: zykj2000
Email: zykj_2000@163.net
BBS: http://bbs.513soft.net

Upgraded by doublel
Email:
Blog: http://blog.csdn.net/doublel/

Upgradeer: northsnow
Email: northsnow@163.com
Blog: http://blog.csdn.net/precipitant

First, the source code of the paging class will be sent up, and then some instances will be sent to explain its usage and how to expand its functions.

The original class code is as follows:

<%
'================================================ ====================================
'Xdownpage ASP version
'Current version: 2.0
'
'
'Original Version 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'Bbs: http://bbs.513soft.net
'
'
'Upgrade version: 1.5 (ASP + Oracle)
Updated by doublel
Email:
Blog: ttp: // blog.csdn.net/doublel/
'Upgrade description:
'
'
'Upgrade version: 100' (ASP + Oracle) ----> current version
'Retain Original Name: xdownpage
Updated by northsnow
'Email: northsnow@163.com
'Blog: http://blog.csdn.net/precipitant
'Upgrade description:
'1. Only the records on the current page are queried during data query, which greatly reduces the data transmission volume.
'2. If the page navigation is normal, you do not need to query the total number of records each time. After the first query, you can pass the parameters.
'3. Support dynamic page size change
'4, supports dynamic sorting
'5. This program only supports oracle. If you want to use SQL Server or other types of databases, you can modify it as public property let getsql (str_ SQL.
'
'
'The other program modifier information, please check in the source code !!!
'The program can be used, modified, copied, reproduced, and referenced for free. I hope my program will be convenient for your work.
'However, keep the above information, especially the original information. In addition, for commercial purposes, please upgrade with the original and this version
Contact a person to obtain a license.
'
'
'Program features
'The program encapsulates the data paging part, and the data display part is completely customized by the user,
'Multiple URL parameters are supported.
'
'Instructions for use
'Program parameter description
'Papgesize defines the number of records per page.
'Getrs returns the paged recordset. This attribute is read-only.
'Getconn get database connection
'Getsql: query statement obtained
'Totalrecordcount total number of records passed

'Program Method description
'Showpage display pagination navigation bar, the only public Method
'Showpagesizechange () display the list of page sizes changed
'
'Example:
'
''Contains files
'
'Set mypage = new xdownpage' create object
'Mypage. getconn = conn' to get the database connection
'Mypage. getsql = "select * From productinfo order by id asc"
'Mypage. pagesize = 5' sets the number of records on each page to 5
'Mypage. totalrecordcount = rstotalcount
'Set rs = mypage. getrs () 'returns recordset
'Mypage. getsubmitform = "frmquery" 'default page submitted form, currentpage Parameter
'Response. Write (mypage. getsubmitform1 () 'outputs the paging submission function.
'Mypage. showpage () 'displays page information. This method can be used after set rs = mypage. getrs ()
'Call at any location, which can be called multiple times
'Do while not Rs. EOF 'the subsequent operations are the same as operations on a common recordset object.
'Response. Write RS (0 )&"
'"' Here you can customize the display mode.
'Rs. movenext
'Loop
'
'Added a script to save the current page quantity.
'The function is getsubmitform ()
'You need to submit a form name to the function getsubmitform.
'Save the variables flag, currentpage, pagesize, and rstotalcount in the submitted form.
'Example:
'Flag = request ("flag ")
'Currentpage = request ("currentpage ")
'Currentpage = request ("pagesize ")
'Currentpage = request ("rstotalcount ")
'Add the following four inputs to the submitted Form:
'<Input name = "flag" type = "hidden" value = "<% = Flag %>">
'<Input name = "currentpage" type = "hidden" value = "<% = currentpage %>">
'<Input name = "pagesize" type = "hidden" value = "<% = pagesize %>">
'<Input name = "rstotalcount" type = "hidden" value = "<% = rstotalcount %>">
'================================================ ====================================

Const btn_first = "<font face =" "webdings"> 9 </font> "'defines the display style of the button on the first page.
Const btn_prev = "<font face =" "webdings"> 3 </font> "'defines the display style of buttons on the previous page.
Const btn_next = "<font face =" "webdings"> 4 </font> "'defines the display style of the next page button
Const btn_last = "<font face =" "webdings" >:</font> "'defines the button display style on the last page.
Const xd_align = "center" 'defines the page information alignment Mode
Const xd_width = "100%" 'defines the size of the page information box
Const xd_height = "20"

Class xdownpage class starts from here

'Variable definition
Total number of public int_totalpage pages
Public int_curcount 'number of records on the current page
Public xd_pagesize 'page size
Private int_curpage 'current page number
Total number of private int_totalrecord records
Private xd_conn' database connection object
Private xd_rs 'record set object
Private xd_ SQL 'Primary SQL statement
Private xd_count_ SQL 'SQL statement for querying the total number of records
Private str_errors
Private str_url
Private xd_surl
Name of the query form required by private submitform (hiding the form name)

'================================================ ======================================
'Pagesize Property
'Set the page size for each page
'================================================ ======================================
Public property let pagesize (int_pagesize)
If isnumeric (int_pagesize) then
If clng (int_pagesize)> 0 then
Xd_pagesize = clng (int_pagesize)
Else
Xd_pagesize = 10
End if
Else
Xd_pagesize = 10
End if
End Property

Public property get pagesize
If xd_pagesize = "" or (not (isnumeric (xd_pagesize) then
Pagesize = 10
Else
Pagesize = xd_pagesize
End if
End Property

'================================================ ======================================
'Getrs attributes
'Return the record set after pagination
'================================================ ======================================
Public property get getrs ()
Set xd_rs = server. Createobject ("ADODB. recordset ")
'Xd _ rs. pagesize = pagesize
Xd_rs.cursorlocation = 3
Xd_rs.open xd_ SQL, xd_conn, 3, 1
Int_curcount = xd_rs.recordcount
If int_totalrecord = "" or not isnumeric (int_totalrecord) Then int_totalrecord = 0' normalize the value of int_totalrecord
If int_totalrecord = 0 and (int_curcount> = pagesize or int_curpage> 1) then call queryrscount () 'queries the total number of records
If err. Number <> 0 then
Response. Write err. Clear
End if
Set getrs = xd_rs
End Property

'================================================ ======================================
'Queryrscount Method
'Query the total number of records
'================================================ ======================================
Public sub queryrscount ()
'Use the following code to calculate the total number of records
If xd_count_ SQL <> "then
Set rs_sqlcount = server. Createobject ("ADODB. recordset ")
Rs_sqlcount.cursorlocation = 3
Rs_sqlcount.open xd_count_ SQL, Conn, 3, 1
If (rs_sqlcount.eof and rs_sqlcount.bof) then
Int_totalrecord = 0
Else
Int_totalrecord = rs_sqlcount (0)
Int_totalrecord = clng (int_totalrecord)
End if
Rs_sqlcount.close
Set rs_sqlcount = nothing
End if
End sub

'================================================ ======================================
'Getconn get database connection
'
'================================================ ======================================
Public property let getconn (obj_conn)
Set xd_conn = obj_conn
End Property

'================================================ ======================================
'Getsql: query statement obtained
'
'================================================ ======================================
Public property let getsql (str_ SQL)
If (str_ SQL <> "") then
'Generate the final query statement based on the given query statement (only the content on the current page): Applicable to Oracle databases
Xd_ SQL = "select * from (select rownum R_N, temptable. * from ("
Xd_ SQL = xd_ SQL & str_ SQL
Xd_ SQL = xd_ SQL & ") temptable) Where R_N between" & CSTR (int_curpage-1) * xd_pagesize + 1) & "and" & CSTR (int_curpage * xd_pagesize)
'Query statement for the total number of records
Xd_count_ SQL = "select count (*) from (" & str_ SQL &")"
End if
End Property

'================================================ ======================================
'Getsubmitform attributes: Form for setting query Conditions
'
'================================================ ======================================

Public property let getsubmitform (frmname)
Submitform = trim (frmname)
End Property

'================================================ ======================================
The 'getsubmitform1 method outputs the scripts required for paging navigation.
'
'================================================ ======================================
Public sub getsubmitform1 ()
'Page navigation JavaScript Functions
Response. Write "" + vrcrlf
Response. Write ("<script language =" "JavaScript"> ") + vbcrlf
Response. Write "function generalsubmit (I)" + vbcrlf
Response. Write "{" + vbcrlf
Response. Write "document." & submitform & ". Flag. value =" "query1111111155555"; "+ vbcrlf
Response. Write "document." & submitform & ". currentpage. value = I;" + vbcrlf
Response. Write "" & submitform & ". Submit ();" + vbcrlf

Response. Write "}" + vbcrlf

'Javascript function for changing page size
Response. Write "function changepagesize (ii)" + vbcrlf
Response. Write "{" + vbcrlf
Response. Write "document." & submitform & ". Flag. value =" "query1111111155555"; "+ vbcrlf
Response. Write "document." & submitform & ". currentpage. value = 1;" + vbcrlf
Response. Write "document." & submitform & ". pagesize. value = II;" + vbcrlf
Response. Write "" & submitform & ". Submit ();" + vbcrlf

Response. Write "}" + vbcrlf
Response. Write ("</SCRIPT>") + vbcrlf
Response. Write "" + vrcrlf
End sub

'================================================ ======================================
'Totalrecordcount Property
'Total number of records
'
'================================================ ======================================

Public property let totalrecordcount (int_totalrecordcount)
If isnumeric (int_totalrecordcount) then
Int_totalrecord = clng (int_totalrecordcount)
End if
End Property

Public property get totalrecordcount
If not (int_totalrecord = "" or (not (isnumeric (int_totalrecord) then
Totalrecordcount = int_totalrecord
End if
End Property
'================================================ ======================================
'Getrecordcount Method
'Number of returned records
'
'================================================ ======================================
Public Function getrecordcount ()
Getrecordcount = int_totalrecord
End Function
'================================================ ======================================
'Class _ initialize class initialization
'Initialize the value of the current page
'
'================================================ ======================================
Private sub class_initialize
'====================================
'Set the token value for some parameters
'====================================
'Xd_pagesize = 10' sets the default page size to 10.
'====================================
'Get the current value
'====================================
If request ("currentpage") = "" then
Int_curpage = 1
Elseif not (isnumeric (Request ("currentpage") then
Int_curpage = 1
Elseif CINT (TRIM (Request ("currentpage") <1 then
Int_curpage = 1
Else
Int_curpage = CINT (TRIM (Request ("currentpage ")))
End if

End sub

'================================================ ==================================
'Showpage creates a paging navigation bar
'The Home Page, Previous Page, next page, last page, and digital navigation
'
'================================================ ==================================
Public sub showpage ()
Dim str_tmp
Xd_surl = geturl ()
'Int_totalrecord = xd_rs.recordcount
If int_totalrecord <= 0 then
Str_error = str_error & "the total number of records is zero. Please input data"
Call showerror ()
End if
If int_totalrecord = "" then
Int_totalpage = 1
Else

'Modify by WLS 041215 for the right pages display ---------------
If int_totalrecord mod pagesize = 0 then
Int_totalpage = clng (int_totalrecord/xd_pagesize *-1) *-1
Else
Int_totalpage = clng (int_totalrecord/xd_pagesize *-1) *-1 + 1
End if

End if

If int_curpage> int_totalpage then
Int_curpage = int_totalpage
End if

'================================================ ==========================================================
'Display paging information. Each module can change the explicit position as required.
'================================================ ==========================================================
'Response. Write ""
Str_tmp = showfirstprv
Response. Write str_tmp
Str_tmp = shownumbtn
Response. Write str_tmp
Str_tmp = shownextlast
Response. Write str_tmp
Str_tmp = showpageinfo
Response. Write str_tmp
Response. Write "& nbsp ;"
Showgoto

End sub

'================================================ ==================================
'Showfirstprv: display the home page and the previous page
'
'
'================================================ ==================================
Private function showfirstprv ()
Dim str_tmp, int_prvpage

If int_curpage = 1 then
Str_tmp = btn_first & "& btn_prev
Elseif int_curpage = 0 then
Str_tmp = btn_first & "& btn_prev
Else
Int_prvpage = int_curpage-1
Str_tmp = "<a href =" "#" "onclick =" "javascript: generalsubmit ('1 ') "" alt = "" Page 1 ""> "& btn_first &" </a> <a href = "#" "onclick =" "javascript: generalsubmit ('"& int_prvpage &"') "" alt = "" Previous Page ">" & btn_prev & "</a>"
End if
Showfirstprv = str_tmp
End Function

'================================================ ==================================
'Shownextlast next and last pages
'
'
'================================================ ==================================
Private function shownextlast ()
Dim str_tmp, int_nextpage

If int_curpage> = int_totalpage then
Str_tmp = btn_next & "& btn_last
Else
Int_nextpage = int_curpage + 1
Str_tmp = "<a href =" # "" onclick = "" javascript: generalsubmit ('"& int_nextpage &"') "" alt = "" next page ""> "& btn_next &" </a> <a href = "" # "" onclick = "" javascript: generalsubmit ('"& int_totalpage &"') "" alt = "" last page ">" & btn_last & "</a>"
End if
Shownextlast = str_tmp
End Function

'End Function
'================================================ ==================================
'Shownumbtn: Digital navigation after modification
'
'================================================ ==================================
Function shownumbtn ()
Dim I, str_tmp, end_page, start_page

Start_page = 1
'Add by sll 2005.05.20 int_curpage = 0
If int_curpage = 0 then
Str_tmp = str_tmp & "0"
Else
If int_curpage> 1 then
Start_page = int_curpage
If (int_curpage <= 5) then
Start_page = 1
End if
If (int_curpage> 5) then
Start_page = int_curpage-2
End if
End if
End_page = start_page + 5
If end_page> int_totalpage then
End_page = int_totalpage
End if
For I = start_page to end_page
Strtemp = xd_surl & CSTR (I)
Str_tmp = str_tmp & "[<a href =" "#" "onclick =" "javascript: generalsubmit ('" & I &"') ""> "& I &" </a>]"
Next
End if
Shownumbtn = str_tmp
End Function

'================================================ ==================================
'Showgoto page Jump
'Automatic page Jump
'Add by sll 2005.05.20
'================================================ ==================================
Private function showgoto ()
'Response. Write int_totalpage
Dim Inti
If int_totalpage <= 0 then

Response. Write "<select name = 'Goto 'disabled>"
Response. Write "<option value = '0'> 0 </option>"
Response. Write "</SELECT>"
Else

Response. Write "<select name = 'Goto 'onchange = 'javascript: generalsubmit (this. Value) '>"

For Inti = 1 to int_totalpage

Response. Write "<option value = '" & Inti &"'"
If CSTR (INTI) = CSTR (int_curpage) then
Response. Write "selected"
End if
Response. Write ">" & Inti & "</option>"
Next
Response. Write "</SELECT>"
End if
End Function

'================================================ ==================================
'Showpageinfo page information
'Modify as required
'
'================================================ ==================================
Private function showpageinfo ()
Dim str_tmp
Str_tmp = "[page times: <font color = Red> "& int_curpage &" </font>/"& int_totalpage &" Page] [total "& int_totalrecord &"] ["& xd_pagesize/ page]"
Showpageinfo = str_tmp
End Function
'================================================ ==================================
'Showpagesizechange change page size
'Modify as required
'
'================================================ ==================================
Public sub showpagesizechange ()
Dim str_tmp
Str_tmp = "page size: <select name = 'ssssspagesize 'onchange = 'changepagesize (this. Value) '>"
Str_tmp = str_tmp & "<option"
If xd_pagesize = 10 then str_tmp = str_tmp & "selected"
Str_tmp = str_tmp & "value = '10'> 10 </option>"
Str_tmp = str_tmp & "<option"
If xd_pagesize = 20 then str_tmp = str_tmp & "selected"
Str_tmp = str_tmp & "value = '20'> 20 </option>"
Str_tmp = str_tmp & "<option"
If xd_pagesize = 50 then str_tmp = str_tmp & "selected"
Str_tmp = str_tmp & "value = '50'> 50 </option>"
Str_tmp = str_tmp & "<option"
If xd_pagesize = int_totalrecord then str_tmp = str_tmp & "selected"
Str_tmp = str_tmp & "value = '" & int_totalrecord & "'> all </option>"
Str_tmp = str_tmp & "</SELECT>"
Response. Write str_tmp
End sub

'================================================ ==================================
'Modified function for getting the current URL parameter
'Codeing by redsun
'Northsnow annotation: do not know where to use it, but keep it
'================================================ ==================================
Private function geturl ()
Dim scriptaddress, m_itemurl, m_item
Scriptaddress = CSTR (request. servervariables ("script_name "))&"? "'Get the current address
If (request. querystring <> "") then
M_itemurl = ""
For each m_item in request. querystring
If instr ("page", m_item) = 0 then
M_itemurl = m_itemurl & m_item & "=" & server. urlencode (request. querystring ("" & m_item &""))&"&"
End if
Next
Scriptaddress = scriptaddress & m_itemurl 'Get the address with Parameters
End if
Geturl = scriptaddress '& "page ="
End Function

'================================================ ==================================
'Set the terminate event.
'================================================ ==================================
Private sub class_terminate
'Xd _ rs. Close
'Set xd_rs = nothing
End sub

'================================================ ==================================
'Showerror error message
'================================================ ==================================
Private sub showerror ()
If str_error <> "" then
Response. Write ("" & sw_error &"")
Response. End
End if
End sub

End Class

%>

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.