MenuAction.java~323~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:13k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import org.apache.struts.actions.DispatchAction;
- import org.apache.struts.action.ActionForward;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionMapping;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import com.chinacannel.xlchemical.service.MenuService;
- import com.chinacannel.xlchemical.struts.ActionForm.MenuActionForm;
- import java.util.List;
- import com.chinacannel.entity.Menu;
- import com.chinacannel.common.ImageUpload;
- import com.chinacannel.entity.Image;
- import com.chinacannel.xlchemical.service.DefaultColumnService;
- import com.chinacannel.entity.DefaultColumn;
- import com.chinacannel.xlchemical.service.InformationService;
- import com.chinacannel.entity.Information;
- import com.chinacannel.xlchemical.service.RoleService;
- import com.chinacannel.entity.Admin;
- import com.chinacannel.entity.Role;
- public class MenuAction extends DispatchAction {
- MenuService ms = new MenuService();
- DefaultColumnService dcs = new DefaultColumnService();
- InformationService is = new InformationService();
- public ActionForward OpenMenu(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List list = null;
- Menu menu = new Menu();
- Long superiorID = new Long(0);
- String Language = "CN";
- try {
- if (servletRequest.getParameter("superiorID") != null) {
- superiorID = new Long(servletRequest.getParameter("superiorID"));
- }
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").toString();
- }
- ms.beginTran();
- if (superiorID.equals(new Long(0))) {
- //list = ms.GetMenuBySuperior(superiorID, Language);
- RoleService rs = new RoleService();
- Admin adm = (Admin) servletRequest.getSession().getAttribute("admin");
- Role role = rs.GetRoleById(adm.getRole().getRol_ID());
- String[] menus = role.getRol_Menu().split(",");
- for (int i = 0; i < menus.length; i++) {
- ms.GetMenuByKey(menus[i] + Language);
- }
- } else {
- list = ms.GetRutMenuBySuperior(superiorID, Language);
- }
- if (servletRequest.getParameter("menID") != null) {
- menu = ms.GetMenuById(new Long(servletRequest.getParameter(
- "menID")));
- }
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("list", list);
- servletRequest.setAttribute("menu", menu);
- if (superiorID.equals(new Long(0))) {
- return actionMapping.findForward("OpenMenu");
- } else {
- return actionMapping.findForward("OpenChildMenu");
- }
- }
- public ActionForward OpenDefaultMenu(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List defList = null;
- List menuList = null;
- Long menuID = new Long(0);
- Menu menu = new Menu();
- String Language = "CN";
- try {
- if (servletRequest.getParameter("menuID") != null) {
- menuID = new Long(servletRequest.getParameter("menuID"));
- }
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- ms.beginTran();
- defList = dcs.GetAllDefaultColumn(Language);
- menuList = ms.GetDefaultMenuByMenID
- (new Long(servletRequest.getParameter("superiorID")));
- if(menu.equals(new Long(0))){
- menu = ms.GetMenuById(menuID);
- }
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("defList", defList);
- servletRequest.setAttribute("menuList", menuList);
- servletRequest.setAttribute("menu", menu);
- return actionMapping.findForward("OpenDefaultMenu");
- }
- public ActionForward EditDefaultColumn(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Menu menu = new Menu();
- MenuActionForm maf = (MenuActionForm)actionForm;
- String Message = "";
- String Language = "CN";
- try {
- ms.beginTran();
- if (!maf.getId().equals(new Long(0))) {
- menu = ms.GetMenuById(maf.getId());
- }
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- DefaultColumn dc = dcs.GetDefaultColumnById(new Long(maf.getName()));
- menu.setMen_Default(new Long(1));
- menu.setMen_Index(new Long(0));
- menu.setMen_Name(maf.getName());
- menu.setMen_Order(maf.getOrder());
- menu.setMen_Superior(maf.getSuperiorID());
- menu.setMen_Url(dc.getDef_Url());
- menu.setMen_Language(Language);
- if (maf.getId().equals(new Long(0))) {
- ms.AddMenu(menu);
- Message = "设置缺省栏目成功,请返回!";
- } else {
- ms.UpdateMenu(menu);
- Message = "更新缺省栏目成功,请返回!";
- }
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "/Manage/Menu.do?todo=OpenDefaultMenu&superiorID=" +
- maf.getSuperiorID());
- return actionMapping.findForward("EditDefaultColumn");
- }
- public ActionForward EditMenu(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- MenuActionForm maf = (MenuActionForm) actionForm;
- Menu menu = new Menu();
- ImageUpload iu = new ImageUpload();
- boolean b = false;
- String Message = "";
- String Url = "";
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- ms.beginTran();
- if(!maf.getId().equals(new Long(0))){
- menu = ms.GetMenuById(maf.getId());
- }
- if (maf.getMenuImg() != null && maf.getMenuImg().getFileSize() > 0) {
- if (!maf.getImageID().equals(new Long(0))) {
- iu.deleteImage(maf.getImageID().intValue());
- }
- Image img = iu.saveImage(maf.getMenuImg(), servletRequest, false);
- menu.setImage(img);
- }
- menu.setMen_Default(new Long(0));
- menu.setMen_Index(maf.getIndex());
- menu.setMen_Language(maf.getLanguage());
- menu.setMen_Name(maf.getName());
- menu.setMen_Superior(maf.getSuperiorID());
- menu.setMen_Type(maf.getType());
- menu.setMen_Order(maf.getOrder());
- menu.setMen_Language(Language);
- if (!maf.getId().equals(new Long(0))) {
- menu.setMen_ID(maf.getId());
- b = ms.UpdateMenu(menu);
- Message = "更新栏目成功,请返回!";
- } else {
- b = ms.AddMenu(menu);
- Message = "添加栏目成功,请返回!";
- }
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if(b == false){
- Message = "操作失败,请返回!";
- }
- if (maf.getSuperiorID().equals(new Long(0))) {
- Url = "/Manage/Menu.do?todo=OpenMenu";
- } else {
- Url = "/Manage/Menu.do?todo=OpenMenu&Language=" + maf.getLanguage() +
- "&superiorID=" + maf.getSuperiorID();
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", Url);
- return actionMapping.findForward("EditMenu");
- }
- public ActionForward DeleteDefaultMenu(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long menuID = new Long(0);
- Menu menu = new Menu();
- Long superiorID = new Long(0);
- String Message = "";
- boolean b = false;
- try {
- menuID = new Long(servletRequest.getParameter("menID"));
- superiorID = new Long(servletRequest.getParameter("superiorID"));
- ms.beginTran();
- menu = ms.GetMenuById(menuID);
- b = ms.DeleteMenu(menu);
- Message = "删除成功,请返回!";
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if(b == false){
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute
- ("Url", "/Manage/Menu.do?todo=OpenDefaultMenu&superiorID=" +
- superiorID);
- return actionMapping.findForward("DeleteDefaultMenu");
- }
- public ActionForward DeleteMenu(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long menuID = new Long(0);
- Long superiorID = new Long(0);
- List list = null;
- Menu menu = null;
- boolean b = false;
- String Message = "";
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (servletRequest.getParameter("menuID") != null) {
- menuID = new Long(servletRequest.getParameter("menuID"));
- }
- if (servletRequest.getParameter("superiorID") != null) {
- superiorID = new Long(servletRequest.getParameter("superiorID"));
- }
- ms.beginTran();
- menu = ms.GetMenuById(menuID);
- list = is.GetInformationByMenu(menu);
- for (int i = 0; i < list.size(); i++) {
- Information inf = (Information) list.get(i);
- is.DeleteInformation(inf);
- }
- b = ms.DeleteMenu(menu);
- Message = "删除菜单成功,请返回!";
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "操作失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "/Manage/Menu.do?todo=OpenMenu&language=" +
- Language + "&superiorID=" + superiorID);
- return actionMapping.findForward("DeleteMenu");
- }
- }