<%@ page contentType="text/html;charset=gbk" %>
<%@ 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.*" %>
<%@ include file="/sessionInfo.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
	
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    //取得表单的信息
    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 {    	
		//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")
            || 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 (!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%>">   
</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));
    }
%>
