<!--#include file="../inc/conn.asp"-->
<!--#include file="Inc/Admin.Asp"-->
<!--#include file="../Inc/Ubbcode.asp"-->
<!--#include file="Inc/Function.asp"-->
<%
dim rs,sql
dim ID,BigClassName,SmallClassName
dim Title,AddDate,FileSize,Language,Softclass,System,Content,Passed,Elite,PhotoUrl,UploadFiles,DownloadUrl
dim ObjInstalled

ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
ID=Trim(Request.Form("ID"))
BigClassName=trim(request.form("BigClassName"))
SmallClassName=trim(request.form("SmallClassName"))
Title=trim(request.form("Title"))
AddDate=trim(request.form("AddDate"))
FileSize=trim(request.form("FileSize"))
Language=trim(request.form("Language"))
Softclass=trim(request.form("Softclass"))
System=trim(request.form("System"))
Content=trim(request.form("Content"))
Passed=trim(request.form("Passed"))
Elite=trim(request.form("Elite"))
PhotoUrl=trim(request.form("PhotoUrl"))
UploadFiles=trim(request.form("UploadFiles"))
DownloadUrl=trim(request.form("DownloadUrl"))

sqlBig="select * from BigClass_down where BigClassName='" & BigClassName & "'"
Set rsBig= Server.CreateObject("ADODB.Recordset")
rsBig.open sqlBig,conn,1,1
rsBig.close

sqlSmall="select * from SmallClass_down where SmallClassName='" & SmallClassName & "' and  BigClassName='" & BigClassName & "'"
Set rsSmall= Server.CreateObject("ADODB.Recordset")
rsSmall.open sqlSmall,conn,1,1
rsSmall.close

if BigClassName="" then
	founderr=true
	errmsg=errmsg+"<li>未指定下载所属大类！</li>"
end if
if Title="" then
	founderr=true
	errmsg="<li>下载标题不能为空！</li>"
end if
if FileSize="" then
	founderr=true
	errmsg="<li>文件大小不能为空！</li>"
end if
if DownloadUrl="" then
	founderr=true
	errmsg=errmsg+"<li>请输入下载连接！</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg+"<li>软件简介容不能为空！</li>"
end if

if founderr=false then
	Title=dvhtmlencode(Title)
	Content=Content
	FileSize=replace(replace(replace(replace(replace(replace(FileSize,"'",""),"*",""),"?",""),"(",""),")",""),",","")
	FileSize=FileSize & " "

	if AddDate<>"" and IsDate(AddDate)=true then
		AddDate=CDate(AddDate)
	else
		AddDate=now()
	end if

	set rs=server.createobject("adodb.recordset")
	if request("action")="add" then
		sql="select top 1 * from Download" 
		rs.open sql,conn,1,3
		rs.addnew
		call SaveData()
		rs.update
		ID=rs("ID")
		rs.close
		set rs=nothing
	elseif request("action")="Modify" then
  		if ID<>"" then
			sql="select * from Download where ID=" & ID
			rs.open sql,conn,1,3
			if not (rs.bof and rs.eof) then
				call SaveData()
				rs.update
				rs.close
				set rs=nothing
 			else
				founderr=true
				errmsg=errmsg+"<li>找不到此下载，可能已经被其他人删除。</li>"
				call WriteErrMsg()
			end if
		else
			founderr=true
			errmsg=errmsg+"<li>不能确定ID的值</li>"
			call WriteErrMsg()
		end if
	else
		founderr=true
		errmsg=errmsg+"<li>没有选定参数</li>"
		call WriteErrMsg()
	end if

	call CloseConn()
