<%
'信息分页
Class Cls_ShowoPage
	public Showo_PageSize,Showo_CurrPage
	
	Private Showo_Sql,Showo_Field,Showo_qurry,Showo_OrderBy,Showo_Id
	Private Showo_RecCount,Showo_PageCount,ResultSet_Sql
	'================================================================
	' Class_Initialize 类的初始化
	'================================================================
	Private Sub Class_Initialize
		Showo_PageSize=10 '设定每页记录条数的默认值为10
		Showo_CurrPage=CheckNum(Trim(""&page&""),1,-1) '获取当前面的值

	
	End Sub

	'================================================================
	' PageSize 设置每一页记录条数,默认10记录
	'================================================================
	Public Property Let PageSize(ByVal intPageSize)
		Showo_PageSize=CheckNum(intPageSize,Showo_PageSize,-1) 
	End Property

	'================================================================
	' Sql 取得sql所需表字段条件排序,输入:字段,表,条件,排序,主ID
	'================================================================
	Public Property Let Sql(ByVal str_sql)  
		Showo_Sql=Split(str_sql,"$")
		Showo_Field=Showo_Sql(0)
		showo_qurry=showo_sql(1)
		Showo_OrderBy=Showo_Sql(2)
		Showo_Id=Showo_Sql(3)
		If Len(Showo_OrderBy)>3 Then Showo_OrderBy=" ORDER BY "&Showo_OrderBy
	
	
	End Property

	'================================================================
	' GetRecCount 取得记录总数
	'================================================================
	public Function RecCount()	       
				
				RecCount=oa.execute("SELECT Count("&Showo_Id&") "&showo_qurry)(0)           
				
	End Function
	public function aceeess()
	aceeess="SELECT "&Showo_Field&" "&showo_qurry&" "&Showo_OrderBy
	end function
	'================================================================
	' GetRecCount 取得记录总数
	'================================================================
	public function geturlname()
	   dim str,host,url,keyword,full  
       str="http://"  
       host = Request.ServerVariables("HTTP_HOST")  
       url = Request.ServerVariables("PATH_INFO") '或url  
       keyword = Request.ServerVariables("QUERY_STRING")  
       if keyword <> "" then  
       full = str&host&url&"?"&keyword  
       else  
       full = str&host&url  
       end if   
	   full=replace(full,"?Page="&Showo_CurrPage,"")
	   full=replace(full,"&Page="&Showo_CurrPage,"")
	   if InStr(full,"?")<len(full) then 
		if InStr(full,"?")>1 then
			if InStr(full,"&")<len(full) then 
				geturlname=full & "&"
			else
				geturlname=full
			end if
		 else
			geturlname=full & "?"
		 end if
	   else
		geturlname=strUrl
	   end if
	end function
	

	'================================================================
	' ResultSet 返回分页后的记录集
	'================================================================
	Public Property Get ResultSet()
	    dim showo_rs
		ResultSet=Null
		'记录总数
		Showo_RecCount=RecCount()
		'当前页
		If Showo_RecCount>0 Then
		'页数
			If (Showo_RecCount mod Showo_PageSize)=0 Then
				Showo_PageCount=Showo_RecCount\Showo_PageSize
			Else
				Showo_PageCount=Showo_RecCount\Showo_PageSize+1
			End If
			'当前页
			Showo_CurrPage=CheckNum(Showo_CurrPage,1,Showo_PageCount)
	
				
					ResultSet_Sql="SELECT TOP "&(Showo_CurrPage)*Showo_PageSize&" "&Showo_Field&" "&showo_qurry&" "&Showo_OrderBy					
					Set Showo_Rs=oa.execute(ResultSet_Sql)
					showo_rs.move(Showo_CurrPage-1)*Showo_PageSize
				
			  
			'response.Write(ResultSet_Sql)
			ResultSet=Showo_Rs.GetRows(Showo_PageSize)
			Showo_Rs.close
			Set Showo_Rs=Nothing
		End If  
	End Property

	'================================================================
	' 输入:检查字段,开始数字(默认数字),结束数字(为-1则不检查大小)
	'================================================================
	Private Function CheckNum(ByVal strStr,ByVal intStartNum,ByVal intEndNum)
		CheckNum=intStartNum
		If IsNumeric(strStr) Then CheckNum=Clng(strStr)        
		If intEndNum>-1Then
			If CheckNum<intStartNum Then CheckNum=intStartNum
			If CheckNum>intEndNum Then CheckNum=intEndNum
		End If
	End Function

	'================================================================
	' Class_Terminate 类注销
	'================================================================
	Private Sub Class_Terminate()
	
	End Sub
	
