ASP Classic Page-Class _ Application Skills

Source: Internet
Author: User
ASP Classic Page-type
Source

'=====================================================================
' Xdownpage ASP version
' Version 1.00
' Code by zykj2000
' Email:zykj_2000@163.net
' Bbs:http://bbs.513soft.net
' This program can be free to use, modify, I hope my program can bring convenience to your work
' But please keep the above interest
'
' Program features
' This program is mainly to the data pagination part of the encapsulation, and the data display part completely by the user customization,
' Support URL multiple parameters
'
' Use instructions
' Program parameter description
' Papgesize defines the number of records per page of pagination
' Getrs Returns a paging recordset this property is read-only
' Getconn get a database connection
' GetSQL get the query statement
' Procedure Method description
' ShowPage display the pager bar, the only common method
'
Cases
'
' Include file
'
' Set mypage=new xdownpage ' Create object
' Mypage.getconn=conn ' Get database connection
' mypage.getsql= ' select * from ProductInfo ORDER by ID ASC
' Mypage.pagesize=5 ' Sets the record bar data for each page to 5
' Set Rs=mypage.getrs () ' returns to the recordset
' Mypage.showpage () ' Displays paging information, which can be used after set Rs=mypage.getrs ()
' Call anywhere, you can call multiple times
' For I=1 to Mypage.pagesize ' The next action is the same as manipulating a normal Recordset object
' If not rs.eof then ' this tag is to prevent last page overflow
' Response.Write Rs (0) & "
"' Here's the way to customize the display.
' Rs.movenext
' Else
' Exit for
' End If
' Next
'
'=====================================================================

Const btn_first= "9" Defines the first page button display style
Const btn_prev= "3" defines the previous-page button display style
Const btn_next= "4" defines the next-page button display style
Const btn_last= ":" Defines the last-page button display style
Const xd_align= "Center" defines the alignment of pagination information
Const xd_width= "100%" Defines the paging information box size
Const xd_height= "20"
Class Xdownpage
Private Xd_pagecount,xd_conn,xd_rs,xd_sql,xd_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_ Totalrecord


'=================================================================
' PageSize Property
' Set the paging size of each page
'=================================================================
Public Property Let PageSize (Int_pagesize)
If IsNumeric (int_pagesize) Then
XD_PAGESIZE=CLNG (Int_pagesize)
Else
Str_error=str_error & "pagesize parameters are incorrect"
ShowError ()
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 Property
' Returns a paginated recordset
'=================================================================
Public Property Get Getrs ()
Set xd_rs=server.createobject ("Adodb.recordset")
Xd_rs.pagesize=pagesize
Xd_rs.open xd_sql,xd_conn,1,1
If not (xd_rs.eof and xd_rs. BOF) Then
If int_curpage>xd_rs. PageCount Then
Int_curpage=xd_rs. PageCount
End If
Xd_rs.absolutepage=int_curpage
End If
Set getrs=xd_rs
End Property

'================================================================
' Getconn get a database connection
'
'================================================================
Public Property Let Getconn (Obj_conn)
Set Xd_conn=obj_conn
End Property

'================================================================
' GetSQL get the query statement
'
'================================================================
Public Property Let GetSQL (Str_sql)
Xd_sql=str_sql
End Property



'==================================================================
' Initialization of the Class_Initialize class
' Initialize the value of the current page
'
'==================================================================
Private Sub Class_Initialize
'========================
' Set some parameters of the Summerside recognition value
'========================
xd_pagesize=10 ' Sets the default value of paging to 10
'========================
' Get when the previous value
'========================
If Request ("page") = "" Then
Int_curpage=1
ElseIf Not (IsNumeric (Request ("page")) Then
Int_curpage=1
ElseIf CInt ("page") <1 Then
Int_curpage=1
Else
Int_curpage=cint Trim (Request ("page"))
End If

End Sub

'====================================================================
' ShowPage Create a pager bar
' There's a homepage, a previous page, the next page, the last, and the digital navigation
'
'====================================================================
Public Sub ShowPage ()
Dim str_tmp

Int_totalrecord=xd_rs. RecordCount
If int_totalrecord<=0 Then
Str_error=str_error & "Total record number is zero, please enter data"
Call ShowError ()
End If
If Int_totalrecord int_totalpage=1
Else
If int_totalrecord mod PageSize =0 Then
Int_totalpage = Int (int_totalrecord/xd_pagesize *-1) *-1
Else
Int_totalpage = Int ((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 needs to change the location
'===============================================================================
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 ' "
Showgoto
Response.Write "
"

End Sub

'====================================================================
' SHOWFIRSTPRV display homepage, previous page
'
'
'====================================================================
Private Function SHOWFIRSTPRV ()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
str_tmp=btn_first& "" &btn_prev
Else
Int_prvpage=int_curpage-1
str_tmp= "" &Btn_First& "& btn_prev&" "
End If
Showfirstprv=str_tmp
End Function

'====================================================================
' Shownextlast next page, last
'
'
'====================================================================
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= "" &Btn_Next& "& btn_last&" "
End If
Shownextlast=str_tmp
End Function


'====================================================================
' SHOWNUMBTN Digital Navigation
'
'
'====================================================================
' Private Function shownumbtn ()
' Dim i,str_tmp
' For I=1 to Int_totalpage
' Str_tmp=str_tmp & ' [&i&] '
' Next
' Shownumbtn=str_tmp
'
' End Function
'====================================================================
' Shownumbtn revised digital navigation
'
'====================================================================
Function shownumbtn ()
Dim I,str_tmp,end_page,start_page
If Int_curpage>4 Then
If Int_curpage+2 start_page=int_curpage-2
End_page=int_curpage+2
Else
Start_page=int_totalpage-4
End_page=int_totalpage
End If
Else
Start_page=1
If Int_totalpage>5 Then
End_page=5
Else
End_page=int_totalpage
End If
End If
For I=start_page to End_page
Str_tmp=str_tmp & "[" &i&] "
Next
Shownumbtn=str_tmp
End Function

'====================================================================
' Showgoto page jump
'
'
'====================================================================
Private Function Showgoto ()
Dim M_item
'========================================================
' writes the returned URL parameter to the hidden field one by one to continue passing with the argument
'========================================================
For each m_item in Request.QueryString
If InStr ("page", M_item) =0 Then ' Removes the value of ' page ' from the argument
Response.Write ""
End If
Next
'========================================================
Response.Write "Go to page:"
Response.Write "Page"
End Function


'====================================================================
' Showpageinfo Paging information
' It is also required to modify its own
'
'====================================================================
Private Function Showpageinfo ()
Dim str_tmp
str_tmp= "[page: &int_curpage&]/&int_totalpage&" page] [total "&int_totalrecord&"] ["&xd_ pagesize& "article/page]"
Showpageinfo=str_tmp
End Function

'====================================================================
' Modified function to get the current URL parameter
' Codeing by Redsun
'====================================================================
Private Function GetUrl ()
Dim scriptaddress, M_itemurl, M_item
scriptaddress = CStr (Request.ServerVariables ("Script_name")) & "?" Get 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 with parameter address
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 hint
'====================================================================
Private Sub ShowError ()
If str_error <> "" Then
Response.Write ("
"& Sw_error &" ")
Response.End
End If
End Sub

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.