<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ 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.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ include file="/sessionInfoWeixin.jsp"%>
<%

    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sPFORM = SzConvert.toZeroStr(request.getParameter("PFORM")); 
	String sType2  = SzConvert.toZeroStr(request.getParameter("type2"));	//关联的ID
	String sPKEY2  = SzConvert.toZeroStr(request.getParameter("PKEY2"));	//主表单信息ID
	String sPFORM2 = SzConvert.toZeroStr(request.getParameter("PFORM2"));	//主表单ID
	String from =  SzConvert.toZeroStr(request.getParameter("from"));
	//System.out.println(from + "=============from");
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    String readonly = SzConvert.toSpaceStr(request.getParameter("readonly"));
    //取得表单的信息
    String moduleName = "";
    String 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();  
    	}
    } 
%>

<%
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
	String sOPERATOR_SOURCE = SzConvert.toSpaceStr(request.getParameter("OPERATOR_SOURCE"));
	
	String hiddenSave = SzConvert.toSpaceStr(request.getParameter("hiddenSave"));
	int iKeyValue = 0;
    BdValueControl bdValueControl = new BdValueControl(moduleName, formName);
	
    boolean flag = false;
    String sUrl = "index.jsp";
    if (!sType.equals("0") && !sPFORM.equals("0")) {
    	sUrl = "relate_index.jsp";
    }
    String sMessage = "";
    if (sOPERATOR.equals("delete")) {
      if (!sType.equals("0") && !sPFORM.equals("0")) {    	
      	sUrl = "relate_index.jsp";
      	BdRelateForm relateForm = new BdRelateForm();
      	relateForm.deleteRelateFormInfo(request,session);
      	flag = true;
      } else {
		String id_str[] = request.getParameterValues("chkId");
		flag = bdValueControl.delete(request, session);    	  
      }
    } else if (sOPERATOR.equals("deleteManage")) {
      String id_str[] = request.getParameterValues("chkId");
      flag = bdValueControl.delete(id_str);
      sUrl = "index_manage.jsp";
      if (!sType.equals("0") && !sPFORM.equals("0")) {
      	sUrl = "relate_manage.jsp";
      }         
    } else if (sOPERATOR.equals("SMSSET")) {   
    	
    	BdForm bdForm = new BdForm();
    	flag = bdForm.smsSet(request);
    	sUrl = "sms_set.jsp";
    } else if (sOPERATOR.startsWith("transactAll")) { 
    	LcFlowControl flowControl = new LcFlowControl();
    	flag = flowControl.transactAll(request, session);
    	sUrl = "index_transact_all.jsp";
    } else if (sOPERATOR.startsWith("getBack")) {
    	//2011-07-12增加阅读状态：可以取回 
    	//取回
    	LcFlowControl flowControl = new LcFlowControl();
    	flag = flowControl.getBackTransact(request, session);
    	sUrl = "index_transacted.jsp";    	
    } else if (sOPERATOR.startsWith("ReadSelected")) {
    	//2011-07-12增加阅读选中的传阅文件 
    	LcFlowControl flowControl = new LcFlowControl();
    	String str_id[] = request.getParameterValues("chkId");
    	int iLen = 0;
    	if (str_id != null) {
    		iLen = str_id.length;
    	}
    	for (int i=0; i<iLen; i++) {
    		flowControl.readPass(iFormID, iDLID_SESSION, SzConvert.toInt(str_id[i]));
    	}
    	flag = true;
    	sUrl = "index_receive.jsp";     
    } else {    
		//flag = lcTest.control(request, session);
    	flag = bdValueControl.control(request, session);

    	iKeyValue = bdValueControl.getKeyValue();
    	
        if (sOPERATOR.equals("add") 
        	|| sOPERATOR.equals("update")
        	|| sOPERATOR.equals("export")
            || sOPERATOR.equals("send")) {
        	sUrl = "index.jsp";
            if (!sType.equals("0") && !sPFORM.equals("0")) {
            	sUrl = "relate_index.jsp";
            }   
            
        } else if (sOPERATOR.startsWith("transact")) {
        	sUrl = "index_transact.jsp";
        	if (from.equals("index_transact_all")) {
        		sUrl = "index_transact_all.jsp";
        	}        	
            if (!sType.equals("0") && !sPFORM.equals("0")) {
            	sUrl = "relate_transact.jsp";
            }        	
        } 
        
    }
    if (sOPERATOR_SOURCE.equals("updateManage")) {
    	sUrl = "index_manage.jsp";
    }
    sMessage = SzOut.getMessage();
    
    if (hiddenSave.equals("YES")) {
    	//返回修改或办理页面
    	if (sOPERATOR.startsWith("transact")) {
    		sOPERATOR = "transact";
    		sUrl = "update.jsp";
    	} else if (sOPERATOR.equals("add") || sOPERATOR.equals("update")) {
    		sOPERATOR = "update";
    		sUrl = "update.jsp";
    	}
    }    
%>
<form name="formHidden" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">
  <input type="hidden" name="PFORM" value="<%=sPFORM%>">  
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>">   
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
  <input type="hidden" name="KEY" value="<%=iKeyValue%>">  
  <input type="hidden" name="type2" value="<%=sType2%>">
  <input type="hidden" name="PKEY2" value="<%=sPKEY2%>">  
  <input type="hidden" name="PFORM2" value="<%=sPFORM2%>">
  <input type="hidden" name="from" value="<%=from%>">    
  <input type="hidden" name="readonly" value="<%=readonly%>">
</form>
<%    
    if (flag) {
        if (sOPERATOR.equals("export")) {
            out.println(SzPageHelp.jsFormSubmitBlank("formHidden", "../../down.jsp?tablename=export&filename=" + bdValueControl.getExportFile(szDLID_SESSION)));
        } else {
            if (hiddenSave.equals("YES")) {
            } else {        	        	
            	out.println(SzPageHelp.jsAlert("操作成功"));
            }
        }
        if (sOPERATOR.equals("updateWin")) {
			//刷新原来的窗口
        	out.println("<script language='javascript'>");	
        	out.println("  var oWindow = window.opener;");
        	out.println("  oWindow.document.location.reload(); ");
        	out.println("  window.close(); ");
        	out.println("</script>");			
        } else {
        	out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
        }
    } else {
        out.println(SzPageHelp.jsAlertBack(sMessage));
    }
%>
