<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.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>
<%@ include file="title.jsp"%>
<%
    String moduleName = "";
    String formName = "";
    String sFlowID = SzConvert.toZeroStr(request.getParameter("FlowID"));     //流程ID
    String sStepID = SzConvert.toZeroStr(request.getParameter("StepID"));     //步骤ID 
    String sFormID = SzConvert.toZeroStr(request.getParameter("FormID"));  //表单ID 
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));		//前一节点的顺序    
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));    
    String TJID = SzConvert.toZeroStr(request.getParameter("TJID"));
    String SXID = SzConvert.toZeroStr(request.getParameter("SXID"));
    //根据表单取得moduleName, formName
    LcForm lcForm = new LcForm();
    LcFormInfo lcFormInfo = null;
    lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(Integer.parseInt(sFormID));
    if (lcFormInfo != null) {
    	moduleName = lcFormInfo.getBDLJ();
    	formName = lcFormInfo.getBDBY1();
    }
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    //取得流程名称
    LcFlow lcFlow = new LcFlow();
    String sFlowName = lcFlow.getMainByKey(Integer.parseInt(sFlowID));
    
    //读取条件信息    
    LcCond lcCond = new LcCond();
    LcCondInfo lcCondInfo = null;
	lcCondInfo = (LcCondInfo)lcCond.getInfoByKey(SzConvert.toInt(TJID));
	if (lcCondInfo == null) {
		lcCondInfo = new LcCondInfo();
	}
	
    LcCondDetail lcCondDetail = new LcCondDetail();
    LcCondDetailInfo lcCondDetailInfo = null;	
    //获取已经设置的判断
    Iterator iterCondDetail = lcCondDetail.getArrayList("SXTJ=" + TJID).iterator();

%>

<!-----信息列表----->
<%
	BdFormControl bdFormControl = new BdFormControl();
    bdFormControl.getMapStatic(moduleName, formName);
    Map formMap  = bdFormControl.getFormMap();
    Map tableMap = bdFormControl.getTableMap();
    Map fieldMap = bdFormControl.getFieldMap();
    
	BdFormInfo bdFormInfo = null;
	bdFormInfo = (BdFormInfo)formMap.get(new String(moduleName + "-" + formName));  
    if (bdFormInfo == null) {
      bdFormInfo = new BdFormInfo();
    }
    
	BdFormTableInfo bdFormTableInfo = null;
	Collection collFormTable = null;
	collFormTable = (Collection)tableMap.get(new String(moduleName + "-" + formName));
	Iterator iterFormTable = null;

	//字段信息
	BdFormFieldInfo bdFormFieldInfo = null;
	Collection collFormField = null;
	collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
	Iterator iterFormField = null;    

    if (collFormTable != null) {
      iterFormTable = collFormTable.iterator();
    }

    if (collFormField != null) {
      iterFormField = collFormField.iterator();
    }
%>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formUpdate" method="post">
  <input type="hidden" name="moduleName" value="<%=moduleName%>">
  <input type="hidden" name="formName" value="<%=formName%>">
  <input type="hidden" name="FormID" value="<%=sFormID%>"> 
  <input type="hidden" name="FlowID" value="<%=sFlowID%>">
  <input type="hidden" name="StepID" value="<%=sStepID%>">
  <input type="hidden" name="TJID" value="<%=TJID%>">
  <input type="hidden" name="SXID" value="<%=SXID%>">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">   
  <tr class="trClassTitle" >
    <td colspan="4">
    <b>表单名称：</b><%=bdFormInfo.getFormName() %>&nbsp;
	<b>流程名称：</b><%=sFlowName %>&nbsp;
    </td>
  </tr>    
  <tr>
    <td colspan="4">条件名称: <input type="text" name="TJMC" class="txtClass" value="<%=lcCondInfo.getTJMC()%>"> 
    <a href="javascript:FormSubmit(formUpdate,'cond_update.jsp?OPERATOR=add&SXID=0');">新增判断</a>
    </td>
  </tr>
</table>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle" >
    <td>判断说明</td>
    <td>与还是或</td>
    <td>优先顺序</td>
    <td>操作</td>
  </tr>
