Super ASP Big Page _ My class allow me to master _ application skills

Source: Internet
Author: User
Tags servervariables
Super ASP Big Page _ My class Let me choose the Blog from Applebbs
Keywords Super ASP Oita page _ My class let me be the Boss
Source
<%
'===================================================================
' Showmorepage ASP version
' Version HuangJM1.00
' Code by Maomao
' Create Date 2004-09-28
' qq:5144707
' HTTP://BLOG.CSDN.NET/MAOMAOYSQ
' Write for my LOVER:HUANGJM ' This program is free to use, modify, but please keep the above information
'
' function
' 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: http://www.***.com/***.asp?aa=1&page=9&bb=2
'
'
' Paramers:
' Papgesize defines the number of records per page of pagination
' Getcurpagenum returns the number of recordsets on the current page This property is read-only
' Getrs Returns a paging recordset this property is read-only
' Getconn get a database connection
' GetSQL get the query statement
' Interface of Class
' ShowPage display the pager bar, the only common method
'
' ############ #类调用样例 #################
' Create object
' Set hjmpage=new showmorepage
' Get a database connection
' Hjmpage.getconn=conn
' SQL statement
' hjmpage.getsql= ' select * from Shop_books where newsbook=1 order by bookid Desc "
' Set the record bar data for each page to 20, the default display 10
' Hjmpage.pagesize=20
' Displays paging information, can be invoked anywhere, and can be invoked multiple times
' Hjmpage.showpage ()
' Set Rs=hjmpage.getrs () ' returns to the recordset
' Show data start
' Here's the way to customize the display.
The number of records for the current page of ' for I=1 to Hjmpage.getcurpagenum '
' Response.Write Left (Trim (RS ("BookName")) & "..."
' Rs.movenext
' Next
' Show Data End
' Set hjmpage=nothing
' ############ #类调用样例 #################
'===================================================================
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 Showmorepage
Private Obj_conn,obj_rs,str_sql,int_pagesize,str_errors,int_curpage,str_url,int_totalpage,int_totalrecord

