<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    int iFrom = SzConvert.toInt(request.getParameter("From"));
    //取得表单的信息
    String moduleName = "";
    String formName = "";
	//根据表单取得moduleName, formName
	LcForm lcForm = new LcForm();
	LcFormInfo lcFormInfo = null;    
    if (iFormID == 0) {
    	moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
    	formName = SzConvert.toSpaceStr(request.getParameter("formName")); 
    	//
    	iFormID = lcForm.getKeyByCond(moduleName, formName); 
    } else {
    	lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(iFormID);    
    	if (lcFormInfo != null) {
    		moduleName = lcFormInfo.getBDLJ();
    		formName = lcFormInfo.getBDBY1();  
    	}
    }
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    if (moduleName.equals("") || formName.equals("")) {
    	out.println("还没有设置相关表单信息！");
    	return;
    }
    
    String sSearchCond = SzConvert.strWriteData(request.getParameter("searchCond"));
    //System.out.println(sSearchCond);
    String id  = SzConvert.toSpaceStr(request.getParameter("id"));      
    BdStatControl statControl = new BdStatControl();
    String s[] = new String[10];
    
    Iterator iter = null;
    if (!id.equals("")) {
    	s = (String[])statControl.getInfoFromXML(id);
    } else {
    	SzConvert.initialArray(s,"");
    }    
    
    String sUrl = "index.jsp";
    if (iFrom == 2) {
    	sUrl = "index_manage.jsp";
    }
    
%>
<!-----上面的工具栏------>
<%@ include file="title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="searchCond" value="<%=sSearchCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="id" value="<%=id%>">   
  <input type="hidden" name="From" value="<%=iFrom%>">   
  <tr>
    <td>  
      <%=SzPageHelp.button("图表统计","javascript:FormSubmit(formBar, 'stat.jsp');") %>    
      <%=SzPageHelp.button("返回","javascript:FormSubmit(formBar, '" + sUrl + "');") %>
      <input type="button" class="btnClass" value="导到excel" OnClick="javascript:window.open('../../upload/export/<%=szDLID_SESSION%>.xls');">
    </td>
  </tr>
  </form>
