<!--#include file="config.asp"-->
<%
Dim Rs,SQL,HtmlContent
Dim softid,SoftName,strAddress,SoftSize
Dim SoftContent,SoftTime,AllHits,filesize
Dim ChannelRootDir,strInstallDir,strIndexName
Dim HtmlFileUrl,HtmlFileName,strUrl

Newasp.ReadChannel(ChannelID)
ChannelRootDir = Newasp.InstallDir & Newasp.ChannelDir
strInstallDir = Newasp.InstallDir
strIndexName = "<a href='" & ChannelRootDir & "'>" & Newasp.ChannelName & "</a>"
softid = Newasp.ChkNumeric(Request.Querystring("softid"))

If softid = 0 Then
	OutAlertScript("错误的系统参数!请输入正确的软件ID")
	Response.End
End If

Newasp.LoadTemplates ChannelID, 6, Newasp.ChannelSkin
HtmlContent = Newasp.HtmlContent
HtmlContent = Replace(HtmlContent, "{$ChannelRootDir}", ChannelRootDir)
HtmlContent = Replace(HtmlContent, "{$InstallDir}", Newasp.InstallDir)
HtmlContent = Replace(HtmlContent, "{$ChannelID}", ChannelID)
HtmlContent = Replace(HtmlContent, "{$ModuleName}", Newasp.ModuleName)
HtmlContent = Replace(HtmlContent, "{$SoftIndex}", strIndexName)
HtmlContent = ReadClassMenu(HtmlContent)
HtmlContent = ReadClassMenubar(HtmlContent)

SQL = "SELECT A.softid,A.SoftName,A.SoftVer,A.Content,A.SoftSize,A.SoftTime,A.AllHits,A.HtmlFileDate,A.DownAddress,C.HtmlFileDir FROM NC_SoftList A INNER JOIN [NC_Classify] C On A.ClassID=C.ClassID WHERE A.ChannelID="& ChannelID &" And A.isAccept <> 0 And A.SoftID=" & SoftID
Set Rs = Newasp.Execute(SQL)
If Rs.EOF And Rs.BOF Then
	OutAlertScript("对不起~！没有找到你想下载的软件。")
	Set Rs = Nothing
Else
	SoftName = Rs("SoftName") &" "& Rs("SoftVer")
	strAddress = Rs("DownAddress")
	SoftTime = Rs("SoftTime")
	AllHits = Rs("AllHits")
	SoftContent = Ubbcode(Rs("Content"))
	If CLng(Rs("SoftSize")) > 0 Then
		SoftSize = ReadSoftsize(Rs("SoftSize"))
	Else
		SoftSize = "未知大小"
	End If
	filesize = CCur(Rs("SoftSize"))
	If CInt(Newasp.IsCreateHtml) <> 0 Then
		HtmlFileUrl = ChannelRootDir & Rs("HtmlFileDir") & Newasp.ShowDatePath(Rs("HtmlFileDate"), Newasp.HtmlPath)
		HtmlFileName = Newasp.ReadFileName(Rs("HtmlFileDate"), Rs("softid"), Newasp.HtmlExtName, Newasp.HtmlPrefix, Newasp.HtmlForm, "")
		strUrl = HtmlFileUrl & HtmlFileName
	Else
		strUrl = ChannelRootDir & "show.asp?id="& Rs("softid")
	End If
End If
Rs.Close:Set Rs = Nothing


HtmlContent = Replace(HtmlContent, "{$PageTitle}", SoftName)
HtmlContent = Replace(HtmlContent, "{$SoftID}", softid)
HtmlContent = Replace(HtmlContent, "{$softid}", softid)
HtmlContent = Replace(HtmlContent, "{$SoftName}", SoftName)
HtmlContent = Replace(HtmlContent, "{$strUrl}", strUrl)
HtmlContent = Replace(HtmlContent, "{$Updatetime}", SoftTime)
HtmlContent = Replace(HtmlContent, "{$SoftSize}", SoftSize)
HtmlContent = Replace(HtmlContent, "{$FileSize}", FileSize)
HtmlContent = Replace(HtmlContent, "{$AllHits}", AllHits)
HtmlContent = Replace(HtmlContent, "{$SoftContent}", SoftContent)
HtmlContent = Replace(HtmlContent, "{$ShowDownAddress}", ShowDownAddress(softid))
HtmlContent = Replace(HtmlContent, "{$SkinPath}", Newasp.SkinPath)
HtmlContent = Replace(HtmlContent,"{$InstallDir}", Newasp.InstallDir)
Response.Write HtmlContent

