package zr.zrpower.analyseengine.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.analyseengine.service.StatisticsConfig;


public class ActionStatisticsOther
    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");
     request.setCharacterEncoding("GBK");
     String strFID = request.getParameter("FID");

     String strAct = request.getParameter("Act");
     if (!strAct.equals(null)) {

         if (strAct.equals("savecfield")) {      //统计计算字段配置
             SaveCField(request, response);
             response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/List3.jsp?ID="+strFID);

           }

           if (strAct.equals("savecustom")) {
               SaveCustom(request, response);       //自定义统计字段配置
               response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/CloseWindow1.jsp");
           }

         if (strAct.equals("savewhere")) {
            SaveWhere(request, response);        //统计条件配置
            response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/List4.jsp?ID="+strFID);
         }
         if (strAct.equals("savecconnection")) {
             SaveCConnection(request, response);  //统计计算字段关联配置表
             response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/CloseWindow1.jsp");
         }

         if (strAct.equals("savecwhere")) {
            SaveCWhere(request, response);        //计算字段初始条件
            response.sendRedirect("ZrAnalyseEngine/StatisticsConfig/CloseWindow1.jsp");
         }



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

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

/**
   * 保存计算字段配置
   * @return FunctionMessage
*/
private void SaveCField(HttpServletRequest request,
                           HttpServletResponse response) throws IOException {
     try {

       StatisticsConfig Statistics = new StatisticsConfig();
       String strFID = request.getParameter("FID");
       String SaveAnalyseCFieldStr  = request.getParameter("AnalyseCFieldStr");
       Statistics.SaveAnalyseCFieldInfo(strFID,SaveAnalyseCFieldStr);
       Statistics = null;
     }
     catch (Exception ex) {

     }

 }


/**
 * 保存统计条件配置
 * @return FunctionMessage
*/
private void SaveWhere(HttpServletRequest request,
                             HttpServletResponse response) throws IOException {
       try {
         StatisticsConfig Statistics = new StatisticsConfig();
         String strFID = request.getParameter("FID");
         String SaveAnalyseWhereStr  = request.getParameter("AnalyseWhereStr");
         Statistics.SaveAnalyseWhereInfo(strFID,SaveAnalyseWhereStr);
         Statistics = null;
       }
       catch (Exception ex) {

       }
}
/**
* 统计计算字段关联配置表
* @return FunctionMessage
*/
private void SaveCConnection(HttpServletRequest request,
         HttpServletResponse response) throws IOException {
         try {
           StatisticsConfig Statistics = new StatisticsConfig();
           String strFID = request.getParameter("FID");
           String SaveAnalyseCConnectionStr  = request.getParameter("AnalyseCConnectionStr");
           Statistics.SaveAnalyseCConnectionInfo(strFID,SaveAnalyseCConnectionStr);
           Statistics = null;

         }
         catch (Exception ex) {
         }

}
       /**
         * 保存自定义统计字段配置
         * @return FunctionMessage
       */
       private void SaveCustom(HttpServletRequest request,
              HttpServletResponse response) throws IOException {
              try {
                StatisticsConfig Statistics = new StatisticsConfig();
                String strFID = request.getParameter("FID");
                String SaveAnalyseCustomStr  = request.getParameter("AnalyseCustomStr");
                Statistics.SaveAnalyseCostomInfo(strFID,SaveAnalyseCustomStr);
                Statistics = null;

               }
             catch (Exception ex) {
             }
  }

/**
 * 保存计算字段初始条件
 * @return FunctionMessage
*/
private void SaveCWhere(HttpServletRequest request,
       HttpServletResponse response) throws IOException {
       try {
          StatisticsConfig Statistics = new StatisticsConfig();
          String strFID = request.getParameter("FID");
          String SaveAnalyseCWhereStr  = request.getParameter("AnalyseCWhereStr");
          Statistics.SaveAnalyseCWhereInfo(strFID,SaveAnalyseCWhereStr);
          Statistics = null;

          }
          catch (Exception ex) {

          }

   }




}
