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