<%@ 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.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ 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>
<%
	String type = SzConvert.toSpaceStr(request.getParameter("type"));
	String object = SzConvert.toSpaceStr(request.getParameter("object"));
	String object2 = SzConvert.toSpaceStr(request.getParameter("object2"));
	String tableobject = SzConvert.toSpaceStr(request.getParameter("tableobject"));
	String moduleNameObject = SzConvert.toSpaceStr(request.getParameter("moduleNameObject"));
	String formNameObject = SzConvert.toSpaceStr(request.getParameter("formNameObject"));
	String formIdObject = SzConvert.toSpaceStr(request.getParameter("formIdObject"));
	String strName = "";
	if (type.equals("field") || type.equals("field2")) {
		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 if (type.equals("field2")) {
    		moduleName = SzConvert.strWriteData(request.getParameter("moduleName2"));
    		formName = SzConvert.strWriteData(request.getParameter("formName2"));    		
    	} else {
    		moduleName = SzConvert.strWriteData(request.getParameter("moduleName2"));
    		formName = SzConvert.strWriteData(request.getParameter("formName2"));
    	}
    }

    BdForm bdForm = new BdForm();
    String XML_str[] = bdForm.getXMLModuleList();    
    //根据moduleName获取响应的表单信息
    
    BdModule bdModule = new BdModule();	  
	  ArrayList list = bdModule.getModuleList();
	  String str_module[] = null;
	    
		String cate_pro = SzConvert.strWriteData(request.getParameter("cate_pro") );
		String cate_fun = SzConvert.strWriteData(request.getParameter("cate_fun") );	 
    
%>    
<table width="100%">
  <form name="formUpdate" method="post" action="field_select.jsp">
  <input type="hidden" name="object" value="<%=object%>">
  <input type="hidden" name="object2" value="<%=object2%>">
  <input type="hidden" name="tableobject" value="<%=tableobject%>">
  <input type="hidden" name="type" value="<%=type%>">
  <input type="hidden" name="moduleNameObject" value="<%=moduleNameObject%>">
  <input type="hidden" name="formNameObject" value="<%=formNameObject%>">
  <input type="hidden" name="formIdObject" value="<%=formIdObject%>">
  <input type="hidden" name="navigator" value="<%=sNavigator_SESSION%>" >
  <tr>
    <td width="80">按行业分类</td>
    <td>
    	<%
    		BdCategory bdCategory = new BdCategory();
    		ArrayList listCategory = bdCategory.getProfessionList();
    		String s_name[] = new String[listCategory.size()];
    		listCategory.toArray(s_name);
    		out.println(SzPageHelp.idSelectArrayFunc(s_name, s_name, "cate_pro", cate_pro, "txtClass200", "this.form.submit()"));
    		//out.println(SzPageHelp.selectArrayFunc(listCategory, 0, 0,"cate_pro", cate_pro, "txtClass2", ""));
    	%>    
    </td>
  </tr> 
    <td width="80">按功能分类</td>
    <td>
    	<%    		
    		listCategory = bdCategory.getFunctionList();
      	s_name = new String[listCategory.size()];
    		listCategory.toArray(s_name);
    		out.println(SzPageHelp.idSelectArrayFunc(s_name, s_name, "cate_fun", cate_fun, "txtClass200", "this.form.submit()"));
    		//out.println(SzPageHelp.selectArrayFunc(listCategory, 0, 0,"cate_pro", cate_pro, "txtClass2", ""));
    	%>      
    </td>
  </tr>       
  <tr>
    <td width="80">选择模块</td>
    <td>
    	<%    		
    		out.println(SzPageHelp.selectArrayFunc(list, 0, 0,1,8,"moduleName", moduleName, "txtClass200","simpleform.xml", 5, cate_pro,6, cate_fun, "this.form.submit()"));
    	%>     
    </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();
    }
    String formId = "0";
    while (iterForm != null && iterForm.hasNext()) {
      	bdFormInfo = (BdFormInfo)iterForm.next();        
      	sFormName = bdFormInfo.getFormName();    	
      	if(formName.equals(sFormName)) {
      		formId = bdFormInfo.getFormId();
      	}
%>
	<option value="<%=sFormName%>" <%if(formName.equals(sFormName)) {%>selected<%}%> ><%=bdFormInfo.getFormDesc()%></option>
<%    	  
    }
