<!-- #include file="../conn.asp" -->
<!-- #include file="../const.asp" -->
<!-- #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>
<%call chksunzom()
mxid=requestA("id")
cid=chk0(requestA("cid"))
gid=chk0(requestA("gid"))
mxiang=requestA("mxiang")
chk=requestA("chk")

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"):mxgs=rs1("mxgs")
end if
rs1.close:set rs1=nothing

%>

<%
ggss=split(mxgs,"[")
Response.Write "<br>请按先后顺序点击执行："
for gs=0 to Cntshu(mxgs,"[")
if instr(ggss(gs),"+")<=0 and instr(ggss(gs),"-")<=0  then  mxbiaoa=ggss(gs):jjjj="+"
if instr(ggss(gs),"+")>0 then  mxbiaoa=right(ggss(gs),len(ggss(gs))-2):jjjj="+"
if instr(ggss(gs),"-")>0 then  mxbiaoa=right(ggss(gs),len(ggss(gs))-2):jjjj="-"
Response.Write "<input onclick=""location.href='mxgs.asp?id="&mxid&"&cid="&gs&"&chk=ok'"" value="""&jjjj&""&mxbiaoa&"""  type=button name=""moren"">→"
next
Response.Write "<hr>"


if chk="ok" then
gs=cid
if instr(ggss(gs),"+")<=0 and instr(ggss(gs),"-")<=0  then  mxbiaoa=ggss(gs):jjjj=""
if instr(ggss(gs),"+")>0 then  mxbiaoa=right(ggss(gs),len(ggss(gs))-2):jjjj="+"
if instr(ggss(gs),"-")>0 then  mxbiaoa=right(ggss(gs),len(ggss(gs))-2):jjjj="-"

mxida=cdatx("id","SZ_mx","where mxdat='"&mxbiaoa&"'")

if len(mxiang)>0 and CheckFields(mxbiaoa,mxiang)=1 then 
sql="select * from SZ_zd where ChannelID="&mxida&" and ShowOnForm=1 and zdbbxs=1 and (FieldName='"&mxiang&"' or  instr(zdhz,'ltj')>0)   order by OrderID desc,id asc"
else
sql="select * from SZ_zd where ChannelID="&mxida&" and ShowOnForm=1 and zdbbxs=1 and (instr(zdhz,'qucf')>0  or  instr(zdhz,'ltj')>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")
hzbt=hzbt&"<td>"&bdTitle&"</td>"

if len(mxiang)>0 and CheckFields(mxbiaoa,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# "
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 "&mxbiaoa&" where isnull(zdsh)  "
if gid>0 then sql=sql&" and gid="&gid&""
sql=sql&" group by "&staname&""

'Response.Write ""&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"><%=mxbiaoa%>自动计算</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
sql="update "&mxbiaoa&" set zdsh=1 where "&staname&"='"&rsxiao(""&staname&"")&"'"
conn.execute(sql)
%>
<tr>
<td><%=rsxiao(""&staname&"")%></td>
<%
hzsj1=split(hzsjx,"|")
for hh=1 to Cntshu(hzsjx,"|")-1
zdxxss=Conn.Execute("select zdhz,DefaultValue,Title,FieldType from SZ_zd where ChannelID="&mxida&" and FieldName='"&hzsj1(hh)&"' ")
zdhz0=zdxxss(0):zdmrz=zdxxss(1):zdlx0=zdxxss(3)

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

sql="update "&mxbiao&" set "&hzsj1(hh)&"=0 where "&hzsj1(hh)&" is null and "&staname&"='"&rsxiao(""&staname&"")&"' "
'Response.Write ""&sql&""
'Response.end
conn.execute(sql)

rs2xx=rs2xx&" "&hzsj1(hh)&"=0,"

if jjjj="-" then
hzzdzhi=""&zdxxs&""
rs1xx=rs1xx&" "&hzsj1(hh)&"="&hzsj1(hh)&"-"&CDbl(hzzdzhi)&","
elseif jjjj="+" then
hzzdzhi=""&zdxxs&""
rs1xx=rs1xx&" "&hzsj1(hh)&"="&hzsj1(hh)&"+"&CDbl(hzzdzhi)&","
else
if zdlx0=4 or zdlx0=5 then hzzdzhi=""&zdxxs&"" else hzzdzhi="'"&zdxxs&"'"
rs1xx=rs1xx&" "&hzsj1(hh)&"="&hzzdzhi&","
end if

Response.Write "<td>"&zdxxs&"</td>"
next

'rs1xx=left(rs1xx,len(rs1xx)-1)
%>
</tr>
<%
'''''''''''''''''''''
sql="select * from "&mxbiao&" where "&staname&"='"&rsxiao(""&staname&"")&"'" 
set rs1 =server.createobject("ADODB.RecordSet")	
rs1.open sql,conn,1,3
if rs1.eof then
rs1.addnew
rs1(""&staname&"")=rsxiao(""&staname&"")
rs1.update
sql="update "&mxbiao&" set "&rs2xx&"tjsj=now() where "&staname&"='"&rsxiao(""&staname&"")&"'"
conn.execute(sql)

sql="update "&mxbiao&" set "&rs1xx&"tjsj=now() where "&staname&"='"&rsxiao(""&staname&"")&"'"
conn.execute(sql)
Response.Write ""&jjjj&"OK1"&rsxiao(""&staname&"")&"："&rs1xx&""
rs1.close:set rs1=nothing
else

sql="update "&mxbiao&" set "&rs1xx&"tjsj=now() where "&staname&"='"&rsxiao(""&staname&"")&"'"
conn.execute(sql)
Response.Write ""&jjjj&"OK2"&rsxiao(""&staname&"")&"："&rs1xx&""
end if
'''''''''''''''''''''
rs1xx="":rs2xx=""


rsxiao.movenext
loop
end if
'stname="":mxbiaoa="":staname=""
%>

</table>
<%end if%>