<%@ 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.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="../sessionInfo2.jsp"%>
<html>
<head>
<BASE target=_self>
<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>
<body>
<%
    //列出有共同主表,共同外健的表单
    BdForm bdForm = new BdForm();
    String XML_str[] = bdForm.getXMLModuleList(0);    
    //根据moduleName获取响应的表单信息 
	String moduleName = SzConvert.strWriteData(request.getParameter("moduleName"));
    String formName = SzConvert.strWriteData(request.getParameter("formName"));
    String relateTable = SzConvert.strWriteData(request.getParameter("relateTable"));
    String relateForeign = SzConvert.strWriteData(request.getParameter("relateForeign")); 
    String detailIndex = SzConvert.strWriteData(request.getParameter("detailIndex"));
    
%>    
<table width="100%">
  <form name="formUpdate" method="post" action="relateForm_select.jsp">
  <input type="hidden" name="detailIndex" value="<%=detailIndex%>">
  <tr>
    <td>选择模块</td>
    <td><%=SzPageHelp.selectArraySubmit(XML_str, XML_str, "moduleName", moduleName, "txtClass1")%></td>
  </tr>    
  <tr>
    <td valign="top">选择表单</td>
    <td><select name="formName" style="width:150;" size="20">
<%
    //根据
    Iterator iterForm = null;
    String sFormName = "";
    BdFormInfo bdFormInfo = null;      
    if (!moduleName.equals("")) {
    	iterForm = bdForm.getFormInfoList(moduleName, 0).iterator();
    }
    String strMainTable = "";
    String strKeyField = "";
    BdFormControl bdFormControl = new BdFormControl();  
    while (iterForm != null && iterForm.hasNext()) {
      	bdFormInfo = (BdFormInfo)iterForm.next();        
      	sFormName = bdFormInfo.getFormName();    
      	//根据模块\表单获得信息信息
      	bdFormControl.getFormInfo(moduleName, sFormName);
      	strMainTable = bdFormControl.strMainTable;
      	strKeyField = bdFormControl.strKeyField;
		/*
      	if (!relateTable.equals(strMainTable) && !relateForeign.equals(strKeyField)) {
      		continue;
      	}
        */	            	
      	if (!relateTable.equals(strMainTable)) {
      		//continue;
      	}      	
%>
	<option value="<%=sFormName%>,<%=strMainTable%>" <%if(formName.equals(sFormName)) {%>selected<%}%> ><%=bdFormInfo.getFormDesc()%></option>
<%    	  
    }
%></select>
	</td>
  </tr>
  <tr>
    <td colspan="2" align="center"  class="trClassTitle">                        
      <input type="button" value="确定" class="btnClass" OnClick="Ok();">
      <input type="button" value="关闭" class="btnClass" OnClick="window.close();">
    </td>  
  </tr>    
  </form>
</table>
</body>
</html>
<script language="javascript">
  function Ok() {
	var oWindow = window.dialogArguments;
	var vModuleName = formUpdate.moduleName.value;
	var vFormName = "";
	var vTableName = "";
	var v = formUpdate.formName.value;
	var detailIndex = formUpdate.detailIndex.value;
	if (v != null) {
		var vCount = v.length;
		var vIndex = v.indexOf(",");
		if (vIndex >0 && vIndex < vCount) {
			vFormName = v.substring(0, vIndex);
			vTableName = v.substring(vIndex + 1, vCount);
		}
	}
	eval("oWindow.formUpdate.moduleName_" + detailIndex + ".value='" + vModuleName + "';");
	eval("oWindow.formUpdate.formName_" + detailIndex + ".value='" + vFormName + "';");
	var relateTable = eval("oWindow.formUpdate.relateTable.value;");
	if (relateTable == "") {
		eval("oWindow.formUpdate.relateTable.value='" + vTableName + "';");
	}
	window.close();
  }
</script>

