<%
'================================================
'/印象分页类(Impression_Page v1.0)
'/作者：纯属.印象
'================================================
'/*定义第一页按钮显示样式*/
Const PageBtn_First = "首页"
'/*定义前一页按钮显示样式*/
Const PageBtn_Prev = "上一页"
'/*定义下一页按钮显示样式*/
Const PageBtn_Next = "下一页"
'/*定义最后一页按钮显示样式*/
Const PageBtn_Last = "尾页"

Const Page_Nolink_Color = "#808080"

Class Impression_Page

	Private YX_PageCount
	Private YX_PageSize
	Private YX_PageNum
	Private YX_NavigationType
	Private YX_Urlstr
	Private YX_FilePath
	Private Page_Conn
	Private Page_RS
	Private Page_Sql
	Private Int_CurPage
	Private Int_TotalPage
	Private Int_TotalRecord
	Private Error_Str
	
	'/*PageSize*/属性
	Public Property Let PageSize(Int_PageSize) 
		If IsNumeric(Int_PageSize) Then 
			YX_PageSize = Clng(Int_PageSize) 
		Else 
			Error_Str = Error_Str &"PageSize的参数不正确" 
			ShowError() 
		End If 
	End Property
	
	Public Property Get PageSize 
		If YX_PageSize = "" Or (Not(IsNumeric(YX_PageSize))) Then 
			PageSize = 10      
		Else 
			PageSize = Clng(YX_PageSize)
		End If 
	End Property

	'/*GetConn得到数据库连接*/ 
	Public Property Let GetConn(ByRef obj_Conn)
		If IsObject(obj_Conn) Then
			Set Page_Conn = obj_Conn
		End If
	End Property
	
	'/*GetSQL得到查询语句*/
	Public Property Let GetSQL(str_Sql)
		Page_Sql = str_sql
	End Property
	
	'/*GetRs属性*/
	'/*返回分页后的记录集*/
	Public Property Get GetRs()
		Set Page_RS = Server.CreateObject("Adodb.Recordset")
		Page_RS.PageSize = PageSize
		Page_RS.Open Page_Sql,Page_Conn,1,1
		If Not(Page_RS.Bof and Page_RS.Eof) Then
			If Int_CurPage >= Page_RS.PageCount Then
				Int_CurPage = Page_RS.PageCount
			End If
			Page_RS.AbsolutePage = Int_CurPage
		End If
		Set GetRs = Page_RS
	End Property
	
	'/*当前页面文件地址*/
	Public Property Let File_Path(Val)
		YX_FilePath = Val
	End Property
	
	'/*分页导航显示样式*/
	Public Property Let Page_NavType(Val)
		YX_NavigationType = Val
	End Property
	
	'Class_Initialize类的初始化
	'初始化当前页的值
	Private Sub Class_initialize()
		'设定分页的默认值为10
		YX_PageSize = 10
		Dim PageNum
		PageNum = Replace(Replace(Trim(Request("page")),"'",""),"%","")
		
		If PageNum = "" Or IsEmpty(PageNum) Then
			Int_CurPage = 1
		Else
			If Not(IsNumeric(PageNum)) Then
				Int_CurPage = 1
			Else
				If Int(PageNum) < 1 Or Int(PageNum) <= 0 Then
					Int_CurPage = 1
				Else
					Int_CurPage = Cint(PageNum)
				End If
			End If
		End If
	End Sub
	 
	'/*Page_Navigation*/创建分页导航条  
	Public Sub Page_Navigation()
		Dim Nav_Htmlstr
		YX_Urlstr = GetUrl(YX_FilePath)
		Int_TotalRecord = Page_RS.RecordCount
		If Int_TotalRecord <= 0 Then
			Error_Str = Error_Str &"总记录数为零，请输入数据"
			Call ShowError()
		End If
		
		If Int_TotalRecord = "" Then
			Int_TotalPage = 1
		Else 
			If Int_TotalRecord Mod PageSize = 0 Then
				Int_TotalPage = Clng(Int_TotalRecord / YX_PageSize * -1)*-1
			Else 
				Int_TotalPage = Clng(Int_TotalRecord / YX_PageSize * -1)*-1+1
			End If
		End If
		If Int_CurPage > Int_TotalPage Then
			Int_CurPage = Int_TotalPage
		End If
		
		'显示分页信息，各个模块根据自己要求更改显求位置
		Response.Write "<table border=""0"" cellpadding=""0"" cellspacing=""0"">"
		Response.Write "<tr>"
		Response.Write "<td>"
		
		Nav_Htmlstr = Show_FirstPrv
		Response.Write Nav_Htmlstr &"&nbsp;"
		
		If YX_NavigationType = 1 Then
			Nav_Htmlstr = Show_NumBtn
			Response.Write Nav_Htmlstr
		End If
		
		Nav_Htmlstr = Show_NextLast
		Response.Write Nav_Htmlstr
		
		Nav_Htmlstr = Show_PageInfo
		Response.Write "&nbsp;"& Nav_Htmlstr
		
		Nav_Htmlstr = Show_PageOption
		Response.Write Nav_Htmlstr
		
		Response.Write "</td>"
		Response.Write "</tr>"
		Response.Write "</table>"
	End Sub
	
	'/*Show_FirstPrv显示首页、前一页*/
	Private Function Show_FirstPrv() 
		Dim str_tmp, int_Prvpage
		If Int_CurPage <= 1 Then 
			str_tmp = "<font color='"& Page_Nolink_Color &"'>"& PageBtn_First &"</font>&nbsp;<font color='"& Page_Nolink_Color &"'>"& PageBtn_Prev &"</font>"
		Else 
			int_Prvpage = Int_CurPage-1 
			str_tmp = "<a href='"& YX_Urlstr &"page=1'>"& PageBtn_First &"</a>&nbsp;<a href='"& YX_Urlstr &"page="& Cstr(int_Prvpage) &"'>" & PageBtn_Prev &"</a>"
		End If
		Show_FirstPrv = str_tmp
	End Function
	
	'/*Show_NextLast显示下一页、末页*/
	Private Function Show_NextLast()
		Dim str_tmp, int_Nextpage
		If Int_CurPage >= Int_TotalPage Then
			str_tmp = "<font color='"& Page_Nolink_Color &"'>"& PageBtn_Next &"</font>&nbsp;<font color='"& Page_Nolink_Color &"'>"& PageBtn_Last &"</font>"
		Else
			Int_NextPage = Int_CurPage+1
			str_tmp = "<a href='"& YX_Urlstr &"page="& Cstr(Int_NextPage) &"'>" & PageBtn_Next &"</a>&nbsp;<a href='"& YX_Urlstr &"page="& Cstr(Int_TotalPage) &"'>"& PageBtn_Last &"</a>"
		End If
		Show_NextLast = str_tmp
	End Function
	
	'/*显示数字导航*/
	Private Function Show_NumBtn()
		Dim Startpage, Endpage
		Startpage = (Int_CurPage \ 10)*10+1
		If Int_CurPage Mod 10 = 0 Then Startpage = (Int_CurPage \ 10)*10-9
		Endpage = Startpage+9
		
		For Startpage = Startpage to Endpage
			str_tmp = str_tmp &"[<a href='"& YX_Urlstr &"page="& Cstr(Startpage) &"'>"
			If Startpage = Int_CurPage Then
				str_tmp = str_tmp &"<font color='#FF0000'>"& Startpage &"</font>"
			Else
				str_tmp = str_tmp & Startpage
			End If
			str_tmp = str_tmp &"</a>] "
			If Startpage >= Int_TotalRecord Then Exit For
		Next
		Show_NumBtn = str_tmp
	End Function
	
	'/*显示OPTION跳转*/
	Private Function Show_PageOption()
		Dim str_tmp, i
		str_tmp = vbcrlf
		str_tmp = str_tmp & "<script language=""javascript"" type=""text/javascript"">"& vbcrlf
		str_tmp = str_tmp & "function jump_page(VALUE_STR){"& vbcrlf
		str_tmp = str_tmp & "location='"& YX_Urlstr &"page='+VALUE_STR"& vbcrlf
		str_tmp = str_tmp & "}"& vbcrlf
		str_tmp = str_tmp & "</script>"& vbcrlf
		str_tmp = str_tmp & "<select onChange=""jump_page(this.value)"">"& vbcrlf
		For i = 1 to Int_TotalPage
			str_tmp = str_tmp & "<option value='"& i &"'"
			If Clng(i) = Int_CurPage Then
				str_tmp = str_tmp & " selected"
			End If
			str_tmp = str_tmp & ">第"& i &"页</option>"& vbcrlf
		Next
		str_tmp = str_tmp & "</select>"
		Show_PageOption = str_tmp
	End Function
	
	'/*ShowPageInfo分页信息*/
	'/*更据要求自行修改*/
	Private Function Show_PageInfo() 
		Dim str_tmp
		str_tmp = "页次："& Int_CurPage &"/"& Int_TotalPage &"页&nbsp;共"& Int_TotalRecord &"条&nbsp;"& YX_PageSize &"条/页" 
		Show_PageInfo = str_tmp 
	End Function
	
	Private Function GetURL(strUrl)
		If strUrl = "" Then
			GetURL = ""
			Exit Function
		End If
		
		If InStr(strUrl,"?") < Len(strUrl) Then 
			If InStr(strUrl,"?") > 1 Then
				If InStr(strUrl,"&") < len(strUrl) Then 
					GetURL = strUrl & "&"
				Else
					GetURL = strUrl
				End If
			Else
				GetURL = strUrl & "?"
			End If
		Else
			GetURL = strUrl
		End If
	End Function
	
	Private Sub Class_Terminate()
		Page_RS.Close
		Set Page_RS = Nothing
	End Sub
	
	Private Sub ShowError()
		If Error_Str <> "" Then 
			Response.Write ""& str_Error &""
			Response.End 
		End If 
	End Sub
	
End Class
%>