package zr.zrpower.analyseengine.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import zr.zrpower.common.web.Upload;
import zr.zrpower.common.util.SysPreperty;
import zr.zrpower.analyseengine.service.StatisticsConfig;

public class ActionStatistics1
    extends HttpServlet{

  //Initialize global variables
  public void init() throws ServletException {
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    response.setContentType("text/html; charset=GBK");

    String strTemplat = SysPreperty.getProperty().LogFilePath;
    strTemplat = strTemplat.substring(0,strTemplat.length()-3)+"StatExcel";

    //分析上传数据
    Upload upload = new Upload();
    upload.setSwitch(false);
    upload.setUpType(0);
    upload.setSuffix(".*");
    upload.setSize(1024*1024*20);  //上传限制为20M
    upload.setObjectPath(strTemplat);

    boolean bUploadOK = false;  //上传是否成功
    try {
      upload.setSourceFile(request);
      bUploadOK = true;
    }
    catch (IOException ex1) {

    }

    if(bUploadOK){
      Hashtable htFields = upload.getFields();
      String[] saFile = upload.getObjectFileName();
      String strAct = (String) htFields.get("Act");


             if (strAct.equals("reload")) {

               try {
                    StatisticsConfig Statistics = new StatisticsConfig();
                    String strID = (String) htFields.get("ID");
                if (saFile != null) {
                  if (saFile.length > 0) {
                       Statistics.SetReTable(strID,saFile[0]);
                  }
                }

                 response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/StatisticsEdit.jsp?SelectedItems="+strID);
               }
               catch (Exception ex) {
                   System.out.println(ex.toString());
               }
             }

           }
          }

            //Process the HTTP Post request
            public void doPost(HttpServletRequest request, HttpServletResponse response) throws
                ServletException, IOException {
              doGet(request, response);
            }

            //Clean up resources
            public void destroy() {
            }
    }
