RoleAction.java~38~
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:8k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import com.chinacannel.entity.Model;
  3. import org.apache.struts.action.ActionForward;
  4. import javax.servlet.http.HttpServletRequest;
  5. import com.chinacannel.xlchemical.struts.Vo.ModelVo;
  6. import java.util.List;
  7. import com.chinacannel.xlchemical.service.ModelService;
  8. import org.apache.struts.action.ActionMapping;
  9. import javax.servlet.http.HttpServletResponse;
  10. import org.apache.struts.action.ActionForm;
  11. import org.apache.struts.actions.DispatchAction;
  12. import java.util.ArrayList;
  13. import com.chinacannel.xlchemical.struts.ActionForm.RoleActionForm;
  14. import com.chinacannel.entity.Role;
  15. import com.chinacannel.xlchemical.service.RoleService;
  16. import java.util.Date;
  17. import com.chinacannel.xlchemical.service.MenuService;
  18. public class RoleAction extends DispatchAction {
  19.     ModelService ms = new ModelService();
  20.     RoleService rs = new RoleService();
  21.     MenuService mes = new MenuService();
  22.     public ActionForward OpenRole(ActionMapping actionMapping,
  23.                                   ActionForm actionForm,
  24.                                   HttpServletRequest servletRequest,
  25.                                   HttpServletResponse servletResponse) {
  26.         List list = null;
  27.         List ModelList = new ArrayList();
  28.         Role role = null;
  29.         String Language = "CN";
  30.         List menuList = null;
  31.         try {
  32.             if (servletRequest.getSession().getAttribute("Language") != null) {
  33.                 Language = servletRequest.getSession().getAttribute("Language").
  34.                            toString();
  35.             }
  36.             ms.beginTran();
  37.             if (servletRequest.getParameter("RolID") != null) {
  38.                 role = rs.GetRoleById(new Long(servletRequest.getParameter(
  39.                         "RolID")));
  40.             }
  41.             list = ms.GetAllModel();
  42.             for (int i = 0; i < list.size(); i++) {
  43.                 ModelVo mv = new ModelVo();
  44.                 Model model = new Model();
  45.                 model = (Model) list.get(i);
  46.                 mv.setMod_CnName(model.getMod_CnName());
  47.                 mv.setMod_EnName(model.getMod_EnName());
  48.                 mv.setMod_ID(model.getMod_ID());
  49.                 mv.setMod_Order(model.getMod_Order());
  50.                 mv.setMod_Superior(model.getMod_Superior());
  51.                 mv.setMod_Url(model.getMod_Url());
  52.                 mv.setMod_Key(model.getMod_Key());
  53.                 ModelList.add(mv);
  54.             }
  55.             menuList = mes.GetMenuBySuperior(new Long(0), Language);
  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("role", role);
  66.         servletRequest.setAttribute("ModelList", ModelList);
  67.         servletRequest.setAttribute("menuList", menuList);
  68.         return actionMapping.findForward("OpenRole");
  69.     }
  70.     public ActionForward OpenRoleList(ActionMapping actionMapping,
  71.                                       ActionForm actionForm,
  72.                                       HttpServletRequest servletRequest,
  73.                                       HttpServletResponse servletResponse) {
  74.         List list = null;
  75.         try {
  76.             rs.beginTran();
  77.             list = rs.GetAllRole();
  78.             rs.commit();
  79.         } catch (Exception ex) {
  80.             log.error(ex.getMessage(), ex);
  81.             try {
  82.                 ms.rollback();
  83.             } catch (Exception ex2) {
  84.                 log.error(ex2.getMessage(), ex2);
  85.             }
  86.         }
  87.         servletRequest.setAttribute("list", list);
  88.         return actionMapping.findForward("OpenRoleList");
  89.     }
  90.     public ActionForward DeleteRole(ActionMapping actionMapping,
  91.                                     ActionForm actionForm,
  92.                                     HttpServletRequest servletRequest,
  93.                                     HttpServletResponse servletResponse) {
  94.         Role role = new Role();
  95.         boolean b = false;
  96.         String Message = "";
  97.         try {
  98.             rs.beginTran();
  99.             role = rs.GetRoleById
  100.                    (new Long(servletRequest.getParameter("roleID")));
  101.             b = rs.DeleteRole(role);
  102.             Message = "删除成功,请返回!";
  103.             rs.commit();
  104.         } catch (Exception ex) {
  105.             log.error(ex.getMessage(), ex);
  106.             try {
  107.                 ms.rollback();
  108.             } catch (Exception ex2) {
  109.                 log.error(ex2.getMessage(), ex2);
  110.             }
  111.         }
  112.         if (b == false) {
  113.             Message = "删除失败,请返回!";
  114.         }
  115.         servletRequest.setAttribute("Message", Message);
  116.         servletRequest.setAttribute("Url", "Manage/Role.do?todo=OpenRoleList");
  117.         return actionMapping.findForward("DeleteRole");
  118.     }
  119.     public ActionForward EditRole(ActionMapping actionMapping,
  120.                                   ActionForm actionForm,
  121.                                   HttpServletRequest servletRequest,
  122.                                   HttpServletResponse servletResponse) {
  123.         RoleActionForm raf = (RoleActionForm) actionForm;
  124.         Role role = new Role();
  125.         String fmodel = "";
  126.         String cmodel = "";
  127.         boolean b = false;
  128.         String Message = "";
  129.         String menu = "";
  130.         try {
  131.             rs.beginTran();
  132.             if (!raf.getId().equals(new Long(0))) {
  133.                 role = rs.GetRoleById(raf.getId());
  134.             }
  135.             String[] fmodels = servletRequest.getParameterValues("fmodel");
  136.             for (int i = 0; i < fmodels.length; i++) {
  137.                 if (fmodel.equals("")) {
  138.                     fmodel = fmodels[i];
  139.                 } else {
  140.                     fmodel += "," + fmodels[i];
  141.                 }
  142.                 String[] cmodels = servletRequest.getParameterValues(fmodels[i]);
  143.                 for (int j = 0; j < cmodels.length; j++) {
  144.                     if (cmodel.equals("")) {
  145.                         cmodel = cmodels[j];
  146.                     } else {
  147.                         cmodel += "," + cmodels[j];
  148.                     }
  149.                 }
  150.             }
  151.             String[] menus = servletRequest.getParameterValues("menus");
  152.             for (int i = 0; i < menus.length; i++) {
  153.                 if (menu.equals("")) {
  154.                     menu = menus[i];
  155.                 } else {
  156.                     menu += "," + menus[i];
  157.                 }
  158.             }
  159.             role.setRol_Menu(menu);
  160.             role.setRol_CModel(cmodel);
  161.             role.setRol_FModel(fmodel);
  162.             role.setRol_Name(raf.getName());
  163.             role.setRol_Time(new Date());
  164.             if (raf.getId().equals(new Long(0))) {
  165.                 b = rs.AddRole(role);
  166.                 Message = "添加成功,请返回!";
  167.             } else {
  168.                 b = rs.UpdateRole(role);
  169.                 Message = "更新成功,请返回!";
  170.             }
  171.             rs.commit();
  172.         } catch (Exception ex) {
  173.             log.error(ex.getMessage(), ex);
  174.             try {
  175.                 ms.rollback();
  176.             } catch (Exception ex2) {
  177.                 log.error(ex2.getMessage(), ex2);
  178.             }
  179.         }
  180.         if (b == false) {
  181.             Message = "操作失败,请返回!";
  182.         }
  183.         servletRequest.setAttribute("Url", "Manage/Role.do?todo=OpenRoleList");
  184.         servletRequest.setAttribute("Message", Message);
  185.         return actionMapping.findForward("EditRole");
  186.     }
  187. }