<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.online.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ include file="/sessionInfoWeixin.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<%@ include file="/share/oa_app_title.jsp"%>
 <link href="<%=strLevel_SESSION%>app/images/soarwell_css.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="<%=strLevel_SESSION%>share/js/commonTool.js"></script>
<script language="javascript"> 
  function OpenPressWin(vFormID, vInfoID, vType) {
    var type = "all";
    var url = "../../flow/press/win_app.jsp?FormID=" + vFormID + "&InfoID=" + vInfoID + "&type=" + vType;
    //window.showModalDialog(url,window,"status=no;dialogWidth=650px;dialogHeight=300px");
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=400px,height=350px");
  }   
</script>  
</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 sTableAnnex = bdValueControl.getTableAnnex();	
	String assistant = bdValueControl.getAssistant(); 
    String sKeyField = bdValueControl.getKeyField();
    boolean hasFlow = bdValueControl.getHasFlow();
	String printTemp = bdValueControl.getPrintTemp();
	String sWeboffice = bdValueControl.getWebOffice();
	int iFlowID = 0;    

    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    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"));
  
    /////////////////////////////////////////流程相关
    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 = "-2";
		}    
    //hasSend = lcFlowControl.hasSend(iFormID, iInfoID);
        //获取管理的信息ID
    //String str_InfoID = lcFlowControl.getManageInfoID(iFormID, flowType);
        

    String sTable_type = "";
    //读取数据

    //String sCond = sKeyField + " IN (" + str_InfoID + ")";
    //if (!sPKEY.equals("0")) {
    //    sCond += "";
    //}
    String sCond = "1=1";
    if (!isBarManager_SESSION && !isDataCanSee_SESSION) {
    	sCond = "1<>1";
    }  
    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) {
    }

    int iPageSize = SzProperties.I_PageSize_APP; 
    //Collection coll = bdValueControl.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, sSearch);
    Collection coll = bdValueControl.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, iPageSize, 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 bRead = false;
	if ((";" + assistant + ";").indexOf(";13;") >=0) {
		bRead = true;
	}	
		
    SzAnnex szAnnex = new SzAnnex(sTableAnnex);
    SzReadForm szReadForm = new SzReadForm(iFormID);		
	BdFormControl bdFormControl = new BdFormControl();
	
%><!-----上面的工具栏------>
<%@ include file="title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="flowType" value="<%=flowType%>">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <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>  
      <% if (isBarManager_SESSION) { %>    
      <input type="button" name="btnDel" class="btnClass" value="删除" OnClick="javascript:FormSubmitConfirm(formList, 'control.jsp?OPERATOR=deleteManage','确定要删除？');">
      <% } %>    
      <%
      	String s_id[] = {"-2","0","1","2"};
      	String s_name[] = {"全部","办理中","否决","办结"};
      	out.println(SzPageHelp.radioSubmit("flowType", s_id, s_name, flowType));
      %>   
    </td>
  </tr>       
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="0" cellspacing="3" cellpadding="3" style="border:#D7D7D9 1px solid;">
  <form name="formList" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="FormID" value="<%=iFormID%>">   

<%
    String value_str[] = null;
    int iKeyValue = 0;
    int iListFieldLen = bdValueControl.getListFieldLen() + 4;
    int iState = 0;
    //归档状态
    LcPigonhole pigonhole = new LcPigonhole();
    boolean hasPigonhole = false;    
    String s_transact[] = null;
    String sPressCount = "";   
    
    LcAssistant lcAssistant = new LcAssistant();
    LcStep lcStep = new LcStep();
    
    boolean canGetBackTransact = false;
    bdValueControl.getTableTitleApp();
    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);   
        iFlowID = lcFlowControl.getFlowID(iFormID, iKeyValue);
        hasPigonhole = pigonhole.pigonholeState(iFormID, iKeyValue);
        //判断是否被读过//2011-07-12增加
        canGetBackTransact = lcFlowControl.canGetBackTransact(iFlowID, iFormID, iKeyValue, iDLID_SESSION);
        if (i>1) {
      		out.println("	<tr>");
  			out.println("	<td height=\"5\" align=\"left\" background=\"../images/line.gif\"></td>");
  			out.println("	</tr>\n"); 
        } 		
%>
  <tr>
    <td><span class="product_name"><%=i%></span>    
    <% if (hasPigonhole) { %>
      <input type="checkbox" disabled>    
    <% } else { %>
      <input type="checkbox" name="chkId" id="chkId" value="<%=iKeyValue%>">    
    <% } %>
      <%
      if (!sTableAnnex.equals("")) {
      	out.println(SzPageHelp.annexImage(strSkin_SESSION, szAnnex.hasAnnex(iKeyValue)));
      }
      if (bRead) {
      	out.println(SzPageHelp.newImage(strSkin_SESSION, szReadForm.hasReaded(iKeyValue, iDLID_SESSION)));
      }      
      %>      
      <% if (!hasPigonhole) { %>
      	<a href="javascript:FormSubmit(formPage,'detail.jsp?OPERATOR=detail&type=<%=flowType%>&KEY=<%=iKeyValue%>&from=<%=BdFormHelp.s_FROM_MANAGE%>');">详情</a>     	
      	<% if (iState == 0 && bPress) { %>
      	<a href="#" OnClick="javascript:OpenPressWin(<%=iFormID%>,<%=iKeyValue%>,'0');">催办</a>
      	<% } %>
      <% } else { %>
      <font color='red'>已归档</font><br>
      <% } %>   
      	             
    </td>    
  </tr>
	<% 
  	   if (hasFlow && iFlowID >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))
						 + "次";
		 if (s_transact[0] != null && !s_transact[0].equals("")) {
		   out.println("<tr><td><span class=\"product_content\"><b>[当前办理人员]</b>" + s_transact[0] + "</span></td></tr>");
		 }
		 if (s_transact[1] != null && !s_transact[1].equals("&nbsp;") && !s_transact[1].equals("")) {
		   out.println("<tr><td><span class=\"product_content\"><b>[剩余办理时间]</b>" + s_transact[1] + "</span></td></tr>");
		 }
	  	 
	  	 out.println("<tr><td><span class=\"product_content\"><b>[办理状态]</b>" + lcFlowControl.getFlowStateName(iFormID, iKeyValue) + "</span></td></tr>"); 
	   } 	
	   out.println(bdValueControl.printTableValueApp(value_str, "", "", 0, sType, iKeyValue,"detail",BdFormHelp.s_FROM_MANAGE));
    } //while
    out.println(bdValueControl.printTableBlankApp(i, iPageSize));
%> 
  </form>
</table>

<!-----下面的工具栏------>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <form name="formPage" method="post">  
  <input type="hidden" name="flowType" value="<%=flowType%>">  
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <%@ include file="/app/share/page_include.jsp" %>
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <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>
