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