package com.modulemodule.servelt;
import com.modulemodule.bean.TbModule;
import com.modulemodule.dao.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;
public class TbModuleServlet 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)){
String moduleName=request.getParameter("moduleName");
String moduleUrl=request.getParameter("moduleUrl");
int parentModuleId=Integer.parseInt(request.getParameter("parentModuleId"));
int isEnable=Integer.parseInt(request.getParameter("isEnable"));
String moduleMemo=request.getParameter("moduleMemo");
if(new TbModuleDAO().add(new TbModule(moduleName,moduleUrl,parentModuleId,isEnable,moduleMemo))){
request.getSession().setAttribute("result", "添加成功");
}else{
request.getSession().setAttribute("result", "添加失败");
}
request.getSession(true).setAttribute("tbModuleList",new TbModuleDAO().getTbModuleAll());
response.sendRedirect("ModuleModule/TbModuleList.jsp");
}
else if("del".equals(method)){
if(UtilDAO.delin("Tb_Module", "ModuleId", request.getParameter("delIds"))){
request.getSession().setAttribute("result", "删除成功");
}else{
request.getSession().setAttribute("result", "删除失败");
}
request.getSession(true).setAttribute("tbModuleList",new TbModuleDAO().getTbModuleAll());
response.sendRedirect("ModuleModule/TbModuleList.jsp");
}
else if("edit".equals(method)){
int moduleId=Integer.parseInt(request.getParameter("moduleId"));
String moduleName=request.getParameter("moduleName");
String moduleUrl=request.getParameter("moduleUrl");
int parentModuleId=Integer.parseInt(request.getParameter("parentModuleId"));
int isEnable=Integer.parseInt(request.getParameter("isEnable"));
String moduleMemo=request.getParameter("moduleMemo");
if(new TbModuleDAO().edit(new TbModule(moduleId,moduleName,moduleUrl,parentModuleId,isEnable,moduleMemo))){
request.getSession().setAttribute("result", "修改成功");
}else{
request.getSession().setAttribute("result", "修改失败");
}
request.getSession(true).setAttribute("tbModuleList",new TbModuleDAO().getTbModuleAll());
response.sendRedirect("ModuleModule/TbModuleList.jsp");
}
else if ("list".equals(method)) {
request.getSession(true).setAttribute("tbModuleList",new TbModuleDAO().getTbModuleAll());
response.sendRedirect("ModuleModule/TbModuleList.jsp");
}
else if ("listById".equals(method)) {
//查询所有父模块
request.getSession(true).setAttribute("tbModuleList", new TbModuleDAO().getTbModuleByParentModuleId(-1));
request.getSession(true).setAttribute("parmoduleId", request.getParameter("moduleId"));
request.getSession(true).setAttribute("tbModule",new TbModuleDAO().getTbModuleByModuleId(Integer.parseInt(request.getParameter("moduleId"))));
response.sendRedirect("ModuleModule/TbModuleOperate.jsp");
}
else if("showadd".equals(method)){
request.getSession().removeAttribute("tbModule");
request.getSession(true).setAttribute("tbModuleList", new TbModuleDAO().getTbModuleByParentModuleId(-1));
request.getSession(true).setAttribute("parmoduleId", "");
response.sendRedirect("ModuleModule/TbModuleOperate.jsp");
}
else if("toindex".equals(method)){
request.getSession(true).setAttribute("tbModuleList",new TbModuleDAO().getTbModuleByParentModuleId(-1));
response.sendRedirect("index.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
}