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