<!-- #include file="../conn.asp" -->
<!-- #include file="../const.asp" -->
<%
sExport=requestA("export")
if sExport="" then
%>
<!-- #include file="../jq1.html" -->
<title><%=dianming%> - 数据汇总</title>
<link href="../images/sunzom.css" rel="stylesheet" type="text/css">
<style media="print" type="text/css"> .NoPrint{DISPLAY:none}</style>
<script language=javascript>
function doPrint() { 
bdhtml=window.document.body.innerHTML; 
sprnstr="<!--startprint-->"; 
eprnstr="<!--endprint-->"; 
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
window.document.body.innerHTML=prnhtml; 
window.print(); 
window.document.body.innerHTML=bdhtml;
}
function killErrors() {return true;}
window.onerror = killErrors;
</script>
<%
end if

call chksunzom()
mxid=requestA("mxid")
cid=chk0(requestA("cid"))
gid=chk0(requestA("gid"))
mxiang=requestA("mxiang")
zdso=requestA("zdso")

sql="select * from sz_mx where id="&mxid&""  
set rs1 =server.createobject("ADODB.RecordSet")	
rs1.open sql,conn,1,3
if not rs1.eof then
mxname=rs1("mxname"):mxml=rs1("mxml"):mxbiao=rs1("mxdat"):mxdat1=rs1("mxdat"):mxdat=Replace(rs1("mxdat"),""&bqz&"",""):xmname=rs1("xmname"):mxdw=rs1("mxdw")
mxms=rs1("mxms"):bbxian=rs1("bbxian"):bdys=chk0(rs1("bdys")):bid=chk0(rs1("bid")):bzd=rs1("bzd"):bbal=rs1("bbal")
end if
rs1.close:set rs1=nothing


'取得搜索关键字
soxs=chk0(requestA("soxs"))
nowstartdate=requestA("startdate") 

if nowstartdate="quan" then nowstartdate=""
if nowstartdate="now" then nowstartdate=date()
if nowstartdate="yue" or nowstartdate="" then nowstartdate=""&year(now)&"-"&month(now)&"-01"
if day(now)<8 then zhoushu=1 else zhoushu=day(now)-7
if nowstartdate="zhou" then nowstartdate=""&year(now)&"-"&month(now)&"-"&zhoushu&""
if len(nowstartdate)=""  then   nowstartdate=(date()-day(date()-1))&" 00:00:00"
nowenddate=requestA("enddate") 
if len(nowenddate)="" or nowenddate="" then  nowenddate=date()&" 23:59:59"

nowkeyword=requestA("keyword")
nowriqi=request("riqi")
nowkey2=request("key2")
if nowriqi<>"" and len(nowriqi)>3 then nowstartdate=nowriqi&" 00:00:00":nowenddate=nowriqi&" 23:59:59"
if nowstartdate<>"" and nowenddate<>"" then
if formatdatetime(nowstartdate,2)=formatdatetime(nowenddate,2) then nowriqi=formatdatetime(nowenddate,2)
if right(nowstartdate,2)<>"00" then nowstartdate=nowstartdate&" 00:00:00"
if right(nowenddate,2)<>"59" then  nowenddate=nowenddate&" 23:59:59" 
if nowstartdate>nowenddate then  Response.Write "<script language='javascript'>alert('结束时间不能小于开始时间！');history.back();</script>" :response.end

sj1=formatdatetime(nowstartdate,1):sj2=formatdatetime(nowenddate,1)
sjxx=""&sj1&"—"&sj2&""
if sj1=sj2 then sjxx=sj1
elseif nowstartdate<>"" and  nowenddate="" then
sjxx=formatdatetime(nowstartdate,1)
elseif nowstartdate="" and  nowenddate<>"" then
sjxx=formatdatetime(nowenddate,1)
end if


If sExport = "excel" Then Response.ContentType = "application/vnd.ms-excel":Response.AddHeader "Content-Disposition", "attachment; filename="&sjxx&""&mxname&".xls"
If sExport = "word" Then Response.ContentType = "application/vnd.ms-word":Response.AddHeader "Content-Disposition:", "attachment; filename="&sjxx&""&mxname&".doc"
If sExport = "csv" Then Response.ContentType = "application/csv":Response.AddHeader "Content-Disposition:", "attachment; filename="&sjxx&""&mxname&".csv"

pgxx0="&startdate="&nowstartdate&"&enddate="&nowenddate&"&id="&mxid&"&cid="&cid&"&gid="&gid&"&mxiang="&mxiang&""

