<%@ 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="com.jspsmart.upload.SmartUpload" %>
<%@ page import="com.jspsmart.upload.Request" %>
<%@ include file="/sessionInfoWeixin.jsp"%>
<%
  //2015-05-08增加，否则附件有乱码
  request.setCharacterEncoding("UTF-8");

	SmartUpload smartUpload = new SmartUpload();    
	smartUpload.initialize(pageContext);    
	smartUpload.upload();    
	Request requestSu = smartUpload.getRequest();


	
    //获取提交的参数
    String sType = SzConvert.toZeroStr(requestSu.getParameter("type"));
    String sPage = SzConvert.toZeroStr(requestSu.getParameter("page"));
    String sSearch = SzConvert.strWriteData(requestSu.getParameter("txtSearch"));
    String sPKEY = SzConvert.toZeroStr(requestSu.getParameter("PKEY"));
    String sPFORM = SzConvert.toZeroStr(requestSu.getParameter("PFORM")); 
		String sType2  = SzConvert.toZeroStr(requestSu.getParameter("type2"));	//关联的ID
		String sPKEY2  = SzConvert.toZeroStr(requestSu.getParameter("PKEY2"));	//主表单信息ID
		String sPFORM2 = SzConvert.toZeroStr(requestSu.getParameter("PFORM2"));	//主表单ID
		String from =  SzConvert.toZeroStr(requestSu.getParameter("from"));
		//System.out.println(from + "=============from");
    int iFormID = SzConvert.toInt(requestSu.getParameter("FormID"));
    String readonly = SzConvert.toSpaceStr(requestSu.getParameter("readonly"));
    //取得表单的信息
    String moduleName = "";
    String formName = "";
		LcForm lcForm = new LcForm();
		LcFormInfo lcFormInfo = null;    
    if (iFormID == 0) {
    	moduleName = SzConvert.toSpaceStr(requestSu.getParameter("moduleName"));
    	formName = SzConvert.toSpaceStr(requestSu.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(requestSu.getParameter("OPERATOR"));
	String sOPERATOR_SOURCE = SzConvert.toSpaceStr(requestSu.getParameter("OPERATOR_SOURCE"));
	String hiddenSave = SzConvert.toSpaceStr(requestSu.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(requestSu,session);
      	flag = true;
      } else {
		String id_str[] = requestSu.getParameterValues("chkId");
		//flag = bdValueControl.delete(requestSu, session);    	  
      }
    } else if (sOPERATOR.equals("deleteManage")) {
      String id_str[] = requestSu.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(requestSu);
    	sUrl = "sms_set.jsp";
    }else if (sOPERATOR.startsWith("detailPass")) {
    	//传阅时填写意见
			String sKEY = SzConvert.toZeroStr(requestSu.getParameter("KEY"));
      String sPassOpinion = SzConvert.toSpaceStr(requestSu.getParameter("PassOpinion"));
    	LcFlowControl flowControl = new LcFlowControl();
      flowControl.readPass(iFormID, iDLID_SESSION, SzConvert.toInt(sKEY), sPassOpinion);
    	flag = true;
    	sUrl = "index_receive.jsp";   
    } else {    	
		//flag = lcTest.control(request, session);
    	flag = bdValueControl.control(smartUpload, session, request);
    	iKeyValue = bdValueControl.getKeyValue();
    	
        if (sOPERATOR.equals("add") 
        	|| sOPERATOR.equals("update")
        	|| sOPERATOR.equals("export")
            || sOPERATOR.equals("send")
            || sOPERATOR.equals("exportCollect") 
            || sOPERATOR.equals("exportStat")) {
        	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";
    }    
    
    //2012-06-13
    smartUpload.closeAll();
    
    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") || sOPERATOR.equals("exportCollect") || sOPERATOR.equals("exportStat")) {
            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));
    }
%>
