<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="../sessionInfo2.jsp"%>
<html>
<body>
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<%
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    String sRelate = SzConvert.toSpaceStr(request.getParameter("relate"));
    String sObjectType = SzConvert.toSpaceStr(request.getParameter("ObjectType"));    
    BdReadSelectXML3 readSelectXML3 = new BdReadSelectXML3();
    //获取已经设置的详细信息
    BdSelectTableInfo3 tableInfo = (BdSelectTableInfo3)readSelectXML3.getTableInfoFromXML(sRelate);
    if (tableInfo == null) {
    	tableInfo = new BdSelectTableInfo3();
    	tableInfo.setGLTJ("1=1");
    }
    if (sOPERATOR.equals("")) {
    	sOPERATOR = "set";
    }
    String sFormType = (String)session.getAttribute("SzFormType");
%>

<form name="formUpdate" method="post" action="formSave.jsp">
<input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
<input type="hidden" name="ObjectType" value="<%=sObjectType%>">
<input type="hidden" name="moduleName" value="<%=sFormType%>">
<input type="hidden" name="moduleName1" value="">
<input type="hidden" name="formName1" value="">
<input type="hidden" name="moduleName2" value="">
<input type="hidden" name="formName2" value="">
<table width="550" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass"
       cellpadding="3" cellspacing="0" align="center">  
  <tr>
    <td colspan="4">
    <%
    if (sOPERATOR.equals("set")) {
      String s_name[] = readSelectXML3.getTableName();
    	out.println("请选择关联信息：");
    	out.println(SzPageHelp.idSelectArrayFunc(s_name, s_name, "relate", sRelate, "txtClass1", "SelectRelate();"));
    }
    %> 
    </td>
  </tr>  
          
  <tr>
    <td colspan="4" class="trClassTitle">==列表选择的主信息设置==</td>
  </tr>         
  <tr>
    <td>关联名称</td>
    <td colspan="3">     
      <input type="text" name="relateName" value="<%=tableInfo.getGLSM() %>"  class="txtClass300">
      <font color="red">*</font>
    </td>
  </tr>
  <tr>
    <td>控件类型</td>
    <td colspan="3">     
      <%
      	String s_id2[] = {"0","1"};
        String s_name2[] = {"下拉列表","radio选择"};
        out.println(SzPageHelp.radio("relateType", s_id2, s_name2, tableInfo.getGLLX()));
      %> 
    </td>
  </tr>  
  <tr>
    <td>关联说明</td>
    <td colspan="3"> 
       <input type="text" name="relateDesc" value="<%=tableInfo.getGLBZ()%>"  class="txtClass2">
    </td>
  </tr>   
  <tr>
    <td colspan="4" class="trClassTitle">==列表选择的主表信息设置==</td>
  </tr>    
  <tr>
    <td>关联主表</td>
    <td>     
       <input type="text" name="tableName" value="<%=tableInfo.getGLBM()%>"  class="txtClass1">
       <font color="red">*</font>
    </td>
    <td><a href="#" onClick="javascript:SelectWin('field', 'formUpdate.fieldName', 'formUpdate.tableName');">显示的字段</a></td>
    <td><input type="text" name="fieldName" value="<%=tableInfo.getFieldName()%>"  class="txtClass1">
    </td>      
  </tr>  
  <tr>
    <td>关联条件</td>
    <td colspan="3"> 
       <input type="text" name="tableCond" value="<%=tableInfo.getGLTJ()%>"  class="txtClass2">
    </td>
  </tr>   
  <tr>
    <td><a href="#" onClick="javascript:SelectWin('field', 'formUpdate.RelateField', 'formUpdate.tableName');">关联的字段</a></td>
    <td><input type="text" name="RelateField" value="<%=tableInfo.getRelateField() %>"  class="txtClass1">
    </td>
    <td><a href="#" onClick="javascript:SelectWin('field','formUpdate.RelateObject', 'formUpdate.tableName');">被关联的字段</a></td>
    <td><input type="text" name="RelateObject" value="<%=tableInfo.getRelateObject()%>"  class="txtClass1">
    </td>    
  </tr>         

  <tr>
    <td colspan="4" class="trClassTitle">==列表选择的分类信息设置==</td>
  </tr>  
  <tr>
    <td width="80">分类表名</td>
    <td width="180">
     <input type="text" name="cateTable" value="<%=tableInfo.getGLGLBM()%>"  class="txtClass1">
    </td>
    <td width="80">      
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateUser', 'formUpdate.cateTable');">员工ID字段</a>
    </td>
    <td width="180">       
      <input type="text" name="cateUser" value="<%=tableInfo.getGLDLID()%>"  class="txtClass1"> 
    </td>    
  </tr> 
  <tr>      
    <td width="80">
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateID', 'formUpdate.cateTable');">ID字段</a>
    </td>
    <td width="180">      
      <input type="text" name="cateID" value="<%=tableInfo.getGLGLID()%>"  class="txtClass1"> 
    </td>
  
    <td>     
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateName', 'formUpdate.cateTable');">名称字段</a>
    </td>
    <td>       
      <input type="text" name="cateName" value="<%=tableInfo.getGLGLMC()%>"  class="txtClass1"> 
    </td>
  </tr> 
  <tr>      
    <td>       
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateRelate', 'formUpdate.tableName');">关联字段</a>
    </td>
    <td>       
      <input type="text" name="cateRelate" value="<%=tableInfo.getFieldType()%>"  class="txtClass1"> 
    </td>   
    <td>     
      查询条件
    </td>
    <td>       
      <input type="text" name="cateCond" value="<%=tableInfo.getGLGLTJ()%>"  class="txtClass1"> 
    </td>
  </tr>   
  <tr>
    <td colspan="4" align="center"  class="trClassTitle">          
