<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=strLevel_SESSION%>/share/js/operatorWin.js"></script>
<style type="text/css">
.div{
	position: absolute;
	z-index: 1;
	display:none;
	background-color: #cccccc;
	border: 0px;
	border-color: black;
	border-style: solid;
}
td{
	word-break : break-all; 
}
</style>
</head>
<%
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    //取得表单的信息
    String moduleName = "";
    String formName = "";
	//根据表单取得moduleName, formName
	LcForm lcForm = new LcForm();
	LcFormInfo lcFormInfo = null;    
    if (iFormID == 0) {
    	moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
    	formName = SzConvert.toSpaceStr(request.getParameter("formName")); 
    	//
    	iFormID = lcForm.getKeyByCond(moduleName, formName); 
    } else {
    	lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(iFormID);    
    	if (lcFormInfo != null) {
    		moduleName = lcFormInfo.getBDLJ();
    		formName = lcFormInfo.getBDBY1();  
    	}
    }
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    if (moduleName.equals("") || formName.equals("")) {
    	out.println("还没有设置相关表单信息！");
    	return;
    }
    
	BdValueControl bdValueControl = new BdValueControl(moduleName, formName);
	String assistant = bdValueControl.getAssistant(); 
    String sKeyField = bdValueControl.getKeyField();	
    boolean hasFlow = bdValueControl.getHasFlow();
	String printTemp = bdValueControl.getPrintTemp();
	String sWeboffice = bdValueControl.getWebOffice();
	int iFlowID = 0;    
%>	
<%@ include file="/share/title.jsp"%>
<%
    /////////////////////////////////////////流程相关
	LcFlowControl lcFlowControl = new LcFlowControl();
	//根据信息ID，获取流程总体办理状态FlowState
	String sState = "";
	//sState = lcFlowControl.getFlowStateName(iFormID, iInfoID); 
	//判断是否能删除、修改
	boolean hasSend = false; //是否已经发送出去
	
    //获取提交的参数
    String flowType = SzConvert.toSpaceStr(request.getParameter("flowType"));
	if (flowType.equals("")) {
		flowType = "-1";
	}
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName"));
    //String sSearchCond = SzConvert.strWriteData(request.getParameter("searchCond"));
    String sSearchCond = SzConvert.strWriteDataHTML(request.getParameter("searchCond"));
	//hasSend = lcFlowControl.hasSend(iFormID, iInfoID);
    //获取管理的信息ID
    String str_InfoID = lcFlowControl.getManageInfoID(iFormID, flowType);    

    String sTable_type = "";
    //读取数据
    LcTest lcTest = new LcTest();
    LcTestInfo lcTestInfo = null;
    String sCond = sKeyField + " IN (" + str_InfoID + ")";
    if (!sPKEY.equals("0")) {
        sCond += "";
    }
    
		if (!sSearchCond.equals("")) {
		//sSearchCond = sSearchCond.replaceAll("‘","'");
			sCond += " AND " + sSearchCond;
		}    
    
    String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
    int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder"))); 
    if (sSortField.equals("")) { 
        sSortField = sKeyField;
        iSortOrder = SzProperties.I_SortOrder_DESC;
    } 
    int iCurrentPage = 1;
    try {
        iCurrentPage =  Integer.parseInt(sPage);
    }catch(Exception e) {
    }

    sCond += " AND SZOA_BDGSID=" + szCOMPANY_SESSION;
    Collection coll = bdValueControl.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, sSearch); 
    Iterator iter = null;
    if (coll != null) {
    	iter = coll.iterator();
    } else {
    	out.println("读取不到数据");
    	return;
    }
    SzPageInfo pageInfo = bdValueControl.getPageInfo();
    int iPageCount = pageInfo.getPageCount();
    int iRecordCount = pageInfo.getRecordCount();
    iCurrentPage = pageInfo.getCurrentPage();
    int i = 0;
    SzData szData = null;      
    
    boolean bPress = false;
	if ((";" + assistant + ";").indexOf(";6;") >=0) {
		bPress = true;
	}    
	boolean bSkip = false;
	if ((";" + assistant + ";").indexOf(";7;") >=0) {
		bSkip = true;
	}     
	boolean bReceive = false;
	if ((";" + assistant + ";").indexOf(";12;") >=0) {
		bReceive = true;
	} 	
    BdFormControl bdFormControl = new BdFormControl(); 
