MenuAction.java~328~
上传用户: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.             menu.setMen_Time(new Date());
  197.             if (!maf.getId().equals(new Long(0))) {
  198.                 menu.setMen_ID(maf.getId());
  199.                 b = ms.UpdateMenu(menu);
  200.                 Message = "更新栏目成功,请返回!";
  201.             } else {
  202.                 b = ms.AddMenu(menu);
  203.                 Message = "添加栏目成功,请返回!";
  204.             }
  205.             ms.commit();
  206.         } catch (Exception ex) {
  207.             log.error(ex.getMessage(), ex);
  208.             try {
  209.                 ms.rollback();
  210.             } catch (Exception ex2) {
  211.                 log.error(ex2.getMessage(), ex2);
  212.             }
  213.         }
  214.         if(b == false){
  215.             Message = "操作失败,请返回!";
  216.         }
  217.         if (maf.getSuperiorID().equals(new Long(0))) {
  218.             Url = "/Manage/Menu.do?todo=OpenMenu";
  219.         } else {
  220.             Url = "/Manage/Menu.do?todo=OpenMenu&Language=" + maf.getLanguage() +
  221.                   "&superiorID=" + maf.getSuperiorID();
  222.         }
  223.         servletRequest.setAttribute("Message", Message);
  224.         servletRequest.setAttribute("Url", Url);
  225.         return actionMapping.findForward("EditMenu");
  226.     }
  227.     public ActionForward DeleteDefaultMenu(ActionMapping actionMapping,
  228.                                            ActionForm actionForm,
  229.                                            HttpServletRequest servletRequest,
  230.                                            HttpServletResponse servletResponse) {
  231.         Long menuID = new Long(0);
  232.         Menu menu = new Menu();
  233.         Long superiorID = new Long(0);
  234.         String Message = "";
  235.         boolean b = false;
  236.         try {
  237.             menuID = new Long(servletRequest.getParameter("menID"));
  238.             superiorID = new Long(servletRequest.getParameter("superiorID"));
  239.             ms.beginTran();
  240.             menu = ms.GetMenuById(menuID);
  241.             b = ms.DeleteMenu(menu);
  242.             Message = "删除成功,请返回!";
  243.             ms.commit();
  244.         } catch (Exception ex) {
  245.             log.error(ex.getMessage(), ex);
  246.             try {
  247.                 ms.rollback();
  248.             } catch (Exception ex2) {
  249.                 log.error(ex2.getMessage(), ex2);
  250.             }
  251.         }
  252.         if(b == false){
  253.             Message = "删除失败,请返回!";
  254.         }
  255.         servletRequest.setAttribute("Message", Message);
  256.         servletRequest.setAttribute
  257.                 ("Url", "/Manage/Menu.do?todo=OpenDefaultMenu&superiorID=" +
  258.                  superiorID);
  259.         return actionMapping.findForward("DeleteDefaultMenu");
  260.     }
  261.     public ActionForward DeleteMenu(ActionMapping actionMapping,
  262.                                     ActionForm actionForm,
  263.                                     HttpServletRequest servletRequest,
  264.                                     HttpServletResponse servletResponse) {
  265.         Long menuID = new Long(0);
  266.         Long superiorID = new Long(0);
  267.         List list = null;
  268.         Menu menu = null;
  269.         boolean b = false;
  270.         String Message = "";
  271.         String Language = "CN";
  272.         try {
  273.             if (servletRequest.getSession().getAttribute("Language") != null) {
  274.                 Language = servletRequest.getSession().getAttribute("Language").
  275.                            toString();
  276.             }
  277.             if (servletRequest.getParameter("menuID") != null) {
  278.                 menuID = new Long(servletRequest.getParameter("menuID"));
  279.             }
  280.             if (servletRequest.getParameter("superiorID") != null) {
  281.                 superiorID = new Long(servletRequest.getParameter("superiorID"));
  282.             }
  283.             ms.beginTran();
  284.             menu = ms.GetMenuById(menuID);
  285.             list = is.GetInformationByMenu(menu);
  286.             for (int i = 0; i < list.size(); i++) {
  287.                 Information inf = (Information) list.get(i);
  288.                 is.DeleteInformation(inf);
  289.             }
  290.             b = ms.DeleteMenu(menu);
  291.             Message = "删除菜单成功,请返回!";
  292.             ms.commit();
  293.         } catch (Exception ex) {
  294.             log.error(ex.getMessage(), ex);
  295.             try {
  296.                 ms.rollback();
  297.             } catch (Exception ex2) {
  298.                 log.error(ex2.getMessage(), ex2);
  299.             }
  300.         }
  301.         if (b == false) {
  302.             Message = "操作失败,请返回!";
  303.         }
  304.         servletRequest.setAttribute("Message", Message);
  305.         servletRequest.setAttribute("Url",
  306.                                     "/Manage/Menu.do?todo=OpenMenu&language=" +
  307.                                     Language + "&superiorID=" + superiorID);
  308.         return actionMapping.findForward("DeleteMenu");
  309.     }
  310. }