</table>
<style>
//小计样式
<!--
.litCt{background-color: #ECF5FF;}
-->
</style>
<!-----信息列表----->
<hr>
<table width="100%">
  <tr>
    <td align="center"><font size="3"><b><%=s[3] %></b></font>&nbsp;</td>
  </tr>
</table>  
<table width="750" align="center" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0" align="center">
  <form name="formList" method="post">
  <input type="hidden" name="searchCond" value="<%=sSearchCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="id" value="<%=id%>">   
  <%=statControl.printStatInfo2(id, sSearchCond, session)%>
  </form>  
</table>  
<br>
<table width="750" align="center" border="0" >
	<tr>
	<td colspan="1" align="center" valign="middle" height="30">
	<b style="color:#E800E8;font-size: 15px;">统计图表</b><br>
	<input type="radio" name="showType" value="1" checked onclick="ClickShowType(tr1);">柱状图
	<input type="radio" name="showType" value="2" onclick="ClickShowType(tr2);">折线图
	<input type="radio" name="showType" value="3" onclick="ClickShowType(tr3);">饼状图
	<b>统计字段：</b>
	<select name="showField" id="showFieldObj" class="txtClass1" onchange="">
	<%
	String[] y_str = statControl.getYFieldStr().split("-");
	String yDesc = "";
	int ilen = y_str.length;
	for(int i=0;i<ilen;i++){
		if(i == 0){
			yDesc = y_str[i];
		}
	%>
		<option value="<%=i%>"><%=y_str[i]%>
	<%} %>
	</select>
	<input type="button" name="btnOK" class="btnClassShort" value="确定" onclick="javascript:showMap();">
	&nbsp;
	</td>
	</tr>
	<%
	String filename = "";
	String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=";
	%>	
	<script language="javascript">
	var graphURL = '<%=graphURL%>';
	</script>
	<tr style="display: block;" id="tr1">
		<td align="center">
		<%
		 	filename = statControl.getBarImagePath(0, yDesc);
			if (!filename.equals("")) {
		%>
		<span id="span1"><img src="<%=graphURL+filename %>" width=500 height=300 border=0></span>
		<%
			}
		%>
		</td>
	</tr>
	<tr style="display: none;" id="tr2">
		<td align="center">
		<%
		 	filename = statControl.getSeriesImagePath(0, yDesc);
			if (!filename.equals("")) {
		%>
		<span id="span2"><img src="<%=graphURL+filename %>" width=500 height=300 border=0></span>
		<%
			}
		%>		
		</td>
	</tr>
	<tr style="display: none;" id="tr3">
		<td align="center">
		<%
			filename = statControl.getPieImagePath(0, yDesc);
			if (!filename.equals("")) {
		%>
		<span id="span3"><img src="<%=graphURL+filename %>" width=500 height=300 border=0></span>
		<%
			}
		%>		
		</td>
	</tr>
</table>  

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="searchCond" value="<%=sSearchCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="id" value="<%=id%>">   
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="searchCond" value="<%=sSearchCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="id" value="<%=id%>">    
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  function ExcelImportWin(vModule, vForm) {
	var url ="../../share/page/excel_import_win.jsp?module=" + vModule + "&formName=" + vForm;
	window.showModalDialog(url,window,"status=no;dialogWidth=580px;dialogHeight=350px");
  }
  // 创建XMLHTTPRequest对象
	function createXMLHTTPRequest(){
		var xmlhttp;
    if(window.ActiveXObject){
      try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e){
         try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) { }
    	}
		 } else if(window.XMLHttpRequest){ 
		     xmlhttp = new XMLHttpRequest(); 
		 }
		 return xmlhttp;
	} 
  function showMap(){
  	var xmlhttp = createXMLHTTPRequest();
  	
  	var selectedIndex = showFieldObj.selectedIndex;
  	var selectOption = showFieldObj.options[selectedIndex];
  	 
  	var index = selectOption.value;
  	var showDesc = selectOption.text;
  	
  	if(document.getElementById('span1')){
  		document.getElementById('span1').innerHTML='<font color=red>数据更新中，请稍候...</font>';
  	}
  	if(document.getElementById('span2')){
  		document.getElementById('span2').innerHTML='<font color=red>数据更新中，请稍候...</font>';
  	}
  	if(document.getElementById('span3')){
  		document.getElementById('span3').innerHTML='<font color=red>数据更新中，请稍候...</font>';
  	}
  	//alert(index+"---"+showDesc);
  	//return;
    var url = "stat_map_server.jsp?showIndex="+index+"&showDesc="+encodeURIComponent(showDesc);
    xmlhttp.open("get",url,true); //与服务端建立连接(请求方式post或get，地址,true表示异步)
    xmlhttp.onreadystatechange = function(){//回调函数，对服务端的响应处理，监视response状态
	   if(xmlhttp.readystate==4) { //请求状态为4表示成功
	       if(xmlhttp.status==200) {//http状态200表示OK
	       	var text = xmlhttp.responseText.replace(/[\s\u3000]/g,'');
	       	//alert(text);
	       	var ss = text.split(';');
	       	if(ss.length!=3){
	       		return;
	       	}
	       	if(document.getElementById('span1')){
		       	document.getElementById('span1').innerHTML='<img src='+graphURL+ss[0]+' width=500 height=300 border=0>';
	       	}
	       	if(document.getElementById('span2')){
		       	document.getElementById('span2').innerHTML='<img src='+graphURL+ss[1]+' width=500 height=300 border=0>';
	       	}
	       	if(document.getElementById('span3')){
		       	document.getElementById('span3').innerHTML='<img src='+graphURL+ss[2]+' width=500 height=300 border=0>';
	       	}
	       }
	    }
	  }
		xmlhttp.send(null); 
		xmlhttp.abort();
  }
  
  function ClickShowType(v) {    
    tr1.style.display = "none";
    tr2.style.display = "none";
    tr3.style.display = "none";
  
    v.style.display = "";
  }
</script>  
