<%@ 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="/sessionInfo.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>
<%
	String type = SzConvert.toSpaceStr(request.getParameter("type"));
	String object = SzConvert.toSpaceStr(request.getParameter("object"));
	String desc = SzConvert.toSpaceStr(request.getParameter("desc"));
	String tagName = SzConvert.toSpaceStr(request.getParameter("tagName"));
	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="desc" value="<%=desc%>">
  <input type="hidden" name="tagName" value="<%=tagName%>">
  <input type="hidden" name="tableobject" value="<%=tableobject%>">
  <input type="hidden" name="type" value="<%=type%>">
  <tr>
    <td>选择模块</td>
    <td><%=SzPageHelp.selectArraySubmit(XML_str, XML_str, "moduleName", moduleName, "")%></td>
  </tr>    
  <tr>
    <td>选择表单</td>
    <td><select name="formName" style="width:140;" 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:140;">
<%
    //根据
    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() + "&" + bdFormFieldInfo.getZDSM();
    			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 vDesc = "";
	var vObject = formUpdate.object.value;
	var desc = formUpdate.desc.value;
	var tagName = formUpdate.tagName.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);
	    vLen = vField.length;	    
	    vIndex = vField.indexOf("&");
           
	    if (vLen > vIndex) {
  	      vDesc = vField.substring(vIndex + 1, vLen);
  	      vField = vField.substring(0, vIndex);
	    }
	    
		if (eval("oWindow." + vTableObject + ".value=='';") ) {
	       	eval("oWindow." + vTableObject + ".value='" + vTable + "';");
		}
		eval("oWindow." + vObject + ".value='" + vField + "';");
		if (tagName != "") {
			eval("oWindow." + tagName + ".value='[" + vField + "]';");
		}
		if (desc != "") {
			eval("oWindow." + desc + ".value='" + vDesc + "';");
		}
		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>

