<%
'===================================================================
'程序特点
'本程序主要是对数据分页的部分进行了封装,而数据显示部份完全由用户自定义,
'支持URL多个参数
'
'使用说明
'程序参数说明
'PapgeSize 定义分页每一页的记录数
'GetRS 返回经过分页的Recordset此属性只读
'GetConn 得到数据库连接
'GetSQL 得到查询语句
'程序方法说明
'ShowPage 显示分页导航条,唯一的公用方法
'
'例:
' Set mypage=new downpage '创建对象
' mypage.getconn=conn '得到数据库连接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '设置每一页的记录条数据为5条
' set rs=mypage.getrs() '返回Recordset
' mypage.showpage() '显示分页信息,这个方法可以,在set rs=mypage.getrs()以后
' 任意位置调用,可以调用多次
' for i=1 to mypage.pagesize '接下来的操作就和操作一个普通Recordset对象一样操作
' if not rs.eof then '这个标记是为了防止最后一页的溢出
' response.write rs(0) & "
'" '这里就可以自定义显示方式了
' rs.movenext
' else
' exit for
' end if
' next
'
'===================================================================
Const Btn_First="<font face='webdings' >9</font>" '定义第一页按钮显示样式
Const Btn_Prev="<font face='webdings' >3</font>" '定义前一页按钮显示样式
Const Btn_Next="<font face='webdings' >4</font>" '定义下一页按钮显示样式
Const Btn_Last="<font face='webdings' >:</font>" '定义最后一页按钮显示样式
Const XD_Align="Center" '定义分页信息对齐方式
Const XD_Width="100%" '定义分页信息框大小
Class downpage
Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord,lg,X_showtype
'==================================================================
'Class_Initialize 类的初始化
'初始化当前页的值
'==================================================================
Private Sub Class_Initialize
'========================
'设定一些参数的黙认值
'========================
XD_PageSize=20 '设定分页的默认值为20
X_showtype=1
'========================
'获取当前面的值
'========================
If request("page")="" Then
int_curpage=1
ElseIf not(IsNumeric(request("page"))) Then
int_curpage=1
ElseIf CInt(Trim(request("page")))<1 Then
int_curpage=1
Else
Int_curpage=CInt(Trim(request("page")))
End If
str_URL=GetURL()
End Sub
'=================================================================
'show 属性 显示的导航条样式 1为下拉式,2为数字导航条
'=================================================================
Public Property let showtype(show_type)
X_showtype=show_type
End Property
Public Property Get showtype
showtype=X_showtype
End Property
'=================================================================
'PageSize 属性
'设置每一页的分页大小
'=================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
XD_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的参数不正确"
ShowError()
End If
End Property
Public Property Get PageSize
If XD_PageSize="" or (not(IsNumeric(XD_PageSize))) Then
PageSize=20
Else
PageSize=XD_PageSize
End If
End Property
'=================================================================
'GetRS 属性
'返回分页后的记录集
'=================================================================
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
int_TotalPage= XD_Rs.pagecount
End If
Set GetRs=XD_RS
End Property
'================================================================
'GetConn 得到数据库连接
'================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn=obj_Conn
End Property
'================================================================
'GetSQL 得到查询语句
'================================================================
Public Property Let GetSQL(str_sql)
XD_SQL=str_sql
End Property
'====================================================================
'ShowPage 创建分页导航条
'有首页、前一页、下一页、末页、还有数字导航,下拉菜单导般条
'====================================================================
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=XD_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "总记录数为零,请输入数据"
Call ShowError()
End If
If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If
'==================================================================
'显示分页信息,各个模块根据自己要求更改显求位置
'==================================================================
response.write ""
response.write ShowFirstPrv '显示首页、前一页
response.write showNumBtn '数字导航
response.write ShowNextLast '下一页、末页
response.write ShowPageInfo '分页信息
response.write moveto ' 拉菜单导航
response.write ""
End Sub
'====================================================================
'ShowFirstPrv 显示首页、前一页
'====================================================================
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&int_prvpage&"'>"& Btn_Prev&"</a>"
End If
ShowFirstPrv=str_tmp
End Function
'====================================================================
'ShowNextLast 下一页、末页
'====================================================================
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&Int_NextPage&"'>"&Btn_Next&" </a> <a href='"&str_URL&int_totalpage&"'>"& Btn_Last&"</a>"
End If
ShowNextLast=str_tmp
End Function
'====================================================================
'ShowNumBtn 数字导航
'====================================================================
Private Function showNumBtn()
Dim i,str_tmp
if int_curpage <10 then
B_i =1
else
B_i =(int_curpage/10)*10-1
end if
E_i=(int_curpage/10 )*10+10
if E_i>int_TotalPage then E_i=int_TotalPage
For i= B_i to E_i
if int_curpage=i then
str_tmp=str_tmp & " <font color=#999999>"&i&"</font> "
else
str_tmp=str_tmp & " <a href='"&str_URL&i&"'><font color=#000000>"&i&"</font></a> "
end if
Next
showNumBtn=str_tmp
End Function
'====================================================================
'moveto 下拉菜单导航
'====================================================================
private function moveto()
dim i ,str_tmp
str_tmp=" 转到:<select name='nowpage' style='color:#A20000' onchange=" &chr(34) &"window.open(this.options[this.selectedIndex].value,'_self')"&chr(34) &">"&chr(10)
for i=1 to int_totalpage
str_tmp=str_tmp &"<option value='" &str_URL &i &"'"
if int_curpage=i then str_tmp=str_tmp& " selected"
str_tmp=str_tmp& ">第" &i &"页</option>"&chr(10)
next
moveto=str_tmp
end function
'====================================================================
'ShowPageInfo 分页信息
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp="页次:"&int_curpage&"/"&int_totalpage&"页 共"&int_totalrecord&"条记录 "&XD_PageSize&"条/每页"
ShowPageInfo=str_tmp
End Function
'==================================================================
'GetURL 得到当前的URL
'更据URL参数不同,获取不同的结果
'==================================================================
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)'得到当前页文件名
str_params=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
'====================================================================
' 设置 Terminate 事件。
'====================================================================
Private Sub Class_Terminate
XD_RS.close
Set XD_RS=nothing
End Sub
'====================================================================
'ShowError 错误提示
'====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("" & SW_Error & "")
Response.End
End If
End Sub
End class
%>