<%@ 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.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=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
    //获取提交的参数
    String name = SzConvert.toSpaceStr(request.getParameter("name"));
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    String moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
    String formName = SzConvert.toSpaceStr(request.getParameter("formName"));
    BdTransfer bdTransfer = new BdTransfer();
    String str[] = bdTransfer.getInfo(name);
    
    if (sOPERATOR.equals("add")) {
			str[1] = moduleName;
			str[2] = formName;

    } else if (sOPERATOR.equals("update")) {
			moduleName = str[1];
			formName = str[2];
    }
	  BdFormHelp formHelp = new BdFormHelp();
	  BdModule bdModule = new BdModule();	  		
	  ArrayList formList = formHelp.getFormList(moduleName);
    Iterator iterForm = null;  		
    String temp = "";
    int i =0;
%>
<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="name" 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="desc" class="txtClass2" value="<%=str[3]%>"></td>
  </tr>
  <tr>
    <td class="tdClassTitle"><a href="#" onClick="javascript:SelectWin('formUpdate.fieldName', '');">关联字段</td>
    <td colspan="3"><input type="text" name="fieldName" class="txtClass1" value="<%=str[4]%>">与转移的表单对应的关联字段关联</td>
  </tr>  
  <tr>
    <td class="tdClassTitle">转移的表单</td>
    <td colspan="3"><input type="hidden" name="relateFormName" id="relateFormName" value="<%=str[5]%>">
    <input type="hidden" name="relateField" id="relateField" value="<%=str[6]%>">
    <%
    if (formList != null) {
    	iterForm = formList.iterator();
    }    
		temp = str[5];
		i = 0;
		String str_form[] = null;
		/*
		    str_form[0] = bdFormInfo.getFormName();
      	str_form[1] = bdFormInfo.getFormDesc();
      	str_form[2] = bdFormInfo.getFormId();
      	str_form[3] = moduleName;
    */
    
    String str_formName[] = str[5].split(",");
    String str_field[] = str[6].split(",");
    int iLen = str_formName.length;
    int j = 0;
    String strField = "";
		while (iterForm != null && iterForm.hasNext()) {
			str_form = (String[])iterForm.next();	
			if (str_form == null) {
					continue;
			}
			strField = "";
			//out.println("<input type='hidden' name='formName" + i + "' id='formName" + i + "' value='" + str_form[0] + "'>");	
			out.println("<span style='width:280px;'><input type='checkbox' name='formName" + i + "' id='formName" + i + "' value='" + str_form[0] + "'");
			for (j = 0; j<iLen; j++) {
				if (str_formName[j] != null && !str_formName[j].equals("") 
						&& str_formName[j].equals(str_form[0]) && !str_field[j].equals("") ) {
					strField = str_field[j];
					out.println(" checked ");
				}
			}

			out.println(">");
			out.println(str_form[0] + " " + str_form[1]);
			out.println("</span>");
			out.println("<span>");
			out.println("<a href=\"#\" onClick=\"javascript:SelectWin('formUpdate.txtField" + i + "', '" + i + "');\">对应的关联字段</a>");
			out.println(" <input type=\"text\" name=\"txtField" + i + "\"  id=\"txtField" + i + "\" value=\"" + strField + "\" class=\"txtClass1\">");

			i ++;
			out.println("</span><br>");

		}
		%>	
		<input type="hidden" name="count" id="count" value="<%=i%>">
    </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.name, "名称")) {
      return false;
    }  
    if (!notSpace(formName.fieldName, "关联字段")) {
      return false;
    }      
    var count = formName.count.value;
    var oForm = null;
    var form = "";
    var field = "";
    var relateFormName = "";
    var relateField = "";
    for (var i =0; i<count; i++) {
      oForm = document.getElementById("formName" + i);
    	form = oForm.value;
    	field = document.getElementById("txtField" + i).value;
    	
    	if (oForm.checked == true && field != "") {
    		relateFormName += "," + form;
    		relateField += "," + field;
    	}
    }
    
		
      
	  if (relateFormName == "") {
		  alert("请至少选择一个转移的表单及对应的关联字段");
		  return false;
	  } 
		formName.relateFormName.value= relateFormName;
		formName.relateField.value= relateField;

    formName.action = "control.jsp";
    formName.submit();
  }
  
  function SelectWin(vObject, i) {
		var moduleName = formUpdate.moduleName.value;
    var formName = eval("formUpdate.formName" + i + ".value");
        
    var url = "../field_select_simple.jsp?object=" + vObject
            + "&moduleName=" + moduleName + "&formName=" + formName;
    window.showModalDialog(url,window,"status=no;dialogWidth=300px;dialogHeight=370px");  
  }
  

   
</script>
</body>
