<!-- #include file="conn.asp" -->
<!-- #include file="cls_main.asp" -->
<% dim obj
set obj = New DownloadVip
	obj.AspInit()
set obj = nothing


class DownloadVip

	Private ID, i, Mesky
	Private Sub Class_Initialize()
		Set Mesky = New Cls_Main
	End Sub
	Private Sub Class_Terminate()
		Set Mesky = Nothing
	End Sub
	Public Sub AspInit()
	
		If Request.QueryString("ID") = "" Then
			Response.Write "非法操作！指定的参数不正确。"
			Response.End
		ElseIf IsNumeric(Request.QueryString("ID")) = False Then
			Response.Write "非法操作！指定的参数不正确。"
			Response.End
		Else
			ID = CLng(Request.QueryString("ID"))
		End If
		
		If Mesky.MemberUserName = "" Then
			Response.Write "本页面供本站会员访问，<a href=""UserLogin.asp?url=" & Mesky.ScriptName & """>点击此处打开会员登录页</a>"
		Else
			Call Main
		End If
	
	End Sub
	Private Sub Main()
		Dim UserPoints, UserClass, UserPassword, UserVipType
		Dim Rs
		Set Rs = Mesky.Execute("select UserID,UserName,Points,UserClass,VipType,VipEndDate,UserState,UserPassword from Mesky_User where UserName = '" & Mesky.MemberUserName & "'")
		If Rs.BOF And Rs.EOF Then
			Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）不存在，可能已经被删除，请联系管理员。"
			Set Rs = Nothing
			Exit Sub
		End If
		If Rs(6) = 0 Then
			Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）已经被锁定，请联系管理员。"
			Set Rs = Nothing
			Exit Sub
		End If
		If Rs(6) = 2 Then
			Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）正等待管理员通过验证，请联系管理员。"
			Set Rs = Nothing
			Exit Sub
		End If
		If Rs(4) = 2 Then
			If Rs(5) < Now() Then
				Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）已经于 : " & Rs(5) & " 过期，请立即充值。"
				Exit Sub
			End If
		ElseIf Rs(4) = 0 Then
			Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）是普通性质用户，不能进行会员下载，请联系管理员。"
			Exit Sub
		End If
		UserPoints = Rs(2)
		UserClass = Rs(3)
		UserPassword = Rs(7)
		UserVipType = Rs(4)
		Set Rs = Nothing
		
		Set Rs = Mesky.Execute("select ID,ResName,ResVer,UserPoints,UserClass,UserName,DownloadUser from Mesky_Down_Resource where ID = " & ID)
		If Rs.BOF And Rs.EOF Then
			Response.Write "此软件不存在，可能已经被删除。"
			Set Rs = Nothing
			Exit Sub
		End If
		If UserClass < Rs(4) Then '级别
			Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）级别小于 " & Rs(4) & " 级，不能进行下载，请联系管理员。"
			Set Rs = Nothing
		End If
		
		If UserVipType = 1 and Mesky.ItemInList(Mesky.MemberUserName,Rs(6)) = False Then '点数用户
			If IsNull(Rs(6)) Or Rs(6) = "" Then
				If UserPoints < Rs(3) Then
					Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）点数小于 " & Rs(3) & " 点，不能进行下载，请立即充值。"
					Set Rs = Nothing
					Exit Sub
				Else
					Mesky.Execute ("Update Mesky_User Set Points = Points - " & Rs(3) & " where UserName = '" & Mesky.MemberUserName & "'")
					Response.Write "系统消息：您已经消费了 " & Rs(3) & " 点<br>"
				End If
			Else
				If Mesky.ItemInList(Mesky.MemberUserName, Rs(6)) = False Then
					If UserPoints < Rs(3) Then
						Response.Write "Sorry！您的用户帐号（" & Mesky.MemberUserName & "）点数小于 " & Rs(3) & " 点，不能进行下载，请立即充值。"
						Set Rs = Nothing
						Exit Sub
					Else
						Mesky.Execute ("Update Mesky_User Set Points = Points - " & Rs(3) & " where UserName = '" & Mesky.MemberUserName & "'")
						Response.Write "系统消息：您已经消费了 " & Rs(3) & " 点<br>"
					End If
				End If
			End If
			If IsNull(Rs(6)) Or IsNull(Rs(6) = "") Then
				Mesky.Execute("update Mesky_Down_Resource set DownloadUser ='"&Mesky.MemberUserName&"' where ID = " & ID)
			Else
				Mesky.Execute("update Mesky_Down_Resource set DownloadUser = DownloadUser & ',"&Mesky.MemberUserName&"' where ID = " & ID)
			End If
		End If
		
		Set Rs = Nothing
		Call UpdateHits(ID)
		Call Mesky.LoadSetting
		Response.Write showDownloadAddress(ID, Mesky.Setting(66))
	End Sub
	Private Sub UpdateHits(ResID)
		Dim Rs
		Set Rs = Mesky.Execute("select HitsTotal,DateMonth,DateWeek,DateToday from Mesky_Down_Resource where ID=" & ResID)
		'更新软件下载次数
		Mesky.Execute ("update Mesky_Down_Address set Hits=Hits+1 where ID=" & ID)
		Mesky.Execute ("update Mesky_Down_Resource set HitsTotal=HitsTotal+1,HitsMonth=HitsMonth+1,HitsWeek=HitsWeek+1,HitsToday=HitsToday+1 where ID=" & ResID)
		If DateDiff("H", Rs(3), Now) >= 24 Then Mesky.Execute ("update Mesky_Down_Resource set DateToday=" & SqlNowString & ",HitsToday=1 where ID=" & ResID)
		If DateDiff("D", Rs(2), Now) >= 8 Then Mesky.Execute ("update Mesky_Down_Resource set DateWeek=" & SqlNowString & ",HitsWeek=1 where ID=" & ResID)
		If DateDiff("D", Rs(1), Now) >= 31 Then Mesky.Execute ("update Mesky_Down_Resource set DateMonth=" & SqlNowString & ",HitsMonth=1 where ID=" & ResID)
		Set Rs = Nothing
	End Sub
	'下载地址
	Private Function showDownloadAddress(ID, brNum)
		Dim sRs, aRs, s, arrDownloadName, arrDownloadURL, i
		Set sRs = Mesky.Execute("select * from Mesky_Down_Address where ResourceID=" & ID & "")
		If Not (sRs.EOF And sRs.BOF) Then
			Do While Not sRs.EOF
			If sRs("SiteID") > 0 Then '使用预定义
				's = s & "<a href=""Download.asp"""
				Set aRs = Mesky.Execute("select ID,DownloadName,DownloadURL,isLB from Mesky_Down_SiteSetting where ID = " & sRs("SiteID"))
				arrDownloadName = Split(aRs(1), ",")
				arrDownloadURL = Split(aRs(2), ",")
					s = s & ("<img src=""images/d_download.gif"" align=""absmiddle"" border=""0""> <b>下载“" & sRs("Name") & "”</b><br>")
					For i = 0 To UBound(arrDownloadName)
						s = s & "·<a href=""" & arrDownloadURL(i) & sRs("URL") & """>" & arrDownloadName(i) & "</a>　"
						If ((i + 1) Mod brNum) = 0 Then s = s & "<br>"
					Next
				Set aRs = Nothing
			Else '不使用预定义
				s = s & "<img src=""images/d_download.gif"" align=""absmiddle"" border=""0""> <a href=""" & sRs("URL") & """>" & sRs("Name") & "</a><br>"
			End If
			sRs.MoveNext
			Loop
			End If
		Set sRs = Nothing
		showDownloadAddress = s
		s = Null
	End Function


End class
%>