if sExport="" then
%><div id="navTab" class="tabsPage NoPrint">
<form  method="POST" action="baoN.asp?mxid=<%=mxid%>&cid=<%=cid%>&gid=<%=gid%>&mxiang=<%=mxiang%>&zdso=<%=zdso%>"> <img src="../images/s.gif">选择时间段：<input name="startdate" title="开始日期" class="date" value="<%=nowstartdate%>" readonly style="width:80px">→<input title="结束日期" name="enddate" class="date" value="<%=nowenddate%>" readonly style="width:80px">
关键词：<input name="keyword" value="<%=nowkeyword%>" style="width:100px" title="输入查询关键词"><input type="submit" value="查询">&nbsp;
</form>
</div>
<%
end if
if len(mxiang)>0 and CheckFields(mxbiao,mxiang)=1 then 
sql="select * from SZ_zd where ChannelID="&mxid&" and ShowOnForm=1 and (FieldName='"&mxiang&"' or  instr(zdhz,'ltj')>0 or  instr(zdhz,'sorq')>0)   order by OrderID desc,id asc"
else
sql="select * from SZ_zd where ChannelID="&mxid&" and ShowOnForm=1 and (instr(zdhz,'qucf')>0  or  instr(zdhz,'ltj')>0  or  instr(zdhz,'sorq')>0 )   order by OrderID desc,id asc"
end if
set rsc2=conn.execute(sql)
if not rsc2.bof then
do while not rsc2.eof
zdid3=rsc2("id"):bdTitle=rsc2("Title"):bdname=rsc2("FieldName"):zdhz=rsc2("zdhz")
if instr(zdhz,"sorq")<=0 then hzbt=hzbt&"<td>"&bdTitle&"</td>"

if len(mxiang)>0 and CheckFields(mxbiao,mxiang)=1 then staname=mxiang
if instr(zdhz,"qucf")>0 then staname=bdname

if instr(zdhz,"ltj")>0  then 
zdtjs=zdtjs&"|"&bdTitle
hzbta=hzbta&"<td>"&bdTitle&"</td>":stname=stname&",sum("&bdname&") as "&bdname&"a"
end if

hzhes=hzhes&""&zdhz&"|"
if Instr(zdhz,"sorq")>0 then issorq=1:sorq=sorq&" and "&bdname&"-#SJ# " else hzsjx=hzsjx&""&bdname&"|"
if Instr(zdhz,"sook")>0 then sozd=sozd&""&bdname&"|"
'hzsjx=hzsjx&""&bdname&"|"

rsc2.movenext
loop
end if
rsc2.close:set rsc2=nothing



sql="select "&staname&""&stname&" from "&mxbiao&" where 1=1 "
'sql="select * from "&mxbiao&" where 1=1 "  


'if gid>0 then sql=sql&" and gid="&gid&""
'if nowuserid=1 or instr(nowqx,"admall")>0 then
'elseif soxs=1 then
'sql=sql&" and Instr('"&nowxs&"',zduser)>0 "
'else
'sql=sql&" and zduser='"&nowuser&"' "
'end if

if nowstartdate<>"" then 
if issorq=1 then sorqa=replace(sorq,"#SJ#","#"&nowstartdate&"#>=0"):sql=sql&" "&sorqa&" "  else  sql=sql&" and tjsj-#"&nowstartdate&"#>=0"
end if
if nowenddate<>"" then 
if issorq=1 then  sorqb=replace(sorq,"#SJ#","#"&nowenddate&"#<=0"):sql=sql&" "&sorqb&" "  else  sql=sql&" and tjsj-#"&nowenddate&"#<=0"
end if
  
if nowkeyword<>"" then
if len(zdso)>2 then sozd=sozd&""&zdso&"|"
soxx1=split(sozd,"|")
for ss=0 to Cntshu(sozd,"|")-1
soxxs=soxxs&" "&soxx1(ss)&" like '%"&nowkeyword&"%' or"
next  
if soxxs<>"" then soxxs1=" and ("&left(soxxs,len(soxxs)-2)&") "
sql=sql&soxxs1
pgxx="&keyword="&escape(nowkeyword)&"&key2="&nowkey2&""&pgxx0&""
else
pgxx="&key2="&nowkey2&""&pgxx0&""
end if 
  
'if request("order1")<>"" then sql=sql&" order by tjsj "&request("order1") else  sql=sql&" order by id desc"  

sql=sql&" group by "&staname&""

'Response.Write "<hr>"&sql&""
'Response.end

set rsxiao =server.createobject("ADODB.RecordSet")	
rsxiao.open sql,conn,3,3
if not rsxiao.eof then
%><%'=sql%><!--startprint-->
<p align="center"><b><font style="font-size: 17pt"><%=mxname%><%=nowkeyword%>汇总报表</font></b>&nbsp; &nbsp; <%=sjxx%></p><hr>
<table width="100%" cellspacing="0" cellpadding="3" border="1" bordercolor="#000000" style="border-collapse: collapse">
<tr>
<%=hzbt%>
</tr>
<%
do while not rsxiao.eof
'zdid=rsxiao("id"):gid=rsxiao("gid")
%>
<tr>
<td><%=rsxiao(""&staname&"")%></td>
<%
'Response.Write ""&hzsjx&"|"&sql&""
'Response.end  