<!--      <input type="button" value="测试" class="btnClass" OnClick="Test();"> -->  
              
      <input type="button" value="确定" class="btnClass" OnClick="Save();">
      <input type="button" value="关闭" class="btnClass" OnClick="window.close();">
    </td>  
  </tr>    
</table>

</form>
<script language="javascript" src="../../../share/js/commonTool.js"></script>
<script language="javascript" src="../../../share/js/selectTool.js"></script>

<script language="javascript">
  function Add() {   
    var vField = formUpdate.txtField.value;
    var vObject = formUpdate.txtObject.value;
    
    if (!notSpace(formUpdate.txtField, "字段")) {
      return false;
    }
    if (!notSpace(formUpdate.txtObject, "控件")) {
      return false;
    }   
    var vLen = 0;
    vLen = formUpdate.fieldName.length;
    formUpdate.fieldName.options[vLen] = new Option(vField, vField); 
       
    vLen = formUpdate.objectName.length;
    formUpdate.objectName.options[vLen] = new Option(vObject, vObject);      
    formUpdate.txtField.value = "";
    formUpdate.txtObject.value = "";           
  }
  function DeleteItem() {
    var vIndex = formUpdate.fieldName.selectedIndex;
    if (vIndex >=0 ) {
    	formUpdate.fieldName.options[vIndex] = null;
    	formUpdate.objectName.options[vIndex] = null;    	
    }
  }  
  function ChangeField() {
  	/*
    var vIndex = formUpdate.fieldName.selectedIndex;
    if (vIndex >=0 ) {
       //formUpdate.objectName.selectedIndex = -1;
       formUpdate.objectName.options[vIndex].selected = true; 
    } 
    */
  }
  
  function ChangeObject() {
  	/*
    var vIndex = formUpdate.objectName.selectedIndex;
    if (vIndex >=0 ) {
       //formUpdate.fieldName.selectedIndex = -1;
       formUpdate.fieldName.options[vIndex].selected = true; 
    }   
    */
  }  
  
  function Test() {   
  }
  
  //删除
  function Delete() {
    var relate = formUpdate.relate.value;
    if (relate == "") {
		alert("请选择要删除的关联信息");
		return false;
    }
    if (confirm("确定要删除？")) {
    	formUpdate.OPERATOR.value = "delete";
    	formUpdate.action = "formSelectOk3.jsp";
    	formUpdate.submit();  
    }
  }
  
  //提交到控制保存的页面
  function Save() {
    //关联名称不能为空
    if (!notSpace(formUpdate.relateName, "关联名称")) {
      return false;
    }  
    //名称只能为字母数字下划线
    if (!isLetterOrNumOrLine(formUpdate.relateName.value)) {
      alert("关联名称只能是字母数字下划线");
      formUpdate.relateName.focus();
      return false;
    }    
    
    if (!notSpace(formUpdate.tableName, "关联主表")) {
      return false;
    } 
    //tableCond

    if (isSpace(formUpdate.cateTable.value) == false) {
    	if (!notSpace(formUpdate.cateID, "分类ID字段")) {
      		return false;
    	}    
    	if (!notSpace(formUpdate.cateName, "分类名称字段")) {
      		return false;
    	}   
    	if (!notSpace(formUpdate.cateRelate, "分类关联字段")) {
      		return false;
    	}    			
    }   
    
    formUpdate.action = "formSelectOk3.jsp";
    formUpdate.submit();
  }
  
  //选择已经存在的，显示出来。
  function SelectRelate() { 
    formUpdate.action = "formSelect3.jsp";
    formUpdate.submit();  
  }
  
  function SelectWin(vType,  vObject, vTableObject) {
    var moduleName1 = formUpdate.moduleName1.value;
    var formName1 = formUpdate.formName1.value;
    var moduleName2 = formUpdate.moduleName2.value;
    var formName2 = formUpdate.formName2.value;    
    var url = "../field_select.jsp?type=" + vType + "&object=" + vObject + "&tableobject=" + vTableObject
            + "&moduleName1=" + moduleName1 + "&formName1=" + formName1
            + "&moduleName2=" + moduleName2 + "&formName2=" + formName2;
    window.showModalDialog(url,window,"status=no;dialogWidth=300px;dialogHeight=370px");  
  }
  
  function Down() {
    var vIndex = 0;
    var vLen   = 0;
    var vText  = "";
    var vValue = "";
    var oObject = null;
    oObject = formUpdate.fieldName;
    vIndex = oObject.selectedIndex;
    vLen   =  oObject.length;
    if (vIndex< vLen -1) {
		vText = oObject.options[vIndex + 1].text;
    	vValue = oObject.options[vIndex  + 1].value;  
    	
    	oObject.options[vIndex + 1].text 
    	=  oObject.options[vIndex].text;
    	oObject.options[vIndex + 1].value 
    	=  oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  vText;
    	oObject.options[vIndex].value 
    	=  vValue;  	
    	
    	//oObject.options[vIndex +1].selected = true;    
    	oObject = formUpdate.objectName;
		vText = oObject.options[vIndex + 1].text;
    	vValue = oObject.options[vIndex  + 1].value;  
    	
    	oObject.options[vIndex + 1].text 
    	=  oObject.options[vIndex].text;
    	oObject.options[vIndex + 1].value 
    	=  oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  vText;
    	oObject.options[vIndex].value 
    	=  vValue;    		 
    }  
  }
  
  function Up() {
    var vIndex = 0;
    var vLen   = 0;
    var vText  = "";
    var vValue = "";
    var oObject = null;
    oObject = formUpdate.fieldName;
    vIndex = oObject.selectedIndex;
    vLen   =  oObject.length;
      
    if (vIndex>0) {
		vText = oObject.options[vIndex].text;
    	vValue = oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  oObject.options[vIndex -1].text;
    	oObject.options[vIndex].value 
    	=  oObject.options[vIndex -1].value;  
    	
    	oObject.options[vIndex -1].text 
    	=  vText;
    	oObject.options[vIndex -1].value 
    	=  vValue;  	
    	
    	//oObject.options[vIndex -1].selected = true;
    	oObject = formUpdate.objectName;    	
		vText = oObject.options[vIndex].text;
    	vValue = oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  oObject.options[vIndex -1].text;
    	oObject.options[vIndex].value 
    	=  oObject.options[vIndex -1].value;  
    	
    	oObject.options[vIndex -1].text 
    	=  vText;
    	oObject.options[vIndex -1].value 
    	=  vValue;      	    	 
    }   
  }  
</script>

</body>
</html>
<!-- 
<iframe name="submitName" style='display:none;'></iframe>
 -->