package com.departusermiddlemodule.servlet;
import com.departusermiddlemodule.bean.TbDepartUserMiddle;
import com.departusermiddlemodule.dao.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;
public class TbDepartUserMiddleServlet extends HttpServlet{
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
String method = request.getParameter("method")==null?"":request.getParameter("method");
if("add".equals(method)){
int departId=Integer.parseInt(request.getParameter("departId"));
int userId=Integer.parseInt(request.getParameter("userId"));
int isMaster=Integer.parseInt(request.getParameter("isMaster"));
String createTime=request.getParameter("createTime");
if(new TbDepartUserMiddleDAO().add(new TbDepartUserMiddle(departId,userId,isMaster,createTime))){
request.getSession().setAttribute("result", "添加成功");
}else{
request.getSession().setAttribute("result", "添加失败");
}
request.getSession(true).setAttribute("tbDepartUserMiddleList",new TbDepartUserMiddleDAO().getTbDepartUserMiddleAll());
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleList.jsp");
}
if("del".equals(method)){
if(UtilDAO.delin("Tb_DepartUserMiddle", "DepartUserMiddleId", request.getParameter("delIds"))){
request.getSession().setAttribute("result", "删除成功");
}else{
request.getSession().setAttribute("result", "删除失败");
}
request.getSession(true).setAttribute("tbDepartUserMiddleList",new TbDepartUserMiddleDAO().getTbDepartUserMiddleAll());
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleList.jsp");
}
if("edit".equals(method)){
int departUserMiddleId=Integer.parseInt(request.getParameter("departUserMiddleId"));
int departId=Integer.parseInt(request.getParameter("departId"));
int userId=Integer.parseInt(request.getParameter("userId"));
int isMaster=Integer.parseInt(request.getParameter("isMaster"));
String createTime=request.getParameter("createTime");
if(new TbDepartUserMiddleDAO().add(new TbDepartUserMiddle(departUserMiddleId,departId,userId,isMaster,createTime))){
request.getSession().setAttribute("result", "修改成功");
}else{
request.getSession().setAttribute("result", "修改失败");
}
request.getSession(true).setAttribute("tbDepartUserMiddleList",new TbDepartUserMiddleDAO().getTbDepartUserMiddleAll());
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleList.jsp");
}
if ("list".equals(method)) {
request.getSession(true).setAttribute("tbDepartUserMiddleList",new TbDepartUserMiddleDAO().getTbDepartUserMiddleAll());
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleList.jsp");
}
if ("listById".equals(method)) {
request.getSession(true).setAttribute("tbDepartUserMiddle",new TbDepartUserMiddleDAO().getTbDepartUserMiddleByDepartUserMiddleId(Integer.parseInt(request.getParameter("departUserMiddleId"))));
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleOperate.jsp");
}
if("showadd".equals(method)){
response.sendRedirect("DepartusermiddleModule/TbDepartUserMiddleOperate.jsp");
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest(request, response);
}// end method doGet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.processRequest(request, response);
}// end method doPost
}