<!--#include file="conn.asp" -->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/vsidasp.asp"-->
<%
Dim Rs, SQL
Dim ID, DownID
Dim ServerID, SoftID, DownLoadUrl, DownPath
Dim isMember, MoneyNum, UserGroupName
Set Rs = server.CreateObject("adodb.recordset")
If Not IsNumeric(Request.querystring("ID")) And Request.querystring("ID") <> "" then
        Response.write "<html><head>"
        Response.write "<title>江南软件园—警告!!!</title>"
        Response.write "<meta http-equiv='Refresh' content='2; URL=http://www.xuanxi.net'>"
        Response.write "</head><Body>"
        Response.write"错误的系统参数!ID必须是数字"
        Response.write "</Body></html>"
	Response.end
Else
	ID = CLng(Request.Querystring("ID"))
End If
If Not IsNumeric(Request.querystring("downid")) And Request.querystring("downid") <> "" then
        Response.write "<html><head>"
        Response.write "<title>轩溪软件园—警告!!!</title>"
        Response.write "<meta http-equiv='Refresh' content='2; URL=http://www.xuanxi.net'>"
        Response.write "</head><Body>"
        Response.write"错误的系统参数!ID必须是数字"
        Response.write "</Body></html>"
	Response.end
Else
	DownID = CLng(Request.Querystring("downid"))
End If
If ID = "" And DownID = "" Then Response.Write ("<script>alert('您执行了非法操作！');history.go(-1)</script>")
SQL = "select DownSite,softid,serverid from NC_SoftSite where id = " & ID
Rs.Open SQL, conn, 1, 1
SoftID = Rs("softid")
DownPath = Rs("DownSite")
ServerID = Rs("ServerID")
Rs.Close
If ServerID = 0 Then
	DownLoadUrl = DownPath
Else
	SQL = "select ServerUrl from NC_ServerSite where serverid = " & DownID
	Rs.Open SQL, conn, 1, 1
	DownLoadUrl = Rs("ServerUrl") & DownPath
	Rs.Close
End If
If DownsysClass.checkpost = False Then
	Response.Write ("<script>location.href='"& DownsysClass.Setting(1) &"'</script>")
	Response.End
End If
SQL = "select NC_SoftInfo.MoneyNum,NC_SoftInfo.isMember,NC_UserGroup.GroupName from NC_SoftInfo,NC_UserGroup where NC_SoftInfo.isMember = NC_UserGroup.grades And NC_SoftInfo.softid = "& SoftID
Rs.Open SQL, conn, 1, 1
isMember = Rs("isMember")
MoneyNum = Rs("MoneyNum")
UserGroupName = Rs("GroupName")
Rs.Close
If CInt(DownsysClass.Setting(41)) = 1 And isMember > 0 Then
	If DownsysClass.memberName = Empty Then
        	Response.write "<html><head>"
        	Response.write "<title>轩溪软件园—警告!!!</title>"
        	Response.write "<meta http-equiv='Refresh' content='2; URL=user.asp'>"
        	Response.write "</head><Body>"
        	Response.write"此软件是会员软件，你还为登陆或未注册，请登陆或注册。"
        	Response.write "</Body></html>"
		Response.End
	End If
	Dim userid, username
	Dim UserMoney, DayDownNum, DayDateTime
	Dim GroupName, GroupSet, UserGrade
	username = DownsysClass.memberName
	userid = CLng(DownsysClass.memberid)
	SQL = "select NC_User.grade,NC_User.money,NC_User.DayDownNum,NC_User.DayDateTime,NC_UserGroup.GroupName,NC_UserGroup.GroupSet from NC_User,NC_UserGroup where NC_User.grade = NC_UserGroup.grades And NC_User.userid = "& userid &" And NC_User.username='" & username & "'"
	Rs.Open SQL, conn, 1, 1
	UserGrade = Rs("grade")
	UserMoney = Rs("money")
	DayDownNum = Rs("DayDownNum")
	DayDateTime = Rs("DayDateTime")
	GroupName = Rs("GroupName")
	GroupSet = Split(Rs("GroupSet"), ",")
	Rs.Close
	If DateDiff("d", DayDateTime, Now()) >= 1 Then
		SQL = "update NC_user set DayDateTime = "& DownsysClass.SqlString &",DayDownNum = 0 where userid = " & userid
		conn.Execute (SQL)
	End If
	If UserGrade < isMember Then
		Response.Write ("<script>alert('此软件是"& UserGroupName &"软件,下载此软件需要["& UserGroupName &"]或更高的会员级别；\n你是["& GroupName &"]，不能下载"& UserGroupName &"软件；\n如果你要下载此软件请联系管理员。');history.go(-1)</script>")
		Response.End
	ElseIf CLng(UserMoney) < CLng(MoneyNum) Then
		Response.Write ("<script>alert('对不起!您的点数不足。不能下载此软件\n下载本软件所需的点数："& MoneyNum &"');history.go(-1)</script>")
		Response.End
	ElseIf CInt(GroupSet(2)) <= DayDownNum And CInt(GroupSet(2)) <> 0 Then
		Response.Write ("<script>alert('对不起!您每天只能下载"& CInt(GroupSet(2)) &"个软件。\n 请明天继续下载。');history.go(-1)</script>")
		Response.End
	Else
		SQL = "select * from NC_User where userid = " & userid
		Rs.Open SQL, conn, 1, 3
		Rs("money") = CCur(Rs("money") - MoneyNum)
		Rs("DayDownNum") = Rs("DayDownNum") + 1
		Rs.update
		Rs.Close
	End If
End If
SQL = "select Hits,DayHits,WeekHits,MonthHits,HitsTime from NC_SoftInfo where softid = "& SoftID
Rs.Open SQL, conn, 1, 3
Rs("Hits") = Rs("Hits") + 1
If DateDiff("Ww", Rs("HitsTime"), Now) <= 0 Then
	Rs("WeekHits") = Rs("WeekHits") + 1
Else
	Rs("WeekHits") = 1
End If
If DateDiff("M", Rs("HitsTime"), Now) <= 0 Then
	Rs("MonthHits") = Rs("MonthHits") + 1
Else
	Rs("MonthHits") = 1
End If
If DateDiff("D", Rs("HitsTime"), Now) <= 0 Then
	Rs("DayHits") = Rs("DayHits") + 1
Else
	Rs("DayHits") = 1
	Rs("HitsTime") = Now
End If
Rs.Update
Rs.Close
Set Rs = Nothing

DownLoadUrl = DownLoadUrl & "?vsid=" & getvsid()

If CInt(DownsysClass.Setting(41)) = 1 And isMember > 0 Then
        Response.write "<html><head>"
        Response.write "<title>会员下载地址!!!</title>"
        Response.write "<meta http-equiv='Refresh' content='5; URL=" & Request.ServerVariables("HTTP_REFERER") & "'>"
        Response.write "</head><Body>"
        Response.write "此软件下载地址为：(5秒中返回)<BR>"
		Response.write "<a href=" & DownLoadUrl &">" & DownLoadUrl &"</a>"
        Response.write "</Body></html>"
Else
	Response.Redirect DownLoadUrl
End If
CloseConn
%>