'================================================
'函数名：ReadSoftsize
'作  用：读取软件的大小
'================================================
Function ReadSoftsize(para)
	On Error Resume Next
	Dim strFileSize, parasize

	parasize = CCur(para)

	If parasize = 0 Then
		ReadSoftsize = "未知大小"
		Exit Function
	End If
	
	If parasize > 1024 * 1024 Then
		strFileSize = Round(parasize / 1024 / 1024, 2) & " GB"
	ElseIf parasize > 1024 Then
		strFileSize = Round(parasize / 1024, 2) & " MB"
	Else
		strFileSize = parasize & " KB"
	End If
	ReadSoftsize = strFileSize
End Function

Function ShowDownAddress(softid)
	Dim rsAddress, sqlAddress, rsDown
	Dim i, AddressNum, ordinal, SoftNameStr, s_DownloadPath
	Dim DownloadName, DownloadPath, sDownloadName, sDownloadPath
	Dim DownAddress, strDownAddress

	On Error Resume Next
	
	Set rsDown = Newasp.Execute("SELECT id,downid,DownFileName FROM [NC_DownAddress] WHERE softid=" & CLng(softid))
	If Not (rsDown.BOF And rsDown.EOF) Then
		Do While Not rsDown.EOF
			'---- 如果使用了下载服务器,就打开下载服务器数据表
			sqlAddress = "SELECT downid,DownloadName,DownloadPath,IsDisp FROM NC_DownServer WHERE ChannelID=" & ChannelID & " And depth=1 And rootid =" & rsDown("downid") & " And isLock=0 ORDER BY orders ASC"
			Set rsAddress = Newasp.Execute(sqlAddress)
			If rsAddress.EOF And rsAddress.BOF Then
				DownloadPath = ""
				DownloadName = ""
			Else
				ordinal = 1
				Do While Not rsAddress.EOF
					'---- 是否直接显示软件直接的下载地址
					'----将所有的下载服务器地址都连成一个数组
					If rsAddress("IsDisp") = 0 Then
						DownloadPath = DownloadPath & "download.asp?softid=" & softid & "&amp;downid=" & rsAddress("downid") & "&id=" & rsDown(0) & "|"
					Else
						DownloadPath = DownloadPath & rsAddress("DownloadPath") & Replace(rsDown(2), "*", ordinal) & "|"
					End If
					DownloadName = DownloadName & rsAddress("DownLoadName") & "|"
					rsAddress.MoveNext
					ordinal = ordinal + 1
				Loop
			End If
			Set rsAddress = Nothing
			rsDown.MoveNext
		Loop
	End If
	Set rsDown = Nothing
	'---- 读取下载地址字符串
	If Newasp.CheckNull(strAddress) And Trim(strAddress) <> "|||" Then
		strDownAddress = strAddress
		strDownAddress = Split(strDownAddress, "|||")
		sDownloadName = strDownAddress(0) & "|"
		s_DownloadPath = Split(strDownAddress(1), "|")
		sDownloadPath = ""
			For i = 0 To UBound(s_DownloadPath)
				If CInt(Newasp.HtmlSetting(1)) = 0 Then
					sDownloadPath = sDownloadPath & "download.asp?softid=" & softid & "&amp;down=" & i & "|"
				Else
					sDownloadPath = sDownloadPath & s_DownloadPath(i) & "|"
				End If
			Next
	Else
		sDownloadName = ""
		sDownloadPath = ""
	End If
	'---- 将下载服务器里面的下载地址和软件下载地址连成一个数组
	DownloadPath = Trim(DownloadPath & sDownloadPath)
	DownloadName = Trim(DownloadName & sDownloadName)
	DownloadPath = Split(DownloadPath, "|")
	DownloadName = Split(DownloadName, "|")
	'---- 得出下载地址数组中的维数
	If UBound(DownloadName) < UBound(DownloadPath) Then
		AddressNum = UBound(DownloadName) - 1
	Else
		AddressNum = UBound(DownloadPath) - 1
	End If
	'--- 开始重新排列下载地址直接显示到页面
	SoftNameStr = SoftName
	ordinal = 1
	i = 0
	For i = 0 To AddressNum
		DownAddress = DownAddress & Newasp.HtmlSetting(3)
		DownAddress = Replace(DownAddress, "{$Ordinal}", ordinal)
		DownAddress = Replace(DownAddress, "{$DownLoadUrl}", DownloadPath(i))
		DownAddress = Replace(DownAddress, "{$DownLoadName}", DownloadName(i))
		DownAddress = Replace(DownAddress, "{$SoftName}", SoftNameStr)
		DownAddress = Replace(DownAddress, "{$ChannelRootDir}", ChannelRootDir)
		DownAddress = Replace(DownAddress, "{$InstallDir}", Newasp.InstallDir)
		ordinal = ordinal + 1
		If i >= AddressNum Then Exit For
	Next
	ShowDownAddress = DownAddress
End Function

CloseConn
%>
