<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.tool.*" %>
<%@ page import="com.jspsmart.upload.SmartUpload" %>
<%@ page import="com.jspsmart.upload.Request" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<title></title>
<BASE target=_self>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>

<%

	SmartUpload smartUpload = new SmartUpload();    
	smartUpload.initialize(pageContext);    
	smartUpload.upload();    
	Request requestSu = smartUpload.getRequest(); 
    //获取提交的参数
    String sModule = SzConvert.toSpaceStr(requestSu.getParameter("module"));
    String formName = SzConvert.toSpaceStr(requestSu.getParameter("formName"));
    int iFormID = SzConvert.toInt(requestSu.getParameter("formID"));
	String sType  = SzConvert.toZeroStr(requestSu.getParameter("type"));	//关联的ID
	String sPKEY  = SzConvert.toZeroStr(requestSu.getParameter("PKEY"));	//主表单信息ID
	String sPFORM = SzConvert.toZeroStr(requestSu.getParameter("PFORM"));	//主表单ID    
    
	
    boolean flag = false;
    String sUrl = "index.jsp";
    String sMessage = "";
 
    if (sModule.equals("")) {
    	sModule = "export";
    }
    SzAnnex szAnnex = new SzAnnex(sModule);
    String strFilePath = szAnnex.upload(smartUpload, sDLXM_SESSION);
    //导入增加关闭 2013-12-12
    smartUpload.closeAll();	

    if (strFilePath.equals("share/annexError.html")) {
    	flag = false;
    	sMessage = "上传失败!";
    } else if (sModule.equals("ModuleImport")) {
    		net.sz600.organize.SzModule szModule = new net.sz600.organize.SzModule();
			flag = szModule.importFile(iDLID_SESSION, sDLXM_SESSION, strFilePath);
			sMessage = szModule.sMessage;	
    } else if (sModule.equals("LoginInfoImport")) {
    		net.sz600.organize.SzLogin szLogin = new net.sz600.organize.SzLogin() ;
			flag = szLogin.importFile(iDLID_SESSION, sDLXM_SESSION, strFilePath);
			sMessage = szLogin.sMessage;
    } else if (sModule.equals("FormZipImport")) {
    	net.sz600.formCreate.BdFormImport bdFormImport = new net.sz600.formCreate.BdFormImport();
    	flag = bdFormImport.formImport(strFilePath);
    	sMessage = SzOutMessage.getMessage();
    } else {
    	BdValueControl bdValueControl = new BdValueControl();
    	if (iFormID >0) {
    		bdValueControl.setModuleInfo(iFormID);
    		flag = bdValueControl.importFile(iDLID_SESSION, sDLXM_SESSION, strFilePath, szCOMPANY_SESSION, sType, sPFORM, sPKEY);
    	} else if (!sModule.equals("") && !formName.equals(""))  {    		
    		bdValueControl.setModuleInfo(sModule, formName);
    		flag = bdValueControl.importFile(iDLID_SESSION, sDLXM_SESSION, strFilePath, szCOMPANY_SESSION);
    	}    		    	
    	//sMessage = khCustomer.sMessage;
    }
    

    if (flag) {
    	if (sModule.equals("FormZipImport")) {
    		//表单导入
    		
        	out.println("<script language='javascript'>"); 
        	//out.println("  var oWindow = window.dialogArguments;");
        	//out.println("  oWindow.document.location.reload(); ");
        	out.println("</script>");    		
    		out.println("<div align='center'>");
    		out.println(SzPageHelp.closeButton());
    		out.println(sMessage);    		
    		out.println("<br>" + SzPageHelp.closeButton());
    		out.println("</div>");
    		SzOutMessage.clearMessage();
    	} else {
	    	out.println(sMessage);
	        out.println(SzPageHelp.jsAlert("操作成功"));
	        //out.println(SzPageHelp.jsGoUrl(sUrl));
	        //out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
	        out.println("<script language='javascript'>"); 
	        //out.println("  var oWindow = window.opener.dialogArguments;");
	        //out.println("  eval('oWindow.document.location.reload();');");
	        //out.println("  window.opener.close();");
	        //out.println("  window.close();");
	        out.println("  var oWindow = window.dialogArguments;");
	        //out.println("  eval('oWindow.document.location.reload();');");
	        out.println("  oWindow.document.location.reload(); ");
	        out.println("  window.close();");
	        out.println("</script>"); 
    	}
    } else {
    	if (sModule.equals("FormZipImport")) {
    		//表单导入
        	out.println("<script language='javascript'>"); 
        	out.println("</script>");    		
    		out.println("<div align='center'>");
    		out.println(SzPageHelp.closeButton());
    		out.println(sMessage);    		
    		out.println("<br>" + SzPageHelp.closeButton());
    		out.println("</div>");
    		SzOutMessage.clearMessage();
    	} else {    	
        	out.println(SzPageHelp.jsAlertBack(sMessage));
        	out.println("<script language='javascript'>"); 
        	out.println("  window.close();");
        	out.println("</script>");
    	}
    }
    //关闭窗口
    
%>
