Xdownpage ASP Version Page classes _asp class class

Source: Internet
Author: User
Tags servervariables trim
<%
'===================================================================
' 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
'
'===================================================================

Const btn_first= "<font face=" "Webdings" ">9</font>" defines the first-page button display style
Const btn_prev= "<font face=" "Webdings" ">3</font>" defines the previous-page button display style
Const btn_next= "<font face=" "Webdings" ">4</font>" defines the next-page button display style
Const btn_last= "<font face=" "Webdings" ">:</font>" 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

Class Xdownpage
Private Xd_pagecount,xd_conn,xd_rs,xd_sql,xd_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_ Totalrecord,xd_surl


'=================================================================
' 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
Xd_surl = GETURL ()
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= "" Then
Int_totalpage=1
Else
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 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 ""
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= "<a href=" "&xd_surl &" 1 "&" ">" & btn_first& "</a> <a href=" "" & Xd_surl & CStr (int_prvpage) & "" > "& btn_prev&" </a> "
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= "<a href=" "& Xd_surl & CStr (int_nextpage) &" ">" & btn_next& "</a> <a href=" "& Xd_surl & CStr (int_totalpage) &" ">" & btn_last& "</a>"
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 & "[<a href=" "& Xd_surl & CStr (i) &" ">" &i& "&LT;/A&GT;]"
Next
Shownumbtn=str_tmp
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&" record &xd_pagesize & "article/every page"
Showpageinfo=str_tmp
End Function
'==================================================================
' GetURL get the current URL
' More depending on the URL parameter, get different results
'
'==================================================================
Private Function GetURL ()
Dim Strurl,str_url,i,j,search_str,result_url
Search_str= "Page="

Strurl=request.servervariables ("URL")
Strurl=split (strURL, "/")
I=ubound (strurl,1)
Str_url=strurl (i) ' Get the current page filename

Str_params=trim (Request.ServerVariables ("query_string"))
If str_params= "" Then
Result_url=str_url & "Page="
Else
If InStrRev (str_params,search_str) =0 Then
Result_url=str_url & "?" & Str_params & "&page="
Else
J=instrrev (STR_PARAMS,SEARCH_STR)-2
If J=-1 Then
Result_url=str_url & "Page="
Else
Str_params=left (STR_PARAMS,J)
Result_url=str_url & "?" & Str_params & "&page="
End If
End If
End If
Geturl=result_url
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 ("" & Str_error & "")
Response.End
End If
End Sub
End Class



' Set conn = server. CreateObject ("Adodb.connection")
' Conn.Open ' Driver={microsoft Access Driver (*.mdb)};d bq= "& Server. Mappath ("/data/5iduohai.mdb")
'
"' ############ #类调用样例 #################
' Create object
' Set mypage=new xdownpage
"Get a database connection
' Mypage.getconn=conn
' SQL statement
' mypage.getsql= ' select * FROM [Dh_company] ORDER by ID ASC "
' Set the record bar data for each page to 5
' Mypage.pagesize=5
"Returns the recordset
' Set Rs=mypage.getrs ()
' Displays paging information, which can be invoked at any location after set Rs=mypage.getrs () and can be invoked multiple times

'
' Show data
' Response.Write ("<br/>")
' For I=1 to Mypage.pagesize
"Here is the way to customize the display.
' If not rs.eof then
' Response.Write Rs (0) & "<br/>"
' Rs.movenext
' Else
' Exit for
' End If
' Next
' Mypage.showpage ()
%>
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.