%>
<!-----上面的工具栏------>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="FormID" value="<%=iFormID%>">   
  <tr>
    <td>
    <% out.println(bdFormControl.printFormDesc(Integer.parseInt(sMKID_SESSION),iFormID));%>
      <% if (isBarManager_SESSION) { %>    
      <input type="button" name="btnDel" class="btnClass" value="删除" OnClick="javascript:FormSubmitConfirm(formList, 'control.jsp?OPERATOR=deleteManage','确定要删除？');">
      <% } %>
      <%
      	String s_id[] = {"-1","0","1","2"};
      	String s_name[] = {"全部","办理中","否决","办结"};
      	out.println(SzPageHelp.radioSubmit("flowType", s_id, s_name, flowType));
      %>
      <%=SzPageHelp.button("综合查询","javascript:FormSubmit(formBar, 'search.jsp?From=2');") %>       
      <%=bdFormControl.statButton(moduleName, formName, isBarManager_SESSION, "图表统计", "stat.jsp?From=2&flowType=" + flowType, true) %>         
    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="flowType" value="<%=flowType%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="FormID" value="<%=iFormID%>">   
  <tr class="trClassTitle">
    <td width="5"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formList, chkCheckAll, 'chkId');"></td>
	<%=bdValueControl.printTableTitle(sSortField, iSortOrder)%>
	<%  
			if (flowType.equals("0")) {
				out.println("<td>当前办理人员</td>");
				out.println("<td>剩余时间</td>");
				if (bPress) {
				out.println("<td>被催办</td>");
				}
			} else if (flowType.equals("2")) {
				out.println("<td>办结时间</td>");
				out.println("<td>是否超时</td>");				
			}	
	%> 	
    <td>总状态</td>       
    <td>操作</td>
  </tr>
<%
    String value_str[] = null;
    int iKeyValue = 0;
    int iListFieldLen = bdValueControl.getListFieldLen();
		if (flowType.equals("0")) {
			iListFieldLen += 2;
			if (bPress) {
				iListFieldLen ++;
			}
	  } else if (flowType.equals("2")) {
    		iListFieldLen += 2;
    }     
    int iState = 0;
    //归档状态
    LcPigonhole pigonhole = new LcPigonhole();
    boolean hasPigonhole = false;
    String s_transact[] = null;
    String sPressCount = "";
    LcAssistant lcAssistant = new LcAssistant();    
    while (iter != null && iter.hasNext()) {    	
    	value_str = (String[])iter.next();
    	iKeyValue = Integer.parseInt(value_str[0]);
    	if (value_str == null) {
    		continue;
    	}
        i++;
        hasSend = lcFlowControl.hasSend(iFormID, iKeyValue);
        iState = lcFlowControl.getFlowState(iFormID, iKeyValue);
        hasPigonhole = pigonhole.pigonholeState(iFormID, iKeyValue);
        iFlowID = lcFlowControl.getFlowID(iFormID, iKeyValue);
%>  
  <tr  onMouseOver="javascript:this.className='trMouseOver'" 
       onMouseOut="javascript:this.className='trMouseOut'"
       onDblClick="javascript:showOperatorWin('div','<%=i %>',85)"       
       >
    <td width="5" title="<%=i%>">
    <% if (hasPigonhole) { %>
      <input type="checkbox" disabled>    
    <% } else { %>
      <!--   <input type="checkbox" disabled>   -->
      <input type="checkbox" name="chkId" id="chkId" value="<%=iKeyValue%>">    
    <% } %>
    </td>
    <%//=bdValueControl.printTableValue(value_str)%>
    <%=bdValueControl.printTableValue(value_str, "", "", 0, "", iKeyValue)%>
	  <%  
			if (flowType.equals("0")) {
				s_transact = lcFlowControl.getCurrentTransactingInfo(iFormID, iKeyValue, "<br>", true);
				sPressCount = Integer.toString(lcAssistant.getPressCount(iFormID, iKeyValue, SzConvert.toInt(s_transact[3])))
	            + "次/总"
	            + Integer.toString(lcAssistant.getPressCount(iFormID, iKeyValue, 0))
	            + "次";
				out.println("<td>" + s_transact[0] + "</td>");
				out.println("<td>" + s_transact[1] + "</td>");
				if (bPress) {
				out.println("<td>" + sPressCount + "</td>");
				}
			} else if (flowType.equals("2")) {
				s_transact = lcFlowControl.getFinishInfo(iFormID, iKeyValue);
				out.println("<td>" + s_transact[0] + "</td>");
				out.println("<td>" + s_transact[1] + "</td>");				
			}	   	   
	  %>      
    <td><%=lcFlowControl.getFlowStateName(iFormID, iKeyValue) %>&nbsp;</td>
    <td>
      <a onclick="showOperatorWin('div','<%=i %>',85)" href="#">操作</a>
      <div id="div<%=i %>" class="div" style="left: 10px;top: 200px;width: 70px;">
      	<div style="padding-top:5px;padding-bottom:5px;position:relative; background-color:#cccccc;border: 0px;">
 				<div  class="Operation">    
	    
      	<% if (!hasPigonhole) { %>
      	<a href="javascript:FormSubmit(formPage,'update.jsp?OPERATOR=detail&type=<%=flowType%>&KEY=<%=iKeyValue%>&from=3');">详情</a><br>      	
      	<% if (iState == 0 && bPress) { %>
      	<a href="#" OnClick="javascript:OpenPressWin(<%=iFormID%>,<%=iKeyValue%>);">催办</a><br>
      	<% } %>
        <% if (isBarManager_SESSION) { %>
        	<% if (bReceive) { %>
        	<a href="../../flow/pass/pass_win.jsp?FormID=<%=iFormID%>&InfoID=<%=iKeyValue%>">印发</a><br>
        	<a href="../../flow/pass/index_manage.jsp?FormID=<%=iFormID%>&InfoID=<%=iKeyValue%>">印发管理</a><br>
        	<% } %>
        	<% if (iState == 2) { %>
        	<a href="#" OnClick="javascript:OpenPigonholeWin(<%=iFormID%>,<%=iKeyValue%>);">归档</a><br>
		  	<a href="javascript:FormSubmit(formPage,'update.jsp?OPERATOR=updateManage&type=<%=flowType%>&KEY=<%=iKeyValue%>');">变更</a><br>          
          	<% } %>
        <% } %>   
      <% } else { %>
      <font color='red'>已归档</font><br>
      <% } %>   
      <% if (!printTemp.equals("")) { %>
      <a href="#" OnClick="javascript:PrintWinWord('<%=iKeyValue%>')">打印浏览</a><br>
      <% } %>
      <% if (hasFlow) { %>
      <a href="#" OnClick="javascript:FlowDetailWin('<%=iFlowID%>','<%=iKeyValue%>');">查看流程</a>
      <% } %>
      <% if (!sWeboffice.equals("")) { %>
      <a href="#" OnClick="javascript:OfficeDetailWin('<%=iKeyValue%>');">查看正文</a>
      <% } %>      
         <a href="#" OnClick="javascript:hideOperatorWin('div');">取消菜单</a>
   		</div>
   		</div>
   	</div>               
    </td>
  </tr>
<%
    }
    out.println(SzPageHelp.outIndexTableTr(i, SzProperties.I_PageSize, 3 + iListFieldLen));