public sub showpage(styclass,num)'sytclass 连接样式 num显示页数 0为上一页下一页显视
   dim strTemp,strUrl,i
   if request("cp")<>"" then
   cpid="-"&request("cp")&""
   end if
    if num=0 then
	strUrl=geturlname()
	strTemp= "<div id='lbb2'>"
	
	strTemp=strTemp & "共 <b>" & reccount & "</b> 条&nbsp;&nbsp;"
	if sid<>"" then	
  	if Showo_CurrPage<2 then
    		strTemp=strTemp & "首页 上一页&nbsp;"
  	else
    		strTemp=strTemp & "<a href=?"&cid&"-"&sid&".html class='"&styclass&"'>首页</a>&nbsp;"
    		strTemp=strTemp & "<a href=?"&cid&"-"&sid&"-" & (Showo_CurrPage-1) &".html class='"&styclass&"'>上一页</a>&nbsp;"
  	end if

  	if Showo_PageCount-Showo_CurrPage<1 then
    		strTemp=strTemp & "下一页 尾页"
  	else
    		strTemp=strTemp & "<a href='?"&cid&""&cpid&"-"&sid&"-" & (Showo_CurrPage+1) &".html' class='"&styclass&"'>下一页</a>&nbsp;"
    		strTemp=strTemp & "<a href='?"&cid&""&cpid&"-"&sid&"-" & (Showo_PageCount) &".html' class='"&styclass&"'>尾页</a>"
  	end if
	else
	if Showo_CurrPage<2 then
    		strTemp=strTemp & "首页 上一页&nbsp;"
  	else
    		strTemp=strTemp & "<a href='?"&cid&"-1.html' class='"&styclass&"'>首页</a>&nbsp;"
    		strTemp=strTemp & "<a href='?"&cid&"-" & (Showo_CurrPage-1) &".html' class='"&styclass&"'>上一页</a>&nbsp;"
  	end if

  	if Showo_PageCount-Showo_CurrPage<1 then
    		strTemp=strTemp & "下一页 尾页"
  	else
    		strTemp=strTemp & "<a href='?"&cid&"-" & (Showo_CurrPage+1) &".html' class='"&styclass&"'>下一页</a>&nbsp;"
    		strTemp=strTemp & "<a href='?"&cid&"-" & (Showo_PageCount) &".html' class='"&styclass&"'>尾页</a>"
  	end if
	end if
   	strTemp=strTemp & "&nbsp;页次：<strong><font color=red>" & Showo_CurrPage & "</font>/" & Showo_PageCount & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & Showo_Pagesize & "</b> 条/页"
	
		

	strTemp=strTemp & "</div>"
else	
    dim pagestart,pageend
   strurl=geturlname()
   pagestart=CheckNum(Showo_CurrPage-2,1,Showo_PageCount)
   pageend=CheckNum(Showo_CurrPage+2,4,Showo_PageCount)
   if sid<>"" then
   sidl="-"&sid&""
   end if
   strtemp="<DIV  id='lbb2'><DIV class='page-num'><DIV class='wp-pagenavi'>"
   	if Showo_CurrPage<2 then
    		strTemp=strTemp & "<a><b><</b></a>&nbsp;"
  	else
    		
    		strTemp=strTemp & "<a href='?" & cid & ""&sidl&"-" & (Showo_CurrPage-1) & ".html' class='"&styclass&"'><b><</b></a>&nbsp;"
  	end if
   for i=pagestart to pageend
     if i=showo_currpage then
	 strtemp=strtemp&"<SPAN class=current>"&i&"</span>"
	 else
     strTemp=strTemp &"<a href='?" & cid& ""&sidl&"-"&i&".html' class='"&styclass&"'>"&i&"</a>"
     end if
   next
   
   if Showo_PageCount-Showo_CurrPage<1 then
    		strTemp=strTemp & "<a><b>></b></a>&nbsp;"
  	else
    		
    		strTemp=strTemp & "<a href='?" & cid & ""&sidl&"-" & (Showo_CurrPage+1) & ".html' class='"&styclass&"'><b>></b></a>"
  	end if

   strtemp=strtemp&"</div></div></div>"
end if
   response.write strtemp
   %>
   <script language="javascript">
   function checkpage(pagecount,strurl)
   {
   if (isNaN(showPage.value))
   {
   location.href=strurl+"Page=1"
   }
   else
   { 
     if (showPage.value>pagecount)
	 {
	 location.href=strurl+"Page="+pagecount;
	  }
	 else if(showPage.value<1)
	 {location.href=strurl+"Page=1";}
	 else
	 {location.href=strurl+"Page="+showPage.value;}}
	 }
   </script>
   <%
end sub

public sub showpage1(styclass)
	dim strTemp,strUrl
	strUrl=geturlname()
	strTemp= "<table align='center'><tr><td>"
	
	strTemp=strTemp & "共 <b>" & reccount & "</b> 条&nbsp;&nbsp;"
	
  	if Showo_CurrPage<2 then
    		strTemp=strTemp & "首页 上一页&nbsp;"
  	else
    		strTemp=strTemp & "<a href='" & strUrl & "Page=1' class='"&styclass&"'>首页</a>&nbsp;"
    		strTemp=strTemp & "<a href='" & strUrl & "Page=" & (Showo_CurrPage-1) & "' class='"&styclass&"'>上一页</a>&nbsp;"
  	end if

  	if Showo_PageCount-Showo_CurrPage<1 then
    		strTemp=strTemp & "下一页 尾页"
  	else
    		strTemp=strTemp & "<a href='" & strUrl & "Page=" & (Showo_CurrPage+1) & "' class='"&styclass&"'>下一页</a>&nbsp;"
    		strTemp=strTemp & "<a href='" & strUrl & "Page=" & Showo_PageCount & "' class='"&styclass&"'>尾页</a>"
  	end if
   	strTemp=strTemp & "&nbsp;页次：<strong><font color=red>" & Showo_CurrPage & "</font>/" & Showo_PageCount & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & Showo_Pagesize & "</b> 条/页"
	
		strTemp=strTemp & "&nbsp;转到：<select name='Page' size='1' onchange=""javascript:window.location='" & strUrl & "Page=" & "'+this.options[this.selectedIndex].value;"">"   
    	for i = 1 to Showo_PageCount   
    		strTemp=strTemp & "<option value='" & i & "'"
			if cint(Showo_CurrPage)=cint(i) then strTemp=strTemp & " selected "
			strTemp=strTemp & ">第" & i & "页</option>"   
	    next
		strTemp=strTemp & "</select>"

	strTemp=strTemp & "</td></tr></table>"
	response.write strtemp
end sub
End Class%>