hzsj1=split(hzsjx,"|")
for hh=1 to Cntshu(hzsjx,"|")-1
zdxxss=Conn.Execute("select zdhz,DefaultValue,Title,FieldType from SZ_zd where ChannelID="&mxid&" and FieldName='"&hzsj1(hh)&"' ")
zdhz0=zdxxss(0):zdmrz=zdxxss(1):zdlx0=zdxxss(3)
if instr(zdhz0,"ltj")>0  then zdhz1=zdxxss(2):tjsjc=tjsjc&"[#]"&zdhz1&"|"&CDbl(chk0(rsxiao(""&hzsj1(hh)&"a")))&""
'if instr(zdhz0,"mohe")>0 and instr(zdmrz,"|")>0  then
'zddat0=split(zdmrz,"|")(0)
'zddat1=split(zdmrz,"|")(1)
'zdxxs=chk0(Conn.Execute("select sum("&zddat1&") from "&zddat0&" where gid="&zdid&"")(0))
'if zdlx0=4 or zdlx0=5 then hzzdzhi=""&hzsj1(hh)&"a="&zdxxs&"" else hzzdzhi=""&hzsj1(hh)&"a='"&zdxxs&"'"
'sql="update "&mxbiao&" set "&hzzdzhi&" where id="&zdid&""
'conn.execute(sql)
'zdxxs=zdxxs&hzzdzhi&"|"&zdid
'else
'Response.Write "<hr>"&sql&"|"&hzsj1(hh)&"a"
'Response.end

zdxxs=rsxiao(""&hzsj1(hh)&"a")
'zdxxs=""&hzsj1(hh)&"a"

'end if
'if instr(zdhz0,"sook")>0 then zdxxs="<a href=""hz.asp?keyword="&escape(zdxxs)&""&pgxx0&""">"&zdxxs&"</a>"  
Response.Write "<td>"&zdxxs&"</td>"
next%>
</tr>
<%
'end if
rsxiao.movenext
loop
end if
%>
<%
zzdd=split(zdtjs,"|")
for zz=1 to Cntshu(zdtjs,"|")
if zz>1 then hhe0=0
ttss=split(tjsjc,"[#]")
for tt=1 to Cntshu(tjsjc,"[#]")
if zzdd(zz)=split(ttss(tt),"|")(0) then 
hhe0=hhe0+CDbl(split(ttss(tt),"|")(1))
end if
hhe1=hhe0
next

if instr(hzbta,">"&zzdd(zz)&"")>0 then hzbta=replace(hzbta,">"&zzdd(zz)&"",">"&hhe1&"")
'hhee=hhee&""&zzdd(zz)&"："&FormatNumber(hhe1,2,-2)&"，"
next
if right(hhee,1)="，" then hhee=left(hhee,len(hhee)-1)
%>
<tr><td>合计</td><%=hzbta%></tr>
</table><!--endprint--><%
if sExport="" then%>
<span><%=dayin%>  &nbsp;&nbsp;<a title="数据导出为Excel" href="baoN.asp?mxid=<%=mxid%>&cid=<%=cid%>&gid=<%=gid%>&export=excel&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&mxiang=<%=mxiang%>&zdso=<%=zdso%>" target="dwzExport" targetType="navTab" title="实要导出这些记录吗?"><img src="../images/exportxls.gif" width="16" height="16" border="0" class="NoPrint"></a>
&nbsp;&nbsp;<a title="数据导出为WORD" href="baoN.asp?mxid=<%=mxid%>&cid=<%=cid%>&gid=<%=gid%>&export=word&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&mxiang=<%=mxiang%>&zdso=<%=zdso%>"  targetType="navTab" title="实要导出这些记录吗?"><img src="../images/exportdoc.gif" width="16" height="16" border="0" class="NoPrint"></a>
&nbsp;&nbsp;<a title="数据导出为CSV" href="baoN.asp?mxid=<%=mxid%>&cid=<%=cid%>&gid=<%=gid%>&export=csv&keyword=<%=escape(nowkeyword)%>&startdate=<%=nowstartdate%>&enddate=<%=nowenddate%>&mxiang=<%=mxiang%>&zdso=<%=zdso%>"  targetType="navTab" title="实要导出这些记录吗?"><img src="../images/exportcsv.gif" width="16" height="16" border="0" class="NoPrint"></a></span>
<%end if%>