<%@ page contentType="text/html;charset=UTF-8" %>
<%@ 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.system.*" %>
<%@ 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>
<%

    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 sKeyField = bdValueControl.getKeyField();
  	String sTableAnnex = bdValueControl.getTableAnnex();
%>	
<%@ include file="/share/title.jsp"%>
<%
    //获取提交的参数
    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; //是否已经发送出去
    //hasSend = lcFlowControl.hasSend(iFormID, iInfoID);
    //获取已经办理的信息ID
    String str_InfoID = lcFlowControl.getPassInfoIDNoPigonhole(iFormID, iDLID_SESSION);      

    String sTable_type = "";
    //读取数据
    LcTest lcTest = new LcTest();
    LcTestInfo lcTestInfo = null;
    String sCond = sKeyField + " IN (" + str_InfoID + ")";
    if (!sPKEY.equals("0")) {
        sCond += "";
    }
    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) {
    }

    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; 
    
    
    String sRead = "";  
    
	BdFormControl bdFormControl = new BdFormControl();
	SzAnnex szAnnex = new SzAnnex(sTableAnnex);
%>
<!-----上面的工具栏------>
<table width="100%">
  <form name="formBar" method="post">
  <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>&nbsp;<% out.println(bdFormControl.printFormDesc(Integer.parseInt(sMKID_SESSION),iFormID));%>
          <input type="button" name="" class="btnClass" value="批量阅示" OnClick="javascript:ReadSelected();">
    </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="OPERATOR" value="ReadSelected">
  <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%>">   
  <tr class="trClassTitle">
    <td width="5"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formList, chkCheckAll, 'chkId');"></td>
    <%
    if (!sTableAnnex.equals("")) {
    	out.println("<td width='20' align='center'>" + SzPageHelp.annexImage(strSkin_SESSION, true) + "</td>");
    }           
    %>
	<%=bdValueControl.printTableTitle(sSortField, iSortOrder)%>  
    <td width="60">个人状态</td>     
    <td width="60">总状态</td> 
    <td width="60">阅读状态</td>              
    <td>操作</td>
  </tr>
<%
    String value_str[] = null;
    int iKeyValue = 0;
    int iListFieldLen = bdValueControl.getListFieldLen();
    if (!sTableAnnex.equals("")) {
    	iListFieldLen++;
    }	    
    boolean hasRead = false;
    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); 
        hasRead = lcFlowControl.hasRead(iFormID, iDLID_SESSION, iKeyValue);
        
        if (hasRead) {
        	sRead = "已读";
        } else {
        	sRead = "<font color='red'>未读</font>";
        }
%>
  <tr  onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
    <td width="5" title="<%=i%>">
    <% if (!hasSend) { %>
      <input type="checkbox" name="chkId" id="chkId" value="<%=iKeyValue%>">    
    <% } else { %>
      <!--   <input type="checkbox" disabled>   -->
      <input type="checkbox" name="chkId" id="chkId" value="<%=iKeyValue%>">    
    <% } %>
    </td>
    <%
    if (!sTableAnnex.equals("")) {
    	out.println("<td width='20' align='center'>" + SzPageHelp.annexImage(strSkin_SESSION, szAnnex.hasAnnex(iKeyValue)) + "</td>");
    }
    %>      
    <%=bdValueControl.printTableValue(value_str)%>
    <td><%=lcFlowControl.getLastPersonStateName(iFormID, iKeyValue, iDLID_SESSION) %>&nbsp;</td>
    <td><%=lcFlowControl.getFlowStateName(iFormID, iKeyValue) %>&nbsp;</td>        
    <td><%=sRead %>&nbsp;</td>
    <td>
      <a href="javascript:FormSubmit(formPage,'update.jsp?OPERATOR=detailPass&type=<%=sType%>&KEY=<%=iKeyValue%>&from=6');">阅读</a>
      <% if (hasRead) { %>
      <a href="#" OnClick="javascript:OpenPigonholeWin(<%=iFormID%>,<%=iKeyValue%>);">归档</a>
      <% } %>                     
    </td>
  </tr>
<%
    }
    out.println(SzPageHelp.outIndexTableTr(i, SzProperties.I_PageSize, 5 + iListFieldLen));
%>

  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <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="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>
<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=23&FormID=" + vFormID + "&InfoID=" + vInfoID;
    window.showModalDialog(url,window,"status=no;dialogWidth=750px;dialogHeight=450px");
  }  
  
  function ReadSelected() {
  	if (confirm("确定要将选中的设置为已阅读吗？")) {
  		formList.action = "control.jsp";
  		formList.submit();
  	}
  } 
    
</script>