<%
  while (iterCondDetail != null && iterCondDetail.hasNext()) {
	  lcCondDetailInfo = (LcCondDetailInfo)iterCondDetail.next();
	  if (lcCondDetailInfo == null) {
		  continue;
	  }
%>
  <tr>
    <td><%=lcCondDetailInfo.getSXBZ() %></td>
    <td><%=lcCondDetailInfo.getSXYH() %></td>
    <td><%=lcCondDetailInfo.getSXSX() %></td>
    <td>
      <a href="javascript:FormSubmit(formUpdate,'cond_update.jsp?OPERATOR=update&TJID=<%=TJID%>&SXID=<%=lcCondDetailInfo.getSXID()%>');">明细</a>
      <a href="javascript:FormSubmit(formUpdate,'cond_control.jsp?OPERATOR=delete&TJID=<%=TJID%>&SXID=<%=lcCondDetailInfo.getSXID()%>');">删除</a>
    </td>
  </tr>
<%	  
  }
%>  
</table>
<%
  //获取本次要显示的判断
  //LcCondDetail lcCondDetail = new LcCondDetail();
  //LcCondDetailInfo lcCondDetailInfo = null;	
  //获取已经设置的判断
  //Iterator iterCondDetail = lcCondDetail.getArrayList("SXTJ=" + TJID).iterator();
  lcCondDetailInfo = (LcCondDetailInfo)lcCondDetail.getInfoByKey(SzConvert.toInt(SXID));
  if (lcCondDetailInfo == null) {
	  lcCondDetailInfo = new LcCondDetailInfo();
  }
  //把已经设置的取到map里
  LcCondField lcCondField = new LcCondField();
  LcCondFieldInfo lcCondFieldInfo = null;
  
  Map condFieldMap = lcCondField.getHashMap("MXSX>0 AND MXSX=" + SXID);
  String SXCG_2 = "";
  if (lcCondDetailInfo.getSXCG() > 0) {
	  SXCG_2 = "" + lcCondDetailInfo.getSXCG();
  }
  String SXSB_2 = "";
  if (lcCondDetailInfo.getSXSB() > 0) {
	  SXSB_2 = "" + lcCondDetailInfo.getSXSB();
  }
%>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">

  <tr class="trClassTitle">
    <td colspan="4">设置判断条件及转向</td>
  </tr>  
  <tr>
    <input type="hidden" name="SXID" class="txtClass" value="<%=lcCondDetailInfo.getSXID() %>">
    <td colspan="4">判断条件名称:<input type="text" name="SXBZ" class="txtClass" value="<%=lcCondDetailInfo.getSXBZ() %>">&nbsp;

    优先顺序:<input type="text" name="SXSX" class="txtClass"  value="<%=lcCondDetailInfo.getSXSX() %>"><BR>
    当条件成立时:
    <input type="radio" name="SXCG" value="0"  <% if (lcCondDetailInfo.getSXCG() == 0) { %> checked <% } %> >办结
    <input type="radio" name="SXCG" value="-1" <% if (lcCondDetailInfo.getSXCG() == -1) { %> checked <% } %> >否决
    <input type="radio" name="SXCG" value="-2" <% if (lcCondDetailInfo.getSXCG() > 0) { %> checked <% } %> >转到指定步骤
    <input type="hidden" name="SXCG_1" class="txtClass">
    <input type="text" name="SXCG_2" class="txtClass" value="<%=SXCG_2%>">
    <INPUT class=btnClassShort onclick="javascript:stepWin('<%=sFlowID%>', 'SXCG');" type=button value=选择 name=btnSelect>
    <br>

    <input type="radio" name="SXYH" value="1"   <% if (lcCondDetailInfo.getSXYH() == 1) { %> checked <% } %>>下列条件同时成立
    <input type="radio" name="SXYH" value="0"   <% if (lcCondDetailInfo.getSXYH() == 0) { %> checked <% } %>>下列条件一个成立<BR>        
    </td>    
  </tr>  
  <tr>
    <td><b>字段名称</b></td>
    <td><b>字段说明</b></td>
    <td><b>运算符号</b></td>
    <td><b>运算值</b></td>        
  </tr>   
