package zr.zrpower.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import zr.zrpower.web.bean.MessageBox;
import zr.zrpower.entity.sys.BPIP_USER_IDEA;
import zr.zrpower.ejb.sys.UserIdeaService;
import zr.zrpower.common.util.FunctionMessage;


public class ActionUserIdea
    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("delete")){
       Delete(request,response);
     }

     if(strAction.equals("add")){
       Add(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  FileNotFoundException,IOException{
if(request.getContentLength()>0){
  BPIP_USER_IDEA  idea= new BPIP_USER_IDEA();
  idea.fullDataFromRequest(request);
  try {
    UserIdeaService ideaManage = new UserIdeaService();

    if (ideaManage.EditUserIdea(idea).getResult()) {
      this.Msg = "意见信息修改成功！";
      idea = null;
      ideaManage = null;
      response.sendRedirect( "zrsysmanage/selfmanage/SeIdea/List.jsp");
      this.isOk = true;
    }
  }
  catch (Exception ex) {
    this.Msg = "意见信息管理中间件服务失败！<br>详细错误信息："+ex.toString();
  }
}
this.out = response.getWriter();
this.returnPath = "zrsysmanage/selfmanage/SeIdea/List.jsp";
//this.GetBox();
}


  //删除意见
private void Delete(HttpServletRequest request, HttpServletResponse response)throws  IOException{
  try {
    UserIdeaService ideaManage = new UserIdeaService();
    ideaManage.DelUserIdea(request.getParameter("ID"));
    this.Msg = "意见信息删除成功！";
      this.isOk = true;
      ideaManage = null;
      response.sendRedirect( "zrsysmanage/selfmanage/SeIdea/List.jsp");
    }
    catch (Exception ex) {
      this.Msg = "连接客户端意见信息中间件服务失败！<br>详细错误信息："+ex.toString();
    }

  this.out = response.getWriter();
  this.returnPath =  "zrsysmanage/selfmanage/SeIdea/List.jsp";
  //this.GetBox();
}

//增加意见

private void Add(HttpServletRequest request, HttpServletResponse response) throws  FileNotFoundException,IOException{
if(request.getContentLength()>0){
  BPIP_USER_IDEA  idea= new BPIP_USER_IDEA();
  idea.fullDataFromRequest(request);
  try {
    UserIdeaService ideaManage = new UserIdeaService();

    if (ideaManage.AddUserIdea(idea).getResult()) {
      this.Msg = "意见增加成功！";
      this.isOk = true;
      this.returnPath = "zrsysmanage/selfmanage/SeIdea/List.jsp";
      idea = null;
      ideaManage = null;
      response.sendRedirect( "zrsysmanage/selfmanage/SeIdea/List.jsp");
    }
  }
  catch (Exception ex) {
    this.Msg = "意见信息管理中间件服务失败！<br>详细错误信息："+ex.toString();
  }
}
this.out = response.getWriter();
this.returnPath = "zrsysmanage/selfmanage/SeIdea/List.jsp";
//this.GetBox();
}

}