'=================================================================
' PageSize Property
' Set the paging size of each page
'=================================================================
Public Property Let PageSize (Intvalue)
If IsNumeric (intvalue) Then
INT_PAGESIZE=CLNG (Intvalue)
Else
Str_errors=str_errors & "pagesize parameters are incorrect"
ShowError ()
End If
End Property
Public Property Get PageSize
If int_pagesize= "" or (Not (IsNumeric (int_pagesize)) Then
pagesize=10
Else
Pagesize=int_pagesize
End If
End Property
'=================================================================
' Getrs Property
' Returns a paginated recordset
'=================================================================
Public Property Get Getrs ()
If int_totalrecord= 0 then call GetPage ()
If not (obj_rs.eof and OBJ_RS.BOF) Then
If Int_curpage<>1 Then
If Int_curpage-1<int_totalpage Then
Obj_rs.move (int_curpage-1) *pagesize
Dim bookmark
Bookmark=obj_rs.bookmark
Else
Int_curpage=1
End If
End If
End If
Set getrs=obj_rs
End Property
'=================================================================
' Getcurpagenum Property
' Returns the number of recordsets on the current page
'=================================================================
Public Property Get Getcurpagenum ()
Dim int_pagenum
Int_pagenum = Int_pagesize
If int_totalrecord= 0 then call GetPage ()
If Int_curpage>int_totalpage Then
Int_curpage=int_totalpage
Int_pagenum = int_totalrecord-(int_totalpage-1) *int_pagesize
ElseIf Int_curpage=int_totalpage Then
Int_pagenum = int_totalrecord-(int_totalpage-1) *int_pagesize
End If
Getcurpagenum = Int_pagenum
End Property
'================================================================
' Getconn get a database connection
'
'================================================================
Public Property Let Getconn (sconn)
Set Obj_conn=sconn
End Property
'================================================================
' GetSQL get the query statement
'
'================================================================
Public Property Let GetSQL (svalue)
Str_sql=svalue
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
'========================
int_pagesize=10 ' Sets the default value of paging to 10
int_totalrecord= 0
'========================
' 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
'====================================================================
' Openrs Open Data set
' There's a homepage, a previous page, the next page, the last, and the digital navigation
'
'====================================================================
Private Sub Openrs ()
Set obj_rs=server.createobject ("Adodb.recordset")
Obj_rs.open str_sql,obj_conn,1,1
End Sub
'====================================================================
' GetPage Create a pager bar
' There's a homepage, a previous page, the next page, the last, and the digital navigation
'
'====================================================================
Private Sub GetPage ()
If TypeName (obj_rs) <> "Object" Then call Openrs ()
Int_totalrecord=obj_rs.recordcount
If int_totalrecord<=0 Then
Str_errors=str_errors & "Total record number is zero, please enter data"
Call ShowError ()
End If
If int_totalrecord mod PageSize =0 Then
Int_totalpage = int_totalrecord \ Int_pagesize
Else
Int_totalpage = int_totalrecord \ int_pagesize+1
End If
If Int_curpage>int_totalpage Then
Int_curpage=int_totalpage
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
Str_url = GETURL ()
If int_totalrecord= 0 then call GetPage ()
'==================================================================
' 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=" "&str_url &" 1 "&" ">" & btn_first& "</a> <a href=" "" & Str_url & 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=" "& Str_url & CStr (int_nextpage) &" ">" & btn_next& "</a> <a href=" "& Str_url & CStr (int_totalpage) &" ">" & btn_last& "</a>"
End If
Shownextlast=str_tmp
End Function

'====================================================================
' SHOWNUMBTN Digital Navigation
' Show 10 pages at a time
'
'====================================================================
Private function shownumbtn ()
Dim I,str_tmp,m,n
m = int_curpage-4
n = int_totalpage
If N>1 Then
For i = 1 to 10
If M < 1 then m = 1
If M > n Then
Exit For
End If
Str_tmp=str_tmp & "[<a href=" "& Str_url & CStr (i) &" ">" &i& "&LT;/A&GT;]"
m = m + 1
Next
End If
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 &int_ pagesize& "bar/per 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,tmp_url,i,j,search_str,result_url
Search_str= "Page="
Strurl=request.servervariables ("URL")
Strurl=split (strURL, "/")
I=ubound (strurl,1)
Tmp_url=strurl (i) ' Get the current page filename
Str_params=trim (Request.ServerVariables ("query_string"))
If str_params= "" Then
Result_url=tmp_url & "Page="
Else
If InStrRev (str_params,search_str) =0 Then
Result_url=tmp_url & "?" & Str_params & "&page="
Else
J=instrrev (STR_PARAMS,SEARCH_STR)-2
If J=-1 Then
Result_url=tmp_url & "Page="
Else
Str_lparams=left (STR_PARAMS,J)
Str_rparams=right (Str_params,len (str_params)-j-1)
If InStr (Str_rparams, "&") <>0 Then
Str_rparams=right (Str_rparams,len (str_rparams)-instr (Str_rparams, "&") +1)
Else
Str_rparams = ""
End If
Result_url=tmp_url & "?" & str_lparams&str_rparams& "&page="
End If
End If
End If
Geturl=result_url
End Function
'====================================================================
' Set the Terminate event.
'
'====================================================================
Private Sub Class_Terminate
Obj_rs.close
Set obj_rs=nothing
Obj_conn.close
Set obj_conn = Nothing
End Sub
'====================================================================
' ShowError error hint
'
'
'====================================================================
Private Sub ShowError ()
If str_errors <> "" Then
Response.Write ("" & Str_errors & "")
Response.End
End If
End Sub
End Class
%>

<!--#include file= "include/function.asp"-->
<%
Dim conn
Call Dbconnect ()
' ############ #类调用样例 #################
' Create object
Set hjmpage=new Showmorepage
' Get a database connection
Hjmpage.getconn=conn
' SQL statement
Hjmpage.getsql= "SELECT Top 6 * shop_books where newsbook=1 ORDER by bookid Desc"
' Set the record bar data for each page to 5
hjmpage.pagesize=2
Set Rs=hjmpage.getrs () ' returns to the recordset
' Displays paging information, which can be invoked at any location after set Rs=hjmpage.getrs () and can be invoked multiple times
Hjmpage.showpage ()
' Show data
Response.Write ("<br/>")
The number of records for the current page of I=1 to Hjmpage.getcurpagenum '
' Here's the way to customize the display.
%>


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.