<%@ 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.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="/xml/formEngine2/sessionInfo2.jsp"%>
<head>
<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>
<%
    //获取提交的参数
    String name = SzConvert.toSpaceStr(request.getParameter("name"));
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
	  String moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
	  String formName = SzConvert.toSpaceStr(request.getParameter("formName"));
	  BdUpdateBack bdUpdateBack = new BdUpdateBack();
    String str[] = bdUpdateBack.getInfo(name);
    
		if (sOPERATOR.equals("add")) {
			str[1] = moduleName;
			str[2] = formName;
			str[4] = "0";
			str[13] = "0";
		} else if (sOPERATOR.equals("update")) {
			moduleName = str[1];
			formName = str[2];
		}
   	
    BdFormControl bdFormControl = new BdFormControl();    
    Map fieldMap = bdFormControl.getFieldMap();
    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
    Iterator iterFormField = null;  		
   	String temp = "";
   	int i =0;
%>
<body>

<!-----上面的工具栏------>
<form name="formUpdate" method="post">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
<input type="hidden" name="moduleName1" value="<%=moduleName%>">
<input type="hidden" name="formName1" value="<%=formName%>">
<input type="hidden" name="moduleName2" value="<%=moduleName%>">
<input type="hidden" name="formName2" value="<%=formName%>">  
<%@ include file="/xml/formEngine2/title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <%=SzPageHelp.saveButton()%>
      <%=SzPageHelp.backButton()%>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">名称</td>
    <td colspan="3"><input type="text" name="name" value="<%=str[0]%>" size="10" <%if (sOPERATOR.equals("update")){%> readonly class="txtClass1R"<%}else {%>class="txtClass1"<%} %>><font color="red">*</font>(可用字母、数字、下划线的组合，10个字以内) </td>
  </tr>
  <tr>
    <td class="tdClassTitle">模块名称</td>
    <td><input type="text" name="moduleName" class="txtClass1R" value="<%=str[1]%>"  readonly></td>
    <td  align="right">表单名称</td>
    <td><input type="text" name="formName" class="txtClass1R" value="<%=str[2]%>"  readonly></td>
  </tr>
  <tr>
    <td class="tdClassTitle">说明</td>
    <td colspan="3"><input type="text" name="desc" class="txtClass2" value="<%=str[3]%>"></td>
  </tr>  
  <tr>
    <td class="tdClassTitle">执行类型</td>
    <td colspan="3">
      <%
        //2014-12增加否决
      	String s_id2[] = {"0","1","2","3","4"};
        String s_name2[] = {"保存时","审批通过时","办结时","删除时","否决时"};
        out.println(SzPageHelp.radio("operatorType", s_id2, s_name2, str[4]));
      %> 
    </td>
  </tr>  
  <tr>
    <td class="tdClassTitle">执行条件</td>
    <td colspan="3"><input type="text" name="cond" class="txtClass2" value="<%=str[5]%>"></td>
  </tr>    
  <tr>
    <td class="tdClassTitle">执行固定部分</td>
    <td colspan="3"><input type="text" name="fixValue" class="txtClass2" value="<%=str[6]%>"></td>
  </tr>   
  <tr>
    <td class="tdClassTitle">回写的表</td>
    <td><input type="text" name="tableName2" class="txtClass1" value="<%=str[11]%>"><font color="red">*</font></td>
    <td align="right">读值的表</td>
    <td><input type="text" name="tableName" class="txtClass1R" value="<%=str[9]%>" readonly><font color="red">*</font></td>
  </tr> 
  <tr>
    <td class="tdClassTitle"><a href="#" onClick="javascript:SelectWin('field', 'formUpdate.condField', 'formUpdate.tableName2');">回写条件字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></td>
    <td><input type="text" name="condField" class="txtClass1" value="<%=str[7]%>"><font color="red">*</font></td>
    <td align="right"><a href="#" onClick="javascript:SelectWin('field','formUpdate.valueField', 'formUpdate.tableName', 'formUpdate.moduleName', 'formUpdate.formName');">读值条件字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></td>
    <td><input type="text" name="valueField" class="txtClass1R" value="<%=str[8]%>" readonly><font color="red">*</font></td>
  </tr>       
  <tr>
    <td class="tdClassTitle">关联信息</td>
    <td colspan="3">
       <a href="#" onClick="javascript:SelectWin('field', 'formUpdate.txtField2', 'formUpdate.tableName2');">回写的字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>        
      <input type="text" name="txtField2" value="" class="txtClass1">
       <a href="#" onClick="javascript:SelectWin('field','formUpdate.txtField', 'formUpdate.tableName' , 'formUpdate.moduleName', 'formUpdate.formName');">读值的字段<img src="<%=strLevel_SESSION%>images/share2/select.gif" border="0" ></a>
      <input type="text" name="txtField" 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" align="right"><br>回写的字段<br>
      <input type="button" value="上移" class="btnClassShort" OnClick="Up();"><br>
      <input type="button" value="下移" class="btnClassShort" OnClick="Down();"> <br>   
    </td>
    <td><input type="hidden" name="field2" value="<%=str[12]%>">
      <select name="field2select" size="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(str[12], "," )); %>  
      </select>
    </td>
    <td valign="top" align="right"><br>读值的字段</td>
    <td><input type="hidden" name="field" value="<%=str[10]%>">
      <select name="fieldselect" size="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(str[10], "," )); %>
      </select>
    </td>  
  </tr>  
  <tr>
    <td class="tdClassTitle">读值类型</td>
    <td colspan="3">
      <%
      	String s_id3[] = {"0","1"};
        String s_name3[] = {"当前记录的值","跟‘读值条件字段’相同的记录，取sum(读值的字段)"};
        out.println(SzPageHelp.radio("valueType", s_id3, s_name3, str[13]));
      %> 
    </td>
  </tr>    
  <tr>
    <td class="tdClassTitle">读值条件</td>
    <td colspan="3"><input type="text" name="valueCond" class="txtClass2" value="<%=str[14]%>"></td>
  </tr>    
  <tr>
  	<td class="tdClassTitle">回写</td>
  	<td colspan="3">update 回写的表 <br>set 执行固定部分,回写的字段 = 读值的字段 <br>where 回写条件字段 = 读值条件字段 AND 执行条件 </td>
  </tr>
  <tr>
  	<td class="tdClassTitle">删除</td>
  	<td colspan="3">delete 回写的表 <br>where 回写条件字段 = 读值条件字段 AND 执行条件 </td>
  </tr>  
