<%
class Ex_SplitPageCls
'*********************************************************
'文件名称: Ex_SplitPageCls.asp
'功能描述: 易心博客分页类
'程序制作：易心
'官方网站: http://www.ex123.net
'论坛支持：http://bbs.ex123.net
'程序演示：http://exblog.ex123.net
'Copyright (C) 2007 ex123.net All rights reserved.
'LastUpdate:    2007-4-21
'*********************************************************
dim Ex_Rs
dim Ex_columns'要提取的字段
dim Ex_datafrom'数据表名
dim Ex_strWhere'记录筛选条件
dim Ex_order'sql排序
dim Ex_idcount'记录总数
dim Ex_pageSize'每页条数
dim Ex_pageCount'总页数
dim Ex_ids'获得本页要用到的id
dim Ex_Sql'构造的sql语句
dim Ex_page'当前显示页码
dim Ex_Conn'数据库联接对象
dim Ex_id'主键字段
Dim Ex_strPage'页码连接地址参数
private sub class_initialize
set Ex_Rs=server.CreateObject("adodb.recordset")
Ex_id="id"
Ex_pageSize=20
end sub
private sub class_terminate
set Ex_rs=nothing
end sub
'属性赋值:
public property let letConn(str)
	Ex_conn=str
end property
'属性赋值:sql语句 要查询的字段 带select
public property let letColumns(str)
	Ex_Columns=str
end property
'属性赋值:sql语句筛选条件部分 带where
public property let letWhere(str)
	Ex_strWhere=str
end property
'属性赋值:sql语句数据表 带from
public property let letDataFrom(str)
	Ex_dataFrom=str
end property
'属性赋值:sql语句排序部分 带order by
public property let letOrder(str)
	Ex_order=str
end property
'属性赋值:每页记录数
public property let letPageSize(str)
	Ex_pageSize=str
end property
'属性赋值:当前页数
public property let letPage(str)
	Ex_page=str
end property
'属性赋值:主表主键字段
public property let letId(str)
	Ex_Id=str
end Property
'属性赋值:页码连接参数 带连接符&
public property let letStrPage(str)
	Ex_strPage=str
end property
'属性:获得记录总数
public property get getRsCount
	getRsCount=Ex_idCount
end property
'属性:获得页总数
public property get getPageCount
if(Ex_idcount>0) then'如果记录总数=0,则不处理
 	if(Ex_idcount mod Ex_pageSize=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
  		Ex_pageCount=int(Ex_idcount/Ex_pageSize)'获取总页数
 	else
  		Ex_pagecount=int(Ex_idcount/Ex_pageSize)+1'获取总页数
	end if
	getPageCount=Ex_pagecount
else
	getPageCount=0
end if
end property
'属性:获得当前页数
public property get getPage
	getPage=Ex_Page
end property
'获得本页要用到的id
private sub ids
	dim i
	Ex_sql="select "&Ex_Id&" "& Ex_datafrom &" " &" "&Ex_strWhere&" "&Ex_order
 	Ex_rs.open Ex_sql,Ex_conn,1,1
	if not Ex_Rs.eof and not Ex_Rs.bof then
		Ex_rs.pagesize =Ex_pageSize '每页显示记录数
		Ex_idcount=Ex_rs.recordcount
		Ex_pageCount=Ex_Rs.pageCount
    	if CInt(Ex_page) < 1 then 
			Ex_page = 1
    	elseif CInt(Ex_page) > CInt(Ex_pagecount) then 
			Ex_page = CInt(Ex_pageCount)
		End if
    	if CInt(Ex_pageCount) > 0 then Ex_rs.absolutepage =CInt(Ex_page)
		for i=1 to Ex_rs.pagesize
 		if Ex_rs.eof then exit for  
  			if(i=1)then
   			Ex_Ids=Ex_rs("id")
  		else
   			Ex_Ids=Ex_Ids &","&Ex_rs("id")
  		end if
 		Ex_rs.movenext
 		next
	end if
	Ex_Rs.close
end Sub
'返回本页要用到的记录集
public function execute
	ids
	If Trim(Ex_ids)<>"" then
		Ex_Sql=Ex_Columns&" "&Ex_dataFrom&" where id in("&Ex_ids&") "&Ex_order
		Ex_Rs.open Ex_Sql,Ex_conn,1,1
	Else
		Ex_idCount=0
	End if
end Function
'返回本页需要调用的记录集
Public Function getRs
	Set getRs=Ex_Rs
End Function
'显示分页连接
Public Function Show
	Dim i
	Show="共有"&Ex_IdCount&"条&nbsp;每页"&Ex_PageSize&"条&nbsp;"
	If CInt(Ex_page)=1 Then
		Show=show&"[首页]&nbsp;[上一页]&nbsp;"
	Else
		show=show&"<a href=""?page=1"&Ex_strPage&""">[首页]</a>&nbsp;<a href=""?page="&Ex_page-1&Ex_strPage&""">[上一页]</a>&nbsp;"
	End If

	For i=((cint(Ex_page)-1) \ 5)*5+1 to ((cint(Ex_page)-1) \ 5)*5+5
	if cint(i)<=cint(Ex_pageCount) then
	 if cint(Ex_page)<>cint(i) then
		show=show&"<a href=?page="&i&Ex_strPage&">["&i&"]</a>&nbsp;"
	 else
		show=show&"<b>"&i&"</b>&nbsp;"
	 end if
	end if
	Next

	If CInt(Ex_Page)=CInt(Ex_pageCount) Then
		show=show&"[下一页]&nbsp;[尾页]"
	Else
		show=show&"<a href=""?page="&Ex_page+1&Ex_strPage&""">[下一页]</a>&nbsp;<a href=""?page="&Ex_pageCount&Ex_StrPage&""">[尾页]</a>"
	End if
End Function 
end class
%>

