MenuAction.java~325~
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:13k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import org.apache.struts.actions.DispatchAction;
  3. import org.apache.struts.action.ActionForward;
  4. import javax.servlet.http.HttpServletRequest;
  5. import org.apache.struts.action.ActionMapping;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.struts.action.ActionForm;
  8. import com.chinacannel.xlchemical.service.MenuService;
  9. import com.chinacannel.xlchemical.struts.ActionForm.MenuActionForm;
  10. import java.util.List;
  11. import com.chinacannel.entity.Menu;
  12. import com.chinacannel.common.ImageUpload;
  13. import com.chinacannel.entity.Image;
  14. import com.chinacannel.xlchemical.service.DefaultColumnService;
  15. import com.chinacannel.entity.DefaultColumn;
  16. import com.chinacannel.xlchemical.service.InformationService;
  17. import com.chinacannel.entity.Information;
  18. import com.chinacannel.xlchemical.service.RoleService;
  19. import com.chinacannel.entity.Admin;
  20. import com.chinacannel.entity.Role;
  21. public class MenuAction extends DispatchAction {
  22.     MenuService ms = new MenuService();
  23.     DefaultColumnService dcs = new DefaultColumnService();
  24.     InformationService is = new InformationService();
  25.     public ActionForward OpenMenu(ActionMapping actionMapping,
  26.                                   ActionForm actionForm,
  27.                                   HttpServletRequest servletRequest,
  28.                                   HttpServletResponse servletResponse) {
  29.         List list = null;
  30.         Menu menu = new Menu();
  31.         Long superiorID = new Long(0);
  32.         String Language = "CN";
  33.         try {
  34.             if (servletRequest.getParameter("superiorID") != null) {
  35.                 superiorID = new Long(servletRequest.getParameter("superiorID"));
  36.             }
  37.             if (servletRequest.getSession().getAttribute("Language") != null) {
  38.                 Language = servletRequest.getSession().getAttribute("Language").toString();
  39.             }
  40.             ms.beginTran();
  41.             if (superiorID.equals(new Long(0))) {
  42.                 //list = ms.GetMenuBySuperior(superiorID, Language);
  43.                 list = new ArrayList();
  44.                 RoleService rs = new RoleService();
  45.                 Admin adm = (Admin) servletRequest.getSession().getAttribute("admin");
  46.                 Role role = rs.GetRoleById(adm.getRole().getRol_ID());
  47.                 String[] menus = role.getRol_Menu().split(",");
  48.                 for (int i = 0; i < menus.length; i++) {
  49.                     list.add(ms.GetMenuByKey(menus[i] + Language));
  50.                 }
  51.             } else {
  52.                 list = ms.GetRutMenuBySuperior(superiorID, Language);
  53.             }
  54.             if (servletRequest.getParameter("menID") != null) {
  55.                 menu = ms.GetMenuById(new Long(servletRequest.getParameter(
  56.                         "menID")));
  57.             }
  58.             ms.commit();
  59.         } catch (Exception ex) {
  60.             log.error(ex.getMessage(), ex);
  61.             try {
  62.                 ms.rollback();
  63.             } catch (Exception ex2) {
  64.                 log.error(ex2.getMessage(), ex2);
  65.             }
  66.         }
  67.         servletRequest.setAttribute("list", list);
  68.         servletRequest.setAttribute("menu", menu);
  69.         if (superiorID.equals(new Long(0))) {
  70.             return actionMapping.findForward("OpenMenu");
  71.         } else {
  72.             return actionMapping.findForward("OpenChildMenu");
  73.         }
  74.     }
  75.     public ActionForward OpenDefaultMenu(ActionMapping actionMapping,
  76.                                          ActionForm actionForm,
  77.                                          HttpServletRequest servletRequest,
  78.                                          HttpServletResponse servletResponse) {
  79.         List defList = null;
  80.         List menuList = null;
  81.         Long menuID = new Long(0);
  82.         Menu menu = new Menu();
  83.         String Language = "CN";
  84.         try {
  85.             if (servletRequest.getParameter("menuID") != null) {
  86.                 menuID = new Long(servletRequest.getParameter("menuID"));
  87.             }
  88.             if (servletRequest.getSession().getAttribute("Language") != null) {
  89.                 Language = servletRequest.getSession().getAttribute("Language").
  90.                            toString();
  91.             }
  92.             ms.beginTran();
  93.             defList = dcs.GetAllDefaultColumn(Language);
  94.             menuList = ms.GetDefaultMenuByMenID
  95.                        (new Long(servletRequest.getParameter("superiorID")));
  96.             if(menu.equals(new Long(0))){
  97.                 menu = ms.GetMenuById(menuID);
  98.             }
  99.             ms.commit();
  100.         } catch (Exception ex) {
  101.             log.error(ex.getMessage(), ex);
  102.             try {
  103.                 ms.rollback();
  104.             } catch (Exception ex2) {
  105.                 log.error(ex2.getMessage(), ex2);
  106.             }
  107.         }
  108.         servletRequest.setAttribute("defList", defList);
  109.         servletRequest.setAttribute("menuList", menuList);
  110.         servletRequest.setAttribute("menu", menu);
  111.         return actionMapping.findForward("OpenDefaultMenu");
  112.     }
  113.     public ActionForward EditDefaultColumn(ActionMapping actionMapping,
  114.                                            ActionForm actionForm,
  115.                                            HttpServletRequest servletRequest,
  116.                                            HttpServletResponse servletResponse) {
  117.         Menu menu = new Menu();
  118.         MenuActionForm maf = (MenuActionForm)actionForm;
  119.         String Message = "";
  120.         String Language = "CN";
  121.         try {
  122.             ms.beginTran();
  123.             if (!maf.getId().equals(new Long(0))) {
  124.                 menu = ms.GetMenuById(maf.getId());
  125.             }
  126.             if (servletRequest.getSession().getAttribute("Language") != null) {
  127.                 Language = servletRequest.getSession().getAttribute("Language").
  128.                            toString();
  129.             }
  130.             DefaultColumn dc = dcs.GetDefaultColumnById(new Long(maf.getName()));
  131.             menu.setMen_Default(new Long(1));
  132.             menu.setMen_Index(new Long(0));
  133.             menu.setMen_Name(maf.getName());
  134.             menu.setMen_Order(maf.getOrder());
  135.             menu.setMen_Superior(maf.getSuperiorID());
  136.             menu.setMen_Url(dc.getDef_Url());
  137.             menu.setMen_Language(Language);
  138.             if (maf.getId().equals(new Long(0))) {
  139.                 ms.AddMenu(menu);
  140.                 Message = "设置缺省栏目成功,请返回!";
  141.             } else {
  142.                 ms.UpdateMenu(menu);
  143.                 Message = "更新缺省栏目成功,请返回!";
  144.             }
  145.             ms.commit();
  146.         } catch (Exception ex) {
  147.             log.error(ex.getMessage(), ex);
  148.             try {
  149.                 ms.rollback();
  150.             } catch (Exception ex2) {
  151.                 log.error(ex2.getMessage(), ex2);
  152.             }
  153.         }
  154.         servletRequest.setAttribute("Message", Message);
  155.         servletRequest.setAttribute("Url",
  156.                 "/Manage/Menu.do?todo=OpenDefaultMenu&superiorID=" +
  157.                                     maf.getSuperiorID());
  158.         return actionMapping.findForward("EditDefaultColumn");
  159.     }
  160.     public ActionForward EditMenu(ActionMapping actionMapping,
  161.                                   ActionForm actionForm,
  162.                                   HttpServletRequest servletRequest,
  163.                                   HttpServletResponse servletResponse) {
  164.         MenuActionForm maf = (MenuActionForm) actionForm;
  165.         Menu menu = new Menu();
  166.         ImageUpload iu = new ImageUpload();
  167.         boolean b = false;
  168.         String Message = "";
  169.         String Url = "";
  170.         String Language = "CN";
  171.         try {
  172.             if (servletRequest.getSession().getAttribute("Language") != null) {
  173.                 Language = servletRequest.getSession().getAttribute("Language").
  174.                            toString();
  175.             }
  176.             ms.beginTran();
  177.             if(!maf.getId().equals(new Long(0))){
  178.                 menu = ms.GetMenuById(maf.getId());
  179.             }
  180.             if (maf.getMenuImg() != null && maf.getMenuImg().getFileSize() > 0) {
  181.                 if (!maf.getImageID().equals(new Long(0))) {
  182.                     iu.deleteImage(maf.getImageID().intValue());
  183.                 }
  184.                 Image img = iu.saveImage(maf.getMenuImg(), servletRequest, false);
  185.                 menu.setImage(img);
  186.             }
  187.             menu.setMen_Default(new Long(0));
  188.             menu.setMen_Index(maf.getIndex());
  189.             menu.setMen_Language(maf.getLanguage());
  190.             menu.setMen_Name(maf.getName());
  191.             menu.setMen_Superior(maf.getSuperiorID());
  192.             menu.setMen_Type(maf.getType());
  193.             menu.setMen_Order(maf.getOrder());
  194.             menu.setMen_Language(Language);
  195.             if (!maf.getId().equals(new Long(0))) {
  196.                 menu.setMen_ID(maf.getId());
  197.                 b = ms.UpdateMenu(menu);
  198.                 Message = "更新栏目成功,请返回!";
  199.             } else {
  200.                 b = ms.AddMenu(menu);
  201.                 Message = "添加栏目成功,请返回!";
  202.             }
  203.             ms.commit();
  204.         } catch (Exception ex) {
  205.             log.error(ex.getMessage(), ex);
  206.             try {
  207.                 ms.rollback();
  208.             } catch (Exception ex2) {
  209.                 log.error(ex2.getMessage(), ex2);
  210.             }
  211.         }
  212.         if(b == false){
  213.             Message = "操作失败,请返回!";
  214.         }
  215.         if (maf.getSuperiorID().equals(new Long(0))) {
  216.             Url = "/Manage/Menu.do?todo=OpenMenu";
  217.         } else {
  218.             Url = "/Manage/Menu.do?todo=OpenMenu&Language=" + maf.getLanguage() +
  219.                   "&superiorID=" + maf.getSuperiorID();
  220.         }
  221.         servletRequest.setAttribute("Message", Message);
  222.         servletRequest.setAttribute("Url", Url);
  223.         return actionMapping.findForward("EditMenu");
  224.     }
  225.     public ActionForward DeleteDefaultMenu(ActionMapping actionMapping,
  226.                                            ActionForm actionForm,
  227.                                            HttpServletRequest servletRequest,
  228.                                            HttpServletResponse servletResponse) {
  229.         Long menuID = new Long(0);
  230.         Menu menu = new Menu();
  231.         Long superiorID = new Long(0);
  232.         String Message = "";
  233.         boolean b = false;
  234.         try {
  235.             menuID = new Long(servletRequest.getParameter("menID"));
  236.             superiorID = new Long(servletRequest.getParameter("superiorID"));
  237.             ms.beginTran();
  238.             menu = ms.GetMenuById(menuID);
  239.             b = ms.DeleteMenu(menu);
  240.             Message = "删除成功,请返回!";
  241.             ms.commit();
  242.         } catch (Exception ex) {
  243.             log.error(ex.getMessage(), ex);
  244.             try {
  245.                 ms.rollback();
  246.             } catch (Exception ex2) {
  247.                 log.error(ex2.getMessage(), ex2);
  248.             }
  249.         }
  250.         if(b == false){
  251.             Message = "删除失败,请返回!";
  252.         }
  253.         servletRequest.setAttribute("Message", Message);
  254.         servletRequest.setAttribute
  255.                 ("Url", "/Manage/Menu.do?todo=OpenDefaultMenu&superiorID=" +
  256.                  superiorID);
  257.         return actionMapping.findForward("DeleteDefaultMenu");
  258.     }
  259.     public ActionForward DeleteMenu(ActionMapping actionMapping,
  260.                                     ActionForm actionForm,
  261.                                     HttpServletRequest servletRequest,
  262.                                     HttpServletResponse servletResponse) {
  263.         Long menuID = new Long(0);
  264.         Long superiorID = new Long(0);
  265.         List list = null;
  266.         Menu menu = null;
  267.         boolean b = false;
  268.         String Message = "";
  269.         String Language = "CN";
  270.         try {
  271.             if (servletRequest.getSession().getAttribute("Language") != null) {
  272.                 Language = servletRequest.getSession().getAttribute("Language").
  273.                            toString();
  274.             }
  275.             if (servletRequest.getParameter("menuID") != null) {
  276.                 menuID = new Long(servletRequest.getParameter("menuID"));
  277.             }
  278.             if (servletRequest.getParameter("superiorID") != null) {
  279.                 superiorID = new Long(servletRequest.getParameter("superiorID"));
  280.             }
  281.             ms.beginTran();
  282.             menu = ms.GetMenuById(menuID);
  283.             list = is.GetInformationByMenu(menu);
  284.             for (int i = 0; i < list.size(); i++) {
  285.                 Information inf = (Information) list.get(i);
  286.                 is.DeleteInformation(inf);
  287.             }
  288.             b = ms.DeleteMenu(menu);
  289.             Message = "删除菜单成功,请返回!";
  290.             ms.commit();
  291.         } catch (Exception ex) {
  292.             log.error(ex.getMessage(), ex);
  293.             try {
  294.                 ms.rollback();
  295.             } catch (Exception ex2) {
  296.                 log.error(ex2.getMessage(), ex2);
  297.             }
  298.         }
  299.         if (b == false) {
  300.             Message = "操作失败,请返回!";
  301.         }
  302.         servletRequest.setAttribute("Message", Message);
  303.         servletRequest.setAttribute("Url",
  304.                                     "/Manage/Menu.do?todo=OpenMenu&language=" +
  305.                                     Language + "&superiorID=" + superiorID);
  306.         return actionMapping.findForward("DeleteMenu");
  307.     }
  308. }