%>

  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="flowType" value="<%=flowType%>">
  <input type="hidden" name="txtSearchName" value="<%=sSearchName%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="FormID" value="<%=iFormID%>">   
  <tr>
    <td align="right">
      <%@ include file="/share/page/page_include.jsp"%>
    </td>
  </tr>
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="flowType" value="<%=flowType%>">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="FormID" value="<%=iFormID%>">   
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  //弹出窗口，选择人员。这里特定是流程里某个步骤的选择人员。
  function OpenPigonholeWin(vFormID, vInfoID) {
    var type = "all";
    var url = "../../flow/pigonhole/type_select.jsp?moduleId=99910&FormID=" + vFormID + "&InfoID=" + vInfoID;
    window.showModalDialog(url,window,"status=no;dialogWidth=750px;dialogHeight=450px");
  }  
  function OpenPressWin(vFormID, vInfoID) {
    hideOperatorWin("div");
    var type = "all";
    var url = "../../flow/press/win.jsp?FormID=" + vFormID + "&InfoID=" + vInfoID;
    window.showModalDialog(url,window,"status=no;dialogWidth=650px;dialogHeight=300px");
  }    
  function PrintWinWord(vKey) {
    var vUrl = "printTemp.jsp?FormID=<%=iFormID%>&KEY=" + vKey + "&type=0&printTemp=<%=printTemp%>";
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;dialogHeight=550px");
  	//window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;");
  }
  
  function FlowDetailWin(vFlowID, vKey) {
  	hideOperatorWin("div");
    var vUrl = "../../flow/flow/draft.jsp?type=" + vFlowID + "&FormID=<%=iFormID%>&InfoID=" + vKey + "&OPERATOR=detail"; 
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=720px;dialogHeight=550px");
  }  
  function OfficeDetailWin(vKey) {
    hideOperatorWin("div");
    var vUrl = "documentEdit.jsp?WebOffice=<%=sWeboffice%>&FormID=<%=iFormID%>&KEY=" + vKey; 
  	//window.open(vUrl,"","left=20,top=20,width=600,height=600");
  	window.showModalDialog(vUrl,window,"status=no;dialogWidth=850px;dialogHeight=800px");
  }     
</script>