%></select>
		<input type="hidden" name="formId" value="<%=formId%>">
	</td>
  </tr>
  <tr>
    <td valign="top"><%=strName%></td>
    <td><select name="field" size="15" style="width:200;" OnDblClick="javascript:Ok();">
<%
    //根据
    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") || type.equals("field2")) {
    			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 vObject2 = formUpdate.object2.value;

	var vTableObject = formUpdate.tableobject.value;
	var vType = formUpdate.type.value;
	var vModuleNameObject = formUpdate.moduleNameObject.value;
	var vFormNameObject = formUpdate.formNameObject.value;
	var vFormIdObject = formUpdate.formIdObject.value;
	
	var navigator = formUpdate.navigator.value;
	

	//var oWindow = window.dialogArguments;
	var oWindow = null;

	if (navigator == "MSIE") {
	  oWindow = window.dialogArguments;
	} else {
	  oWindow = window.opener;
	}
	//把表单名称，模块名称也填写过去。
	if (vType == "field") {
	    //格式为：表&字段
	    vIndex = vField.indexOf("&");
	    vLen = vField.length;	    
	    vTable = vField.substring(0,vIndex);
	    vField = vField.substring(vIndex + 1, vLen);
	    if (vTableObject != "") {
				eval("oWindow." + vTableObject + ".value='" + vTable + "';");
      } 
      if (vObject != "" && vObject != "undefined" ) {
				eval("oWindow." + vObject + ".value='" + vField + "';");		
			}
      if (vObject2 != "" && vObject2 != "undefined" ) {		
				eval("oWindow." + vObject2 + ".value='" + vField2 + "';");
			}	
			eval("oWindow.formUpdate.moduleName1.value='" + formUpdate.moduleName.value + "';");
			eval("oWindow.formUpdate.formName1.value='" + formUpdate.formName.value + "';");	
			//选择字段的话，把对应的数据表名称也填写过去，这样就不用重复去填写表名		
	} else if (vType == "field2") {
	    //格式为：表&字段
	    vIndex = vField.indexOf("&");
	    vLen = vField.length;	    
	    vTable = vField.substring(0,vIndex);
	    vField = vField.substring(vIndex + 1, vLen);
	    if (vTableObject != "") {
				eval("oWindow." + vTableObject + ".value='" + vTable + "';");
      } 
      if (vObject != "" && vObject != "undefined" ) {
				eval("oWindow." + vObject + ".value='" + vField + "';");		
			}
      if (vObject2 != "" && vObject2 != "undefined" ) {		
				eval("oWindow." + vObject2 + ".value='" + vField2 + "';");
			}	
			eval("oWindow.formUpdate.moduleName2.value='" + formUpdate.moduleName.value + "';");
			eval("oWindow.formUpdate.formName2.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 + "';");
	}
	if (vModuleNameObject != "" && vModuleNameObject != "undefined" ) {
		eval("oWindow." + vModuleNameObject + ".value='" + formUpdate.moduleName.value + "';");
  }	
	if (vFormNameObject != "" && vFormNameObject != "undefined" ) {
		eval("oWindow." + vFormNameObject + ".value='" + formUpdate.formName.value + "';");
  }	 
	if (vFormIdObject != "" && vFormIdObject != "undefined" ) {
		eval("oWindow." + vFormIdObject + ".value='" + formUpdate.formId.value + "';");
  }	   
	window.close();

  }
</script>

