<%
Class CommonCls
	   Private LocalCacheName, Cache_Data,CacheData,CacheChannel,CacheClass,Reloadtime
        Public KSCache
		Public SiteSN
		Public Version,PointName,PointUnit,PointStr

	  Private Sub Class_Initialize()
		Set KSCache = New ClsCache
		Call KSCMSInitialize
      End Sub
	 Private Sub Class_Terminate()
	   Set KSCache=Nothing
	 End Sub
	'检查是否是数字 ，并转换为长整型
	Public Function ChkClng(ByVal str)
		If str<>"" and IsNumeric(str) Then
			ChkClng = CLng(str)
		Else
			ChkClng = 0
		End If
	End Function

	'**************************************************
	'函数名：ShowPagePara
	'作  用：显示“上一页 下一页”等信息
	'参  数：filename  ----链接地址
	'       TotalNumber ----总数量
	'       MaxPerPage  ----每页数量
	'       ShowAllPages ---是否用下拉列表显示所有页面以供跳转。
	'       strUnit     ----计数单位,CurrentPage--当前页,ParamterStr参数
	'返回值：无返回值
	'**************************************************
	Public Function ShowPagePara(totalnumber, MaxPerPage, FileName, ShowAllPages, strUnit, CurrentPage, ParamterStr)
		  Dim N, I, PageStr
				Const Btn_First = "<font face='webdings' size='1' title='第一页'>9</font>" '定义第一页按钮显示样式
				Const Btn_Prev = "<font face='webdings' size='1' title='上一页'>3</font>" '定义前一页按钮显示样式
				Const Btn_Next = "<font face='webdings' size='1' title='下一页'>4</font>" '定义下一页按钮显示样式
				Const Btn_Last = "<font face='webdings' size='1' title='最后一页'>:</font>" '定义最后一页按钮显示样式
				  PageStr = ""
					If totalnumber Mod MaxPerPage = 0 Then
						N = totalnumber \ MaxPerPage
					Else
						N = totalnumber \ MaxPerPage + 1
					End If
				If N > 1 Then
					PageStr = PageStr & ("页次：<font color=red>" & CurrentPage & "</font>/" & N & "页 共有:" & totalnumber & strUnit & " 每页:" & MaxPerPage & strUnit & " ")
					If CurrentPage < 2 Then
						PageStr = PageStr & Btn_First & " " & Btn_Prev & " "
					Else
						PageStr = PageStr & ("<a href=" & FileName & "?page=1" & "&" & ParamterStr & ">" & Btn_First & "</a> <a href=" & FileName & "?page=" & CurrentPage - 1 & "&" & ParamterStr & ">" & Btn_Prev & "</a> ")
					End If
					
					If N - CurrentPage < 1 Then
						PageStr = PageStr & " " & Btn_Next & " " & Btn_Last & " "
					Else
						PageStr = PageStr & (" <a href=" & FileName & "?page=" & (CurrentPage + 1) & "&" & ParamterStr & ">" & Btn_Next & "</a> <a href=" & FileName & "?page=" & N & "&" & ParamterStr & ">" & Btn_Last & "</a> ")
					End If
					If ShowAllPages = True Then
						PageStr = PageStr & ("GO:<select  onChange='location.href=this.value;' style='width:55;' name='select'>")
				   For I = 1 To N
					 If Cint(CurrentPage) = I Then
						PageStr = PageStr & ("<option value=" & FileName & "?page=" & I & "&" & ParamterStr & " selected>NO." & I & "</option>")
					 Else
						 PageStr = PageStr & ("<option value=" & FileName & "?page=" & I & "&" & ParamterStr & ">NO." & I & "</option>")
					 End If
				   Next
				  PageStr = PageStr & "</select>"
				  End If
			 End If
			 ShowPagePara = PageStr
	End Function
	Sub ShowPageParamter(totalnumber, MaxPerPage, FileName, ShowAllPages, strUnit, CurrentPage, ParamterStr)
		Response.Write (ShowPagePara(totalnumber, MaxPerPage, FileName, ShowAllPages, strUnit, CurrentPage, ParamterStr))
	End Sub

	'**************************************************
	'函数名：MakeRandom
	'作  用：生成指定位数的随机数
	'参  数： maxLen  ----生成位数
	'返回值：成功:返回随机数
	'**************************************************
	Public Function MakeRandom(ByVal maxLen)
	  Dim strNewPass,whatsNext, upper, lower, intCounter
	  Randomize
	 For intCounter = 1 To maxLen
	   upper = 57:lower = 48:strNewPass = strNewPass & Chr(Int((upper - lower + 1) * Rnd + lower))
	 Next
	   MakeRandom = strNewPass
	End Function
	'生成随机密码
	
	Function Encrypt(ecode)
	dim texts,i
	for i=1 to len(ecode)
	texts=texts & chr(asc(mid(ecode,i,1))+3)
	next
	Encrypt = texts
	End Function
	'解密
	Function Decrypt(dcode)
	dim texts,i
	for i=1 to len(dcode)
	texts=texts & chr(asc(mid(dcode,i,1))-3)
	next
	Decrypt=texts
	End Function

	
	'取得Request.Querystring 或 Request.Form 的值
	Public Function G(Str)
	 G = Replace(Replace(Request(Str), "'", ""), """", "")
	End Function


  '======================================================================================
End Class

'通用缓存类
Class ClsCache
        Private cache           '缓存内容
        Private cacheName       '缓存Application名称
        Private expireTime      '缓存过期时间
        Private expireTimeName  '缓存过期时间Application名称
        Private vaild           'ansir添加
		Private Sub Class_Initialize()
		End Sub
        Private Sub Class_Terminate()
		End Sub
		Property Get Version()
         Version = "Kesion Cache"
		End Property
		
		Property Get valid() 
		If IsEmpty(cache) Or (Not IsDate(expireTime)) Then
		vaild = False
		Else
		valid = True
		End If
		End Property
		
		Property Get value()
		If IsEmpty(cache) Or (Not IsDate(expireTime)) Then
		value = Null
		ElseIf CDate(expireTime) < Now Then
		value = Null
		Else
		value = cache
		End If
		End Property
		
		Public Property Let name(str)
		cacheName = str
		cache = Application(cacheName)
		expireTimeName = str & "_expire"
		expireTime = Application(expireTimeName)
		End Property
		
		Public Property Let expire(tm)
		expireTime = tm
		Application.Lock
		Application(expireTimeName) = expireTime
		Application.UnLock
		End Property
		
		Public Sub add(varCache, varExpireTime) 
		If IsEmpty(varCache) Or Not IsDate(varExpireTime) Then
		Exit Sub
		End If
		cache = varCache
		expireTime = varExpireTime
		Application.Lock
		Application(cacheName) = cache
		Application(expireTimeName) = expireTime
		Application.UnLock
		End Sub
		
		Public Sub clean()
		Application.Lock
		Application(cacheName) = Empty
		Application(expireTimeName) = Empty
		Application.UnLock
		cache = Empty
		expireTime = Empty
		End Sub
		 
		Public Function verify(varcache2) 
		If TypeName(cache) <> TypeName(varcache2) Then
			verify = False
		ElseIf TypeName(cache) = "Object" Then
			If cache Is varcache2 Then
				verify = True
			Else
				verify = False
			End If
		ElseIf TypeName(cache) = "Variant()" Then
			If Join(cache, "^") = Join(varcache2, "^") Then
				verify = True
			Else
				verify = False
			End If
		Else
			If cache = varcache2 Then
				verify = True
			Else
				verify = False
			End If
		End If
		End Function
End Class
%> 
