<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="/xml/formEngine2/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"));
    
    BdTrigger bdTrigger = new BdTrigger();
		BdTriggerInfo info = null;
		info = bdTrigger.getInfo(sRelate);

		if (sOPERATOR.equals("add")) {
			info.setGLTJ("1=1");
		} else if (sOPERATOR.equals("update")) {
		}
    if (sOPERATOR.equals("")) {
    	sOPERATOR = "set";
    }
    String sFormType = (String)session.getAttribute("SzFormType");
%>

<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="">
<%@ include file="/xml/formEngine2/title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <%=SzPageHelp.saveButton()%>
      <%=SzPageHelp.backButton()%>
    </td>
  </tr>
</table>
<table width="600" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
         
  <tr>
    <td colspan="4" class="trClassTitle2">==关联的主信息设置==</td>
  </tr>         
  <tr>
    <td>关联名称</td>
    <td colspan="3"><input type="text" name="relateName" value="<%=info.getGLSM() %>" <%if (sOPERATOR.equals("update")){%> readonly class="txtClass1R"<%}else {%>class="txtClass1"<%} %>>（字母、下划线、数字） <font color="red">*</font></td>
  </tr>
  <tr>
    <td>触发类型</td>
    <td>     
      <%
      	String s_id2[] = {"0","1"};
        String s_name2[] = {"手动获取","添加时自动获取"};
        out.println(SzPageHelp.radio("relateType", s_id2, s_name2, info.getGLLX()));
      %> 
    </td>
    <td>所属模块</td>
    <td>     
      <input type="text" name="moduleName" value="<%=info.getModuleName()%>" class="txtClass1R" readonly>
    </td>    
  </tr>    
  <tr>
    <td>关联说明</td>
    <td colspan="3"> 
       <input type="text" name="relateDesc" value="<%=info.getGLBZ()%>"  class="txtClass2">
    </td>
  </tr>    
  <tr>
    <td>关联表名</td>
    <td colspan="3">
       <input type="text" name="tableName" value="<%=info.getGLBM()%>"  class="txtClass2"> <font color="red">*</font>
    </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 nowrap><input type="text" name="RelateField" value="<%=info.getRelateField() %>"  class="txtClass1"> <font color="red">*</font>
    <td><a href="#" onClick="javascript:SelectWin('object','formUpdate.RelateObject', 'formUpdate.tableName', 'formUpdate.moduleName');">条件控件<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a></td>
	  <td>    
       <input type="text" name="RelateObject" value="<%=info.getRelateObject()%>"  class="txtClass1R" readonly> <font color="red">*</font>
    </td>    
  </tr>    
  <tr>
    <td>默认条件</td>
    <td colspan="3"> 
       <input type="text" name="tableCond" value="<%=info.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', 'formUpdate.moduleName');">控件<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
      <input type="text" name="txtObject" value="" class="txtClass1R" readonly>
      <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();"><br>
      (最多18个) 
    </td>
    <td>
      <select name="fieldName" size="18" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(info.getFieldName(), ";" )); %>  
      </select>
    </td>
    <td valign="top"><br>控件</td>
    <td>
      <select name="objectName" size="18" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(info.getFieldDesc(), ";" )); %>
      </select>
    </td>  
  </tr>
  <tr>
    <td colspan="4" align="center"  class="trClassTitle">          
    </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 vLen = 0;
    vLen = formUpdate.fieldName.length;
    if (vLen >=18) {
    	alert("最多关联18个字段");
    	return;
    }  
    var vField = formUpdate.txtField.value;
    var vObject = formUpdate.txtObject.value;
    
    if (!notSpace(formUpdate.txtField, "字段")) {
      return false;
    }
    if (!notSpace(formUpdate.txtObject, "控件")) {
      return false;
    }   
    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 == -1) {
    	alert("请选择下面的其中一个字段");
    	return;
    }
    if (confirm("确定要删除选中的关联信息？")) {
    	formUpdate.fieldName.options[vIndex] = null;
    	formUpdate.objectName.options[vIndex] = null;    	
    } 
  }  

  
  //提交到控制保存的页面
  function FormSave(formName, url) {     
    //关联名称不能为空
    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;
    }   
    if (!notSpace(formUpdate.moduleName, "所属模块")) {
      return false;
    }
    if (formUpdate.txtField.value != "" || formUpdate.txtObject.value != "") {
    	//提醒还有没添加的关联信息
    	if (confirm("还有没添加的关联信息,是否返回添加")) {
    		return false;
    	}
    }
    if (formUpdate.fieldName.length == 0) {
    	alert("关联信息的字段和控件不能为空");
    	return false;
    }
    SelectAllOption(formUpdate.fieldName);
    SelectAllOption(formUpdate.objectName);
    
    formUpdate.action = "control.jsp";
    formUpdate.submit();
  }
  
  
  function SelectWin(vType,  vObject, vTableObject, vModuleNameObject, vObject2) {
		var moduleName = formUpdate.moduleName.value;
    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 
    				+ "&object2=" + vObject2 + "&tableobject=" + vTableObject
            + "&moduleName1=" + moduleName1 + "&formName1=" + formName1
            + "&moduleName2=" + moduleName2 + "&formName2=" + formName2
            + "&moduleNameObject=" + vModuleNameObject; 
    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>