%>
<!-- #include file="Inc/Head.asp" -->
<table cellpadding="2" cellspacing="1" border="0" width="510" align="center" class="border">
	<tr>
		<td class="topbg" height="25" align="center"><strong>添加 修改 下载</strong></td>
	</tr>
	<tr>
		<td align="center">
      <table width="100%"  border="0" align=center cellpadding="0" cellspacing="1" class="a3">
        <tr align=center > 
          <td  height="25" colspan="2" class="Title"><b> 
            <%if request("action")="add" then%>
            添加 
            <%else%>
            修改 
            <%end if%>
          下载成功</b></td>
        </tr>
        <tr> 
          <td width="19%" height="22"  class="tdbgl"> <p align="right">下载序号：</p></td>
          <td width="81%"  class="tdbg"><%=ID%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">标题名称：</td>
          <td  class="tdbg"><%=Title%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">整理日期：</td>
          <td  class="tdbg"><%=AddDate%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">文件大小：</td>
          <td  class="tdbg"><%=FileSize%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">软件语言：</td>
          <td  class="tdbg"><%=Language%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">授权类型：</td>
          <td  class="tdbg"><%=Softclass%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">运行环境：</td>
          <td  class="tdbg"><%=System%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">图片地址：</td>
          <td  class="tdbg"><%=PhotoUrl%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">下载地址一</td>
          <td  class="tdbg"><%=DownloadUrl%></td>
        </tr>
        <tr> 
          <td height="22" align="right"  class="tdbgl">所属类别：</td>
          <td  class="tdbg"> 
<%
response.write BigClassName
if SmallClassName<>"" then response.write " &gt;&gt; " & SmallClassName
%>          </td>
        </tr>
        <tr> 
          <td height="22" colspan="2"  class="tdbg"> 
          <p align="center"> 【<a href="Download_edit.asp?ID=<%=ID%>">修改下载</a>】&nbsp;【<a href="Download_Add.asp">继续添加下载</a>】&nbsp;【<a href="Download.asp">下载管理</a>】&nbsp;【<a href="../DownloadShow.asp?ID=<%=ID%>" target="_blank">预览下载内容</a>】</p></td>
        </tr>
      </table>
		</td>
	</tr>
</table>
<%Call GetCreateIndex%>
<!-- #include file="Inc/foot.asp" -->
<%
else
	WriteErrMsg
end if

sub SaveData()
	rs("BigClassName")=BigClassName
	rs("SmallClassName")=SmallClassName
	rs("Title")=Title
	rs("FileSize")=FileSize
	rs("Language")=Language
	rs("Softclass")=Softclass
	rs("System")=System
	rs("Content")=Content
	if Passed="yes" then
		rs("Passed")=True
	else
		rs("Passed")=False
	end if
	if Elite="yes" then
		rs("Elite")=True
	else
		rs("Elite")=False
	end if
	rs("AddDate")=AddDate
	rs("DownloadUrl")=DownloadUrl

	'删除无用的上传文件
	if ObjInstalled=True and DelUploadsoftPic="Yes" then
		dim fso,strRubbishFile
		Set fso = Server.CreateObject("Scripting.FileSystemObject")
		if instr(UploadFiles,"|")>1 then
			dim arrUploadFiles,intTemp
			arrUploadFiles=split(UploadFiles,"|")
			UploadFiles=""
			for intTemp=0 to ubound(arrUploadFiles)
				if instr(Content,arrUploadFiles(intTemp))<=0 and arrUploadFiles(intTemp)<>PhotoUrl then
					strRubbishFile=server.MapPath("" & arrUploadFiles(intTemp))
					if fso.FileExists(strRubbishFile) then
						fso.DeleteFile(strRubbishFile)
						response.write "<br><li>" & arrUploadFiles(intTemp) & "在文章中没有用到，也没有被设为首页图片，所以已经被删除！</li>"
					end if
				else
					if intTemp=0 then
						UploadFiles=arrUploadFiles(intTemp)
					else
						UploadFiles=UploadFiles & "|" & arrUploadFiles(intTemp)
					end if
				end if
			next
		else
			if instr(Content,UploadFiles)<=0 and UploadFiles<>PhotoUrl then
				strRubbishFile=server.MapPath("" & UploadFiles)
				if fso.FileExists(strRubbishFile) then
					fso.DeleteFile(strRubbishFile)
					response.write "<br><li>" & UploadFiles & "在文章中没有用到，也没有被设为首页图片，所以已经被删除！</li>"
				end if
				UploadFiles=""
			end if
		end if
		set fso=nothing
	end If
	'结束
	'***************************************
	rs("PhotoUrl")=PhotoUrl
	rs("UploadFiles")=UploadFiles
end sub
%>