<%@ page contentType="text/html;charset=gbk" %>
<%@ 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"));
    
    BdOpenSelect bdOpenSelect = new BdOpenSelect();
		BdOpenSelectInfo info = null;
		info = bdOpenSelect.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="formSave.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() %>"  class="txtClass300">
      <font color="red">*</font>
  
      <%
      	String s_id2[] = {"0","1"};
        String s_name2[] = {"单项选择","多项选择"};
        out.println(SzPageHelp.radio("relateType", s_id2, s_name2, info.getGLLX()));
      %> 
    </td>
  </tr>
  <tr>
    <td>关联说明</td>
    <td> 
       <input type="text" name="relateDesc" value="<%=info.getGLBZ()%>"  class="txtClass1">
    </td>
    <td>所属模块</td>
    <td> 
       <input type="text" name="moduleName" value="<%=info.getModuleName()%>" class="txtClass1R" readonly>
    </td>         
  </tr>   
  <tr>
    <td colspan="4" class="trClassTitle2">==弹出选择的主表信息设置==</td>
  </tr>    
  <tr>
    <td>关联主表</td>
    <td>     
       <input type="text" name="tableName" value="<%=info.getGLBM()%>"  class="txtClass1">
       <font color="red">*</font>
    </td>
    <td><a href="#" onClick="javascript:SelectWin('field', 'formUpdate.tableUser', 'formUpdate.tableName');">员工ID字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a></td>
    <td>     
       <input type="text" name="tableUser" value="<%=info.getFieldID()%>" class="txtClass1">
    </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><input type="text" name="RelateField" value="<%=info.getRelateField() %>"  class="txtClass1">
    </td>
    <td nowrap><a href="#" onClick="javascript:SelectWin('object','formUpdate.RelateObject', 'formUpdate.tableName');">条件控件<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a></td>
    <td><input type="text" name="RelateObject" value="<%=info.getRelateObject()%>"  class="txtClass1R" readonly>
    </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">           
      <%
      	String s_id3[] = {"0","1","2"};
        String s_name3[] = {"列出所有","列出个人所有","列出个人所有，管理员列出全部"};
        out.println(SzPageHelp.radio("tablePopedom", s_id3, s_name3, info.getFieldPopedom()));
      %>          
    </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="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(info.getFieldName(), ";" )); %>  
      </select>
    </td>
    <td valign="top"><br>控件</td>
    <td>
      <select name="objectName" size="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(info.getFieldDesc(), ";" )); %>
      </select>
    </td>  
  </tr>
  <tr>
    <td colspan="4" class="trClassTitle2">==弹出选择的分类信息设置==</td>
  </tr>  
  <tr>
    <td>分类表名</td>
    <td>
     <input type="text" name="cateTable" value="<%=info.getGLGLBM()%>"  class="txtClass1">
    </td>
    <td>      
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateUser', 'formUpdate.cateTable');">员工ID字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
    </td>
    <td>       
      <input type="text" name="cateUser" value="<%=info.getGLDLID()%>"  class="txtClass1"> 
    </td>    
  </tr> 
  <tr>      
    <td>
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateID', 'formUpdate.cateTable');">ID字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
    </td>
    <td>      
      <input type="text" name="cateID" value="<%=info.getGLGLID()%>"  class="txtClass1"> 
    </td>
  
    <td>     
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateName', 'formUpdate.cateTable');">名称字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
    </td>
    <td>       
      <input type="text" name="cateName" value="<%=info.getGLGLMC()%>"  class="txtClass1"> 
    </td>
  </tr> 
  <tr>      
    <td>       
      <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.cateRelate', 'formUpdate.tableName');">关联字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
    </td>
    <td>       
      <input type="text" name="cateRelate" value="<%=info.getFieldType()%>"  class="txtClass1"> 
    </td>   
    <td>     
      查询条件
    </td>
    <td>       
      <input type="text" name="cateCond" value="<%=info.getGLGLTJ()%>"  class="txtClass1"> 
    </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 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 == -1) {
    	alert("请选择下面的其中一个字段");
    	return;
    }
    if (confirm("确定要删除选中的关联信息？")) {
    	formUpdate.fieldName.options[vIndex] = null;
    	formUpdate.objectName.options[vIndex] = null;    	
    } 
  }   
  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;      	    	 
    }   
  }  
  
  //提交到控制保存的页面
  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.moduleName, "所属模块")) {
      return false;
    }     
    //tableCond
    if (    (ValueOfRadio(formUpdate.tablePopedom) == "1" || ValueOfRadio(formUpdate.tablePopedom) == "2")
          && isSpace(formUpdate.tableUser.value) ) {
		alert("所选的权限员工ID字段必须填写");
		return false;
    }
        
    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;
    	}    			
    }   
    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 SelectRelate() { 
    formUpdate.action = "formSelect.jsp";
    formUpdate.submit();  
  }
  
  function SelectWin(vType,  vObject, vTableObject, vModuleNameObject) {
		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 + "&tableobject=" + vTableObject
            + "&moduleName1=" + moduleName1 + "&formName1=" + formName1
            + "&moduleName2=" + moduleName2 + "&formName2=" + formName2
            + "&moduleNameObject=" + vModuleNameObject; 
    window.showModalDialog(url,window,"status=no;dialogWidth=300px;dialogHeight=370px");  
  }
  

</script>

</body>
</html>
