<!--#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
%>
<%
flag=request("flag")
sql=request("sql")
dim avalue(10)
i=1
curpath=Server.mappath("excel\")
Set fs = CreateObject("Scripting.FileSystemObject")
if not fs.FolderExists(curpath) then fs.CreateFolder(curpath)
Randomize
sRand=rnd
sRand=flag&year(now)&month(now)&hour(now)&minute(now)&second(now)&sRand&".CSV"
Set excelfile = fs.CreateTextFile(curpath&"\"&sRand, True)

if flag="XSFX" then
    while instr(sql,",")>0 
	    avalue(i)= mid(sql,1,instr(sql,",") - 1)   
		sql=mid(sql,instr(sql,",")+1 ,200)
		i=i+1
	wend
	excelfile.WriteLine("客户平均订单数量,"&avalue(1)&",客户平均订单金额,"&avalue(2))
	excelfile.WriteLine("订单转化率,"&avalue(3)&"%,注册会员购买率,"&avalue(4)&"%")
	excelfile.WriteLine("平均所有会员订单量,"&avalue(5)&",平均所有会员订单金额,"&avalue(6))
	excelfile.WriteLine("平均购买会员订单量,"&avalue(7)&",平均购买会员订单金额,"&avalue(8))
	excelfile.close
    set fs=nothing
%>
<script>
    opener.document.all.xsfx.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>
<%
elseif flag="HYDD" then
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
	excelfile.WriteLine("用户名,订单量")
	while not rs.eof
        excelfile.WriteLine(rs(0)&","&rs(1))
        rs.movenext
    wend
	excelfile.close
    set fs=nothing
	set rs=nothing
%>
<script>
    opener.document.all.hydd.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>
<%
elseif flag="HYGWE" then
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
	excelfile.WriteLine("用户名,购物额")
	while not rs.eof
        excelfile.WriteLine(rs(0)&","&round(rs(1),2))
        rs.movenext
    wend
	excelfile.close
    set fs=nothing
	set rs=nothing
%>
<script>
    opener.document.all.hygwe.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>
<%
elseif flag="FWCS" then
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
	excelfile.WriteLine("商品名称,访问次数")
	while not rs.eof
        excelfile.WriteLine(rs(0)&","&rs(1))
        rs.movenext
    wend
	excelfile.close
    set fs=nothing
	set rs=nothing
%>
<script>
    opener.document.all.fwcs.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>
<%
elseif flag="CSDB" then
    set rs=server.createobject("adodb.recordset")
	set rsxs=server.createobject("adodb.recordset")
    rs.open sql,conn,1,1
	sql1=request("sql1")
	rsxs.open sql1,conn,1,1
	excelfile.WriteLine("商品名称(按访问次数排名),访问次数/销售额,商品名称(按销售额排名),销售额/访问次数")
	while not rs.eof
        
		tmps=rs(0)&","&rs(1)&" / "&round(rs(2),2)&","
		if not rsxs.eof then
		    tmps=tmps&rsxs(0)&","&round(rsxs(2),2)&" / "&rsxs(1)
		    rsxs.movenext   
		else
		    tmps=tmps&","
		end if
		excelfile.WriteLine(tmps)
        rs.movenext
    wend
	excelfile.close
    set fs=nothing
	set rs=nothing
%>
<script>
    opener.document.all.csdb.innerHTML="<a href='excel/<%=sRand%>'><%=sRand%></a>";
	//opener.document.all.excelfile.innerHTML="<%=sRand%>";
    window.close();
</script>
<%
end if

'set rs=server.createobject("adodb.recordset")

'rs.open sql,conn,1,1


%>