<%
    int j = 0;
    int i = 0;
    String tableName = "";
    String tableId = "";
    String objectStr = "";
    String tableType = "";
    LcFieldPopedom lcFieldPopedom = new LcFieldPopedom();
    String strPopedom = lcFieldPopedom.getPopedomStr(Integer.parseInt(sFormID), Integer.parseInt(sFlowID), Integer.parseInt(sStepID) );
       

    String sCheck = "";
    while (iterFormTable != null && iterFormTable.hasNext()) {
        bdFormTableInfo = (BdFormTableInfo)iterFormTable.next();
        if (bdFormTableInfo.getGLBM().equals("")) {
            continue;
        }
        if (bdFormTableInfo.getGLLX().equals("1")) {
            continue;
        }        
        tableName = bdFormTableInfo.getGLBM();
        tableId = bdFormTableInfo.getGLID();
        //读取字段
        i=0;
        
        //本表已经设置的
        sCheck = "";
        iterFormField = collFormField.iterator();
        while ((iterFormField != null && iterFormField.hasNext())) {
            bdFormFieldInfo = null;
            if (iterFormField != null && iterFormField.hasNext()) {
                bdFormFieldInfo = (BdFormFieldInfo)iterFormField.next();
            }
            if (!tableId.equals(bdFormFieldInfo.getTableId())) {
                continue;
            }
            //字段是隐藏的，跳过
            //是否已经有设置的
            lcCondFieldInfo = (LcCondFieldInfo)condFieldMap.get(new String(bdFormFieldInfo.getZDMC()));
            if (lcCondFieldInfo == null) {
            	lcCondFieldInfo = new LcCondFieldInfo();
            }
%>
  <tr>
    <td align="left"><input type="hidden" name="MXZD<%=i%>" value="<%=bdFormFieldInfo.getZDMC()%>"><%=bdFormFieldInfo.getZDMC()%></td>
    <td align="left"><%=bdFormFieldInfo.getZDSM()%></td>
    <td align="left">
    &nbsp;<%=SzPageHelp.selectCondJava("MXYSF" + i, "" + lcCondFieldInfo.getMXYSF())%>
    </td>
    <td align="left"><input type="text" name="MXYSZ<%=i%>" value="<%=lcCondFieldInfo.getMXYSZ() %>"></td>
  </tr>
<%
            i ++;
        }
   }
%>
   <input type="hidden" name="fieldCount" value="<%=i%>" >
  <tr>
    <td align="center" colspan="4">
      <input type="button" value="保存" OnClick="javascript:FormSave(formUpdate, 'cond_control.jsp');">&nbsp;
      <input type="button" value="返回" onClick="document.location.href='index.jsp?type=<%=sFlowID%>'">
    </td>
  </tr>   
  </form>
</table>

<br>

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

  //这里指定跳转的步骤
  function stepWin(vFlowID, vType) {
    var vUrl = "step_win.jsp";
    vUrl += "?FlowID=" + vFlowID + "&type=" + vType;
    window.showModalDialog(vUrl,window,"status=no;dialogWidth=680px;dialogHeight=580px");  
  }  
  
  function FormSave(formName, url) {
  	//名称不能为空
    if (!notSpace(formName.TJMC, "条件名称")) {
      return false;
    }
    if (!notSpace(formName.SXBZ, "判断条件名称")) {
      return false;
    }  
    if (!notNum(formName.SXSX, "优先顺序")) {
      return false;
    }  
    if (CheckField() == false) {
      alert("请至少设置一个条件");
      return false;
    }  	
    formName.action = url;
    formName.submit();

  }

  //当改变一个字段的名字时，检查是否有重复的
  function CheckField() {
    var oObject = null;

    var objectCount = parseInt(formUpdate.fieldCount.value);
    var v = false;    
    for (var i=0; i<=objectCount; i++) {

      oObject = eval("formUpdate.MXYSF" + i);

      if (oObject != null && oObject.value != "0") {
        v = true;
        break;
      }
    }
    return v;
  }

</script>
