<%@ 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.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 sType = SzConvert.toZeroStr(request.getParameter("type"));
		int iFrom = SzConvert.toInt(request.getParameter("From"));
    String flowType = SzConvert.toSpaceStr(request.getParameter("flowType"));
	  String datefield = SzConvert.strWriteData(request.getParameter("datefield"));   //日期字段，     
		if (flowType.equals("")) {
			flowType = "-2";
		}
	
    //取得表单的信息
    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;
    }

    
    String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
    int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder")));         
    
    //组合查询条件 
    String id     = SzConvert.toSpaceStr(request.getParameter("id"));    
    int iCount    = SzConvert.toInt(request.getParameter("count"));
    String field = "";
    int cond = 0;
    String value = "";
    StringBuffer sb = new StringBuffer("1=1");
    for (int i=0; i<iCount; i++) {
    	field = SzConvert.toZeroStr(request.getParameter("field" + i));
    	cond = SzConvert.toInt(SzConvert.toZeroStr(request.getParameter("cond" + i)));
    	value = SzConvert.strWriteData(request.getParameter("value" + i));
    	if (!value.equals("")) {
    		sb.append(" AND ");
    		sb.append(field);
    		switch(cond) {
    		case 0:
    			sb.append(" = ");
    			break;
    		case 1:
    			sb.append(" like ");
    			value = "%" + value + "%";
    			break;
    		case 2:
    			sb.append(" > ");
    			break;
    		case 3:
    			sb.append(" >= ");
    			break;
    		case 4:
    			sb.append(" < ");
    			break;
    		case 5:
    			sb.append(" <= ");
    			break; 			
    		}
    		sb.append("'");
    		sb.append(value);
    		sb.append("'");
    	}
    }
    
    //从管理页面过来，说明有流程,根据流程办理状态筛选。
    /*
    //2015-01注释掉，这部分条件在其他地方已包括
    if (iFrom == 2) {
        String sKeyField = "";
        String str_InfoID = "";
    	BdValueControl bdValueControl = new BdValueControl(moduleName, formName);
    	sKeyField = bdValueControl.getKeyField();	
    	LcFlowControl lcFlowControl = new LcFlowControl();
    	str_InfoID = SzConvert.toZeroStr(lcFlowControl.getManageInfoID(iFormID, flowType));
		sb.append(" AND ");
		sb.append(sKeyField);
		sb.append(" IN (");
		sb.append(str_InfoID);
		sb.append(")");    	
    }    
    */
    String sCond = sb.toString();
    sb = null;
%>    
<form name="formHidden" method="post">
  <input type="hidden" name="searchCond" value="<%=sCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="From" value="<%=iFrom%>">   
  <input type="hidden" name="id" value="<%=id%>">  
  <input type="hidden" name="flowType" value="<%=flowType%>">  
  <input type="hidden" name="datefield" value="<%=datefield%>">  
</form>
<%
    String sUrl = "index.jsp";
    if (sType.equals("stat")) {
    	sUrl = "stat_result.jsp";	
    } else if (sType.equals("collect")) {
    	sUrl = "collect_result.jsp"; 
    } else {
    	if (iFrom == 2) {
			sUrl = "index_manage.jsp";
    	}
	}
	out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
%>

