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