<!--#include file="conn.asp"-->
<!--#include file="adminset.asp"-->
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆！');window.location.href='login.asp';</script>"
response.End
end if
if session("flag")>1 then
response.Write "<div align=center><font size=80 color=red><b>您没有此项目管理权限！</b></font></div>"
response.End
end if
if qx2<>1 then
response.Write "<div align=center><font size=80 color=red><b>您没有此项目管理权限！</b></font></div>"
response.End
end if
%>
<%
report=request("report")
if report="销售报表" then
    shead="XS"
else
    shead="KC"
end if
set rs=server.createobject("adodb.recordset")
sql=request("sql")
rs.open sql,conn,1,1
curpath=Server.mappath("excel\")
Set fs = CreateObject("Scripting.FileSystemObject")
if not fs.FolderExists(curpath) then fs.CreateFolder(curpath)
Randomize
sRand=rnd
sRand=shead&year(now)&month(now)&hour(now)&minute(now)&second(now)&sRand&".CSV"
Set excelfile = fs.CreateTextFile(curpath&"\"&sRand, True)
if shead="XS" then '销售
    if not rs.eof then
        excelfile.WriteLine("商品ID,商品名称,"&rs(3)&",销售数量,销售额")
    else
        excelfile.WriteLine("商品ID,商品名称,商品单位,销售数量,销售额")
    end if
    while not rs.eof
        excelfile.WriteLine(rs(0)&","&rs(1)&","&rs(2)&","&rs(4)&","&rs(5))
        rs.movenext
    wend
else '库存
    if not rs.eof then
        excelfile.WriteLine("商品ID,商品名称,"&rs(3)&",库存量")
    else
        excelfile.WriteLine("商品ID,商品名称,商品单位,库存量")
    end if
    while not rs.eof
        excelfile.WriteLine(rs(0)&","&rs(1)&","&rs(2)&","&rs(4))
        rs.movenext
    wend
end if
excelfile.close
set fs=nothing
%>
<script>
    opener.document.all.excelfile.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>