<%@ 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.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=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
	String type = SzConvert.toSpaceStr(request.getParameter("type"));
	String object = SzConvert.toSpaceStr(request.getParameter("object"));
	String tableobject = SzConvert.toSpaceStr(request.getParameter("tableobject"));
	String strName = "";
	if (type.equals("field")) {
		strName = "选择字段";		
	} else {
		strName = "选择控件";
	}    	

	String moduleName = SzConvert.strWriteData(request.getParameter("moduleName"));
    String formName = SzConvert.strWriteData(request.getParameter("formName"));
    if (moduleName.equals("") && formName.equals("")) {
    	if (type.equals("field")) {
    		moduleName = SzConvert.strWriteData(request.getParameter("moduleName1"));
    		formName = SzConvert.strWriteData(request.getParameter("formName1"));
    	} else {
    		moduleName = SzConvert.strWriteData(request.getParameter("moduleName2"));
    		formName = SzConvert.strWriteData(request.getParameter("formName2"));
    	}
    }

    BdForm bdForm = new BdForm();
    String XML_str[] = bdForm.getXMLModuleList();    
    //根据moduleName获取响应的表单信息
    
%>    
<table width="100%">
  <form name="formUpdate" method="post" action="field_select.jsp">
  <input type="hidden" name="object" value="<%=object%>">
  <input type="hidden" name="tableobject" value="<%=tableobject%>">
  <input type="hidden" name="type" value="<%=type%>">
  <tr>
    <td width="80">选择模块</td>
    <td><%=SzPageHelp.selectArraySubmit(XML_str, XML_str, "moduleName", moduleName, "txtClass200")%></td>
  </tr>    
  <tr>
    <td>选择表单</td>
    <td><select name="formName" style="width:200;" onChange="this.form.submit();">
    <option value="">===请选择===</option>
<%
    //根据
    Iterator iterForm = null;
    String sFormName = "";
    BdFormInfo bdFormInfo = null;      
    if (!moduleName.equals("")) {
    	iterForm = bdForm.getFormInfoList(moduleName).iterator();
    }
    while (iterForm != null && iterForm.hasNext()) {
      	bdFormInfo = (BdFormInfo)iterForm.next();        
      	sFormName = bdFormInfo.getFormName();    	  
%>
	<option value="<%=sFormName%>" <%if(formName.equals(sFormName)) {%>selected<%}%> ><%=bdFormInfo.getFormDesc()%></option>
<%    	  
    }
%></select>
	</td>
  </tr>
  <tr>
    <td valign="top"><%=strName%></td>
    <td><select name="field" size="15" style="width:200;">
<%
    //根据
    BdFormTableInfo bdFormTableInfo = null;
    Collection collFormTable = null;
    if (!moduleName.equals("") && !formName.equals("")) {
    	collFormTable = bdForm.getTableList(moduleName, formName);
    }
    Iterator iterFormTable = null;
    if (collFormTable != null) {
      iterFormTable = collFormTable.iterator();
    }
    
    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    Iterator iterFormField = null;
    if (!moduleName.equals("") && !formName.equals("")) {
    	collFormField = bdForm.getFieldList(moduleName, formName);
    }
    if (collFormField != null) {
      iterFormField = collFormField.iterator();
    }
    String sName = "";
    String sValue = "";
    
    String tableName = "";
    String tableId = "";    
    while (iterFormTable != null && iterFormTable.hasNext()) {
        bdFormTableInfo = (BdFormTableInfo)iterFormTable.next();
        if (bdFormTableInfo.getGLID().equals("") || bdFormTableInfo.getGLBM().equals("")) {
            continue;
        }
        tableName = bdFormTableInfo.getGLBM();
        tableId = bdFormTableInfo.getGLID();
        iterFormField = collFormField.iterator();
    	while ((iterFormField != null && iterFormField.hasNext())) {
    		bdFormFieldInfo = (BdFormFieldInfo)iterFormField.next();
            if (!tableId.equals(bdFormFieldInfo.getTableId())) {
                continue;
            }    		
    		if (type.equals("field")) {
    			sValue = tableName + "&" + bdFormFieldInfo.getZDMC();
    			sName = "[" + bdFormFieldInfo.getZDMC() + "]" + bdFormFieldInfo.getZDSM(); 
    		} else if (type.equals("object")) {
    			sValue = bdFormFieldInfo.getZDID();
    			sName = "[" + bdFormFieldInfo.getZDID() + "]" + bdFormFieldInfo.getZDSM();
    		}
%>
	<option value="<%=sValue%>"><%=sName%></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 vIndex = 0;
	var vLen = 0;
	var vTable = "";
	var vField  = formUpdate.field.value;
	var vObject = formUpdate.object.value;
	var vTableObject = formUpdate.tableobject.value;
	var vType = formUpdate.type.value;
	var oWindow = window.dialogArguments;
	
	//把表单名称，模块名称也填写过去。
	if (vType == "field") {
	    //格式为：表&字段
	    vIndex = vField.indexOf("&");
	    vLen = vField.length;	    
	    vTable = vField.substring(0,vIndex);
	    vField = vField.substring(vIndex + 1, vLen);
	    
		eval("oWindow." + vTableObject + ".value='" + vTable + "';");
		eval("oWindow." + vObject + ".value='" + vField + "';");
		eval("oWindow.formUpdate.moduleName1.value='" + formUpdate.moduleName.value + "';");
		eval("oWindow.formUpdate.formName1.value='" + formUpdate.formName.value + "';");	
		//选择字段的话，把对应的数据表名称也填写过去，这样就不用重复去填写表名		
	} else {
	    eval("oWindow." + vObject + ".value='" + vField + "';");
		eval("oWindow.formUpdate.moduleName2.value='" + formUpdate.moduleName.value + "';");
		eval("oWindow.formUpdate.formName2.value='" + formUpdate.formName.value + "';");
	}
	
	window.close();
  }
</script>

