package zr.zrpower.flowengine.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.web.bean.MessageBox;
import zr.zrpower.flowengine.mode.config.FLOW_CONFIG_PROCESS;
import zr.zrpower.flowengine.service.FlowConfig;

/**
 * <p>Title: ZRPower</p>
 * <p>Description: ZRPowerWeb程序</p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: </p>
 * @author  NFZR
 */
public class FlowProcess
    extends MessageBox {

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

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      ServletException, IOException {
    request.setCharacterEncoding("GBK");
    response.setContentType("text/html; charset=GBK");
    String strAction = request.getParameter("Act");
    if (!strAction.equals(null)) {
      if (strAction.equals("edit")) {
        Edit(request, response);
      }

      if (strAction.equals("del")) {
        Delete(request, response);
      }

      if (strAction.equals("add")) {
        Add(request, response);
      }
      if (strAction.equals("edit1")) {
        edit1(request, response);
      }

   }
}

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

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

  //修改流程管理基本属性
  private void Edit(HttpServletRequest request,
                        HttpServletResponse response) throws IOException {

    FLOW_CONFIG_PROCESS ProcessId = new FLOW_CONFIG_PROCESS();
    ProcessId.fullDataFromRequest(request);

    try {

      FlowConfig Flow = new FlowConfig();
      String strFormfields = request.getParameter("formfields");
      String strFormfields1 = request.getParameter("formfields1");
      Flow.EditPr(ProcessId,strFormfields,strFormfields1);

      ProcessId = null;
      Flow = null;
      response.sendRedirect("ZrWorkFlow/flowconfig/Other/CloseWindow.jsp");
    }
    catch (Exception ex) {
      this.Msg = "文件管理中间件服务失败！<br>详细错误信息：" + ex.toString();
    }
    ProcessId = null;
    this.returnPath = "ZrWorkFlow/flowconfig/Other/CloseWindow.jsp";
    //this.GetBox();
  }

  //删除流程管理基本属性
  private void Delete(HttpServletRequest request,
                          HttpServletResponse response) throws IOException {
    try {
      FlowConfig Flow = new FlowConfig();
      Flow.DeletePr(request.getParameter("ID"));
      Flow = null;
      response.sendRedirect("ZrWorkFlow/flowconfig/Other/CloseWindow.jsp");
    }
    catch (Exception ex) {
      this.Msg = "连接文件管理中间件服务失败！<br>详细错误信息：" + ex.toString();
    }

    this.returnPath = "ZrWorkFlow/flowconfig/Other/CloseWindow.jsp";
    ////this.GetBox();
  }

  //添加流程管理基本属性
  private void Add(HttpServletRequest request, HttpServletResponse response) throws
      IOException {

    FLOW_CONFIG_PROCESS ProcessId = new FLOW_CONFIG_PROCESS();
    try {
      FlowConfig Flow = new FlowConfig();
      ProcessId.fullDataFromRequest(request);
      String strFormfields = request.getParameter("formfields");
      String strFormfields1 = request.getParameter("formfields1");
      Flow.AddPr(ProcessId,strFormfields,strFormfields1);

      Flow = null;
      ProcessId = null;

      response.sendRedirect("ZrWorkFlow/flowconfig/Other/CloseWindow.jsp");
    }
    catch (Exception ex2) {
      this.Msg = "连接客户端文件中间件服务失败！<br>详细错误信息：<br>   " + ex2.toString();
    }
    this.returnPath = "ZrWorkFlow/flowconfig/Other/CloseWindow.jsp";
    //this.GetBox();
  }

  //修改流程管理基本属性
   private void edit1(HttpServletRequest request,
                         HttpServletResponse response) throws IOException {
     String strconneid = request.getParameter("ID");
   try {
      FlowConfig Flow = new FlowConfig();
       String strName = request.getParameter("NAME");
       String strdesc1 = request.getParameter("DESC1");
       String strwhere1 = request.getParameter("WHERE1");
       String type = request.getParameter("CONNTYPE");
       String ISNEED = request.getParameter("ISNEED");
       String ISATT = request.getParameter("ISATT");

       String strFormfields = request.getParameter("formfields");
       Flow.UpdataActivity(strconneid,strName,strdesc1,strwhere1,type,ISNEED,ISATT,strFormfields);

       Flow = null;
       response.sendRedirect("ZrWorkFlow/flowconfig/FlowProcess/ManageActivityConne.jsp?ID="+strconneid);
     }
     catch (Exception ex) {
       this.Msg = "文件管理中间件服务失败！<br>详细错误信息：" + ex.toString();
     }


     this.returnPath = "ZrWorkFlow/flowconfig/FlowProcess/ManageActivityConne.jsp?ID="+strconneid;
     //this.GetBox();
  }

}
