<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.jsp"%>
<%
  String strLevel = "../../";
%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
    //获取提交的参数
    String id = SzConvert.toSpaceStr(request.getParameter("id"));
	int iFrom = SzConvert.toInt(request.getParameter("From"));
	String moduleName = SzConvert.strWriteData(request.getParameter("moduleName"));
	String formName = SzConvert.strWriteData(request.getParameter("formName"));
	
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    
    BdStatControl statControl = new BdStatControl();
    String s[] = new String[10];
    
    Iterator iter = null;
    if (!id.equals("")) {
    	s = (String[])statControl.getInfoFromXML(id);
    } else {
    	SzConvert.initialArray(s,"");
    }
    BdFormControl bdFormControl = new BdFormControl();
    bdFormControl.getMapStatic(moduleName, formName);
    String detailTableId = bdFormControl.detailTableId;
    //字段信息

    Map fieldMap = bdFormControl.getFieldMap();
    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
    Iterator iterFormField = null;      
%>
<body>

<!-----上面的工具栏------>
<form name="formUpdate" method="post">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">
  <input type="hidden" name="From" value="<%=iFrom%>">   
<%@ include file="title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <%=SzPageHelp.saveButton()%>
      <%=SzPageHelp.backButton()%>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="600" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <input type="hidden" name="id" class="txtClass2" value="<%=s[0]%>">
  <tr>
    <td class="tdClassTitle">名称</td>
    <td><input type="text" name="statName" class="txtClass2" value="<%=s[3]%>"></td>
  </tr>
  <tr>
    <td class="tdClassTitle">统计的字段</td>
    <td>
<%
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
	int i =0;
	String temp = "," + s[5] + ",";
	while (iterFormField != null && iterFormField.hasNext()) {
		bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();			
		if (bdFormFieldInfo.getZDBJ() == 1) {
			continue;
		}
		out.println("<input type='checkbox' name='statField' value='" + bdFormFieldInfo.getZDMC() + "'");
		if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",") >=0) {
			out.println(" checked ");
		}
		out.println(" onclick='javascript:checkGroup(this);' ");
		out.println(">");
		out.println(bdFormFieldInfo.getZDSM());
		i ++;
		if (i % 4 == 0) {
			out.println("<br>");
		}
	}
%>
    &nbsp;</td>
  </tr>   
  <tr>
    <td class="tdClassTitle">分组的字段</td>
    <td>
<%
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
	i = 0;
	temp = "," + s[6] + ",";
	while (iterFormField != null && iterFormField.hasNext()) {
		bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();	
		if (	bdFormFieldInfo.getZDLX().startsWith("int") 
				|| bdFormFieldInfo.getZDLX().startsWith("numeric")
				|| bdFormFieldInfo.getZDLX().startsWith("ntext")) {
			continue;
		}
		out.println("<input type='checkbox' name='groupField' value='" + bdFormFieldInfo.getZDMC() + "'");
		if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",") >=0) {
			out.println(" checked ");
		}
		out.println(" onclick='javascript:checkState(this);' ");
		out.println(">");
		out.println(bdFormFieldInfo.getZDSM());
		i ++;
		if (i % 5 == 0) {
			out.println("<br>");
		}		
	}
%>
    &nbsp;</td>
  </tr>    
</table>

</form>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">

  function FormSave(formName, url) {

    //检查是否可以保存
    if (!notSpace(formName.statName, "名称")) {
      return false;
    }   
    //if (NumberOfCheck(formName.statField) == 0) {
	  //alert("请至少选择一个统计的字段");
	  //return false;
    //}
    if (NumberOfCheck(formName.groupField) == 0) {
	  alert("请至少选择一个分组的字段");
	  return false;
    }
    formName.action = "stat_control.jsp";
    formName.submit();
  }
  
  function checkGroup(obj){
  	var vValue = obj.value;
  	var bChecked = obj.checked?true:false;
  	var group_obj = document.getElementsByName("groupField");
  	var len = (group_obj)?group_obj.length:0;
  	for(var i=0;i<len;i++){
  		if(group_obj[i].value==vValue){
  			group_obj[i].disabled=bChecked;
  		}
  	}
  }
 
 	function checkState(obj){
  	var vValue = obj.value;
  	var bChecked = obj.checked?true:false;
  	var stat_obj = document.getElementsByName("statField");
  	var len = (stat_obj)?stat_obj.length:0;
  	for(var i=0;i<len;i++){
  		if(stat_obj[i].value==vValue){
  			stat_obj[i].disabled=bChecked;
  		}
  	}
  }
 
</script>
</body>
