<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="../sessionInfo2.jsp"%>
<%
    strLevel_SESSION = "../../../";
    strSkin_SESSION = "../../../images/skin2_blue2";
%>
<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"));    
    BdReadSelectXML2 readSelectXML = new BdReadSelectXML2();
    //获取已经设置的详细信息
    BdSelectTableInfo2 tableInfo = (BdSelectTableInfo2)readSelectXML.getTableInfoFromXML(sRelate);
    if (tableInfo == null) {
    	tableInfo = new BdSelectTableInfo2();
    }
    if (sOPERATOR.equals("")) {
    	sOPERATOR = "set";
    }
%>

<form name="formUpdate" method="post" action="formSave2.jsp">
<input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
<input type="hidden" name="ObjectType" value="<%=sObjectType%>">
<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">请选择关联信息：
    <%

      String s_name[] = readSelectXML.getTableName();
    %>
    <%=SzPageHelp.idSelectArrayFunc(s_name, s_name, "relate", sRelate, "txtClass1", "SelectRelate();")%>
    <input type="button" value="删除" class="btnClass" OnClick="Delete();"> 
    </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="txtClass2"></td>
  </tr>
  <tr>
    <td>关联表名</td>
    <td colspan="3">
       <input type="text" name="tableName" value="<%=tableInfo.getGLBM()%>"  class="txtClass2">
    </td>    
  </tr>   
  <tr>
    <td nowrap><a href="#" onClick="javascript:SelectWin('field', 'formUpdate.RelateField', 'formUpdate.tableName');">条件字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a></td>
    <td colspan="3"  nowrap><input type="text" name="RelateField" value="<%=tableInfo.getRelateField() %>"  class="txtClass1">
     <a href="#" onClick="javascript:SelectWin('object','formUpdate.RelateObject', 'formUpdate.tableName');">条件控件<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
       <input type="text" name="RelateObject" value="<%=tableInfo.getRelateObject()%>"  class="txtClass1">
    </td>    
  </tr>    
  <tr>
    <td>默认条件</td>
    <td colspan="3"> 
       <input type="text" name="tableCond" value="<%=tableInfo.getGLTJ()%>"  class="txtClass2">
    </td>
  </tr>  
  <tr>
    <td>关联字段</td>
    <td colspan="3">
       <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.txtField', 'formUpdate.tableName');">字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>        
      <input type="text" name="txtField" value="" class="txtClass1">
       <a href="#" onClick="javascript:SelectWin('object','formUpdate.txtObject', 'formUpdate.tableName');">控件<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
      <input type="text" name="txtObject" value="" class="txtClass100">
      <input type="button" value="添加"  class="btnClassShort" OnClick="Add();">
      <input type="button" value="删除" class="btnClassShort" OnClick="DeleteItem();">      
    </td>  
  </tr>       
  <tr>
    <td valign="top"><br>字段<br>
      <input type="button" value="上移" class="btnClassShort" OnClick="Up();"><br>
      <input type="button" value="下移" class="btnClassShort" OnClick="Down();">    
    </td>
    <td>
      <select name="fieldName" size="10" multiple style="width:180;" OnChange="ChangeField();">
      <% out.println(SzPageHelp.selectOption(tableInfo.getFieldName(), ";" )); %>  
      </select>
    </td>
    <td valign="top"><br>控件</td>
    <td>
      <select name="objectName" size="10" multiple style="width:180;" OnChange="ChangeObject();">
      <% out.println(SzPageHelp.selectOption(tableInfo.getFieldDesc(), ";" )); %>
      </select>
    </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() {
    formUpdate.OPERATOR.value = "delete";
    formUpdate.action = "formSelectOk2.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;
    } 
    if (!notSpace(formUpdate.RelateField, "条件字段")) {
      return false;
    } 
    if (!notSpace(formUpdate.RelateObject, "条件控件")) {
      return false;
    }         
    
    SelectAllOption(formUpdate.fieldName);
    SelectAllOption(formUpdate.objectName);
    
    formUpdate.action = "formSelectOk2.jsp";
    formUpdate.submit();
  }
  
  //选择已经存在的，显示出来。
  function SelectRelate() { 
    formUpdate.action = "formSelect2.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>
 -->
