<%@ page contentType="text/html;charset=gbk" %>
<%@ 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.formEngine.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="/xml/formEngine2/sessionInfo2.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>
<%
    //获取提交的参数
    String id = SzConvert.toSpaceStr(request.getParameter("id"));
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
	  String moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
	  String formName = SzConvert.toSpaceStr(request.getParameter("formName"));
		BdCollect bdCollect = new BdCollect();
    String str[] = bdCollect.getInfo(id);

		if (sOPERATOR.equals("add")) {
			str[1] = moduleName;
			str[2] = formName;
			str[10] = "2"; //默认可选择明细
			str[11] = "1"; //默认可导excel
		} else if (sOPERATOR.equals("update")) {
			moduleName = str[1];
			formName = str[2];
		}
		String strPath = "";
		if (!id.equals("") && !moduleName.equals("") && !formName.equals("")) {
			BdFormControl bdFormControl = new BdFormControl();
			strPath = "share/formEngine2/collect_result.jsp?id=" + id + "&FormID=" + bdFormControl.getFormID(moduleName, formName);;
		}   	
%>
<body>

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

<!-----信息维护------>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">名称</td>
    <td colspan="3"><input type="text" name="id" value="<%=str[0]%>" size="10" <%if (sOPERATOR.equals("update")){%> readonly class="txtClass1R"<%}else {%>class="txtClass1"<%} %>> (可用字母、数字、下划线的组合，10个字以内) <font color="red">*</font></td>
  </tr>
  <tr>
    <td class="tdClassTitle">模块名称</td>
    <td><input type="text" name="moduleName" class="txtClass1R" value="<%=str[1]%>"  readonly></td>

    <td class="tdClassTitle">表单名称</td>
    <td><input type="text" name="formName" class="txtClass1R" value="<%=str[2]%>" readonly></td>
  </tr> 
  <tr>
    <td class="tdClassTitle">汇总标题</td>
    <td colspan="3"><input type="text" name="statName" class="txtClass2" value="<%=str[3]%>"><font color="red">*</font></td>
  </tr>
  <tr><input type="hidden" name="statField" value="<%=str[4]%>">
    <td class="tdClassTitle">显示的字段<br>
    	<b>(粗体的可合计)</b>
    </td>
    <td colspan="3">
    <%
    BdFormControl bdFormControl = new BdFormControl();    
    Map fieldMap = bdFormControl.getFieldMap();
    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
    Iterator iterFormField = null;    

    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		int i =0;
		String temp = "," + str[4] + ",";
		String strPrioTable = "";		
		while (iterFormField != null && iterFormField.hasNext()) {
			bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();			
			if (    bdFormFieldInfo.getZDBJ() == 1 
				 	|| bdFormFieldInfo.getZDBJ() == 3 
				 	|| bdFormFieldInfo.getZDBJ() == 34
			  ) {
					continue;
				}		
			if (!strPrioTable.equals("") && !strPrioTable.equals( bdFormFieldInfo.getTableName() )) {
				out.println("<br>");
			}				
			out.println("<span style='width:200px;'><input type='checkbox' name='statField2' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",") >=0) {
				out.println(" checked ");
			}
			out.println(">");
			if(bdFormFieldInfo.getZDLX().startsWith("int") 
					|| bdFormFieldInfo.getZDLX().startsWith("numeric")) {
				out.println("<b>");
				out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
				out.println("</b>");
			} else {
				out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());	
			}
			
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
			
			strPrioTable = bdFormFieldInfo.getTableName();
		}
		%>    
    </td>
  </tr>    
  <tr><input type="hidden" name="condField" value="<%=str[6]%>">
    <td class="tdClassTitle">模糊查询字段</td>
    <td colspan="3">
    <%
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		i = 0;
		temp = "," + str[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("<span style='width:200px;'><input type='checkbox' name='condField2' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",") >=0) {
				out.println(" checked ");
			}
			out.println(">");
			out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
		}
		%>    
    </td>
  </tr>   
  <tr><input type="hidden" name="condBetweenField" value="<%=str[7]%>">
    <td class="tdClassTitle">区间查询字段</td>
    <td colspan="3">
    <%
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		i = 0;
		temp = "," + str[7] + ",";
		while (iterFormField != null && iterFormField.hasNext()) {
			bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();	
			if (    bdFormFieldInfo.getZDBJ() == 1 
				 	|| bdFormFieldInfo.getZDBJ() == 3 
				 	|| bdFormFieldInfo.getZDBJ() == 34
			  ) {
					continue;
			}				
			if (	!bdFormFieldInfo.getZDLX().startsWith("int") 
					&& !bdFormFieldInfo.getZDLX().startsWith("numeric")
					&& bdFormFieldInfo.getZDBJ() != 4
					&& bdFormFieldInfo.getZDBJ() != 42
					&& bdFormFieldInfo.getZDBJ() != 43
					&& bdFormFieldInfo.getZDBJ() != 44) {
				continue;
			}
			out.println("<span style='width:200px;'><input type='checkbox' name='condBetweenField2' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",") >=0) {
				out.println(" checked ");
			}
			out.println(">");
			out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
		}
		%>    
    </td>
  </tr>   

  <tr>
    <td class="tdClassTitle">默认查询条件</td>
    <td colspan="3"><input type="text" name="statCond" class="txtClass2" value="<%=str[8]%>"></td>
  </tr>  
  <tr>
    <td class="tdClassTitle">备注</td>
    <td colspan="3"><input type="text" name="desc" class="txtClass2" value="<%=str[9]%>"></td>
  </tr> 
  <tr>
    <td class="tdClassTitle">导到excel</td>
    <td colspan="3">     
      <%
      	String s_id3[] = {"0","1"};
        String s_name3[] = {"不需要","需要"};
        out.println(SzPageHelp.radio("exportExcel", s_id3, s_name3, str[11]));
      %> 
    </td>  
  </tr>    
  <% if (!strPath.equals("")) { %>  
  <tr>
  	<td>访问地址</td>
  	<td colspan="3"><%=strPath%></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.id, "名称")) {
      return false;
    }
    if (!notSpace(formName.statName, "汇总标题")) {
      return false;
    }    
    if (!isLetterOrNumOrLine(formName.id.value)) {
      alert("名称只能是字母、数字、下划线的组合");
      return false;
    }  
    var statField2 = ValueOfCheck(formName.statField2)
    if (statField2 == "") {
    } else {
    	formName.statField.value = statField2;
    }
    if (statField2 == "") {
      alert("请至少选择一个显示的字段");
      return false;
    }

    formName.condField.value = ValueOfCheck(formName.condField2)
    formName.condBetweenField.value = ValueOfCheck(formName.condBetweenField2)
          
    formName.action = "control.jsp";
    formName.submit();
  }
  
  function checkGroup(obj){
  	var vValue = obj.value;
  	var bChecked = obj.checked?true:false;
  	var group_obj = document.getElementsByName("groupField2");
  	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("statField2");
  	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>