</table>

</form>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" src="../../../share/js/commonTool.js"></script>
<script language="javascript" src="../../../share/js/selectTool.js"></script>
<script language="javascript">

  function FormSave(formName, url) {
    if (!notSpace(formName.name, "名称")) {
      return false;
    }  
    if (!notSpace(formName.tableName2, "回写的表")) {
      return false;
    }          
    if (!notSpace(formName.tableName, "读值的表")) {
      return false;
    }
    if (!notSpace(formName.condField, "回写条件字段")) {
      return false;
    } 
    if (!notSpace(formName.valueField, "读值条件字段")) {
      return false;
    }     
    if (formName.txtField.value != "" || formName.txtField2.value != "") {
    	//提醒还有没添加的关联信息
    	if (confirm("还有没添加的关联信息,是否返回添加")) {
    		return false;
    	}
    }
    var operatorType = ValueOfRadio(formName.operatorType);
    if (operatorType != "3" &&  formName.field.length == 0) {
    	alert("关联信息的回写的字段和读值的字段不能为空");
    	return false;
    }       
    if (!notSpace(formName.moduleName, "所属模块")) {
      return false;
    }     
    if (!notSpace(formName.formName, "所属表单")) {
      return false;
    }     
    //SelectAllOption(formName.field);
    //SelectAllOption(formName.field2);   
    formName.field.value = ValueOfSelect(formName.fieldselect,",");
    formName.field2.value = ValueOfSelect(formName.field2select,","); 
    
    formName.action = "control.jsp";
    formName.submit();
  }
 
   function SelectWin(vType,  vObject, vTableObject, vModuleNameObject, vFormNameObject) {

    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 + "&formNameObject=" + vFormNameObject;
    window.showModalDialog(url,window,"status=no;dialogWidth=300px;dialogHeight=370px");  
  } 
  function Add() {   
    var vField = formUpdate.txtField.value;
    var vObject = formUpdate.txtField2.value;
    
    if (!notSpace(formUpdate.txtField, "读值的字段")) {
      return false;
    }
    if (!notSpace(formUpdate.txtField2, "回写的字段")) {
      return false;
    }   
    var vLen = 0;
    vLen = formUpdate.fieldselect.length;
    formUpdate.fieldselect.options[vLen] = new Option(vField, vField); 
       
    vLen = formUpdate.field2select.length;
    formUpdate.field2select.options[vLen] = new Option(vObject, vObject);      
    formUpdate.txtField.value = "";
    formUpdate.txtField2.value = "";           
  }
  function DeleteItem() {  
    var vIndex = formUpdate.fieldselect.selectedIndex;
    if (vIndex == -1) {
    	alert("请选择下面的其中一个字段");
    	return;
    }
    if (confirm("确定要删除选中的关联信息？")) {
    	formUpdate.fieldselect.options[vIndex] = null;
    	formUpdate.field2select.options[vIndex] = null;    	
    } 
  }   
  function Down() {
    var vIndex = 0;
    var vLen   = 0;
    var vText  = "";
    var vValue = "";
    var oObject = null;
    oObject = formUpdate.field2select;
    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.field2select;
		  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>
