RoleAction.java~37~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:8k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import com.chinacannel.entity.Model;
- import org.apache.struts.action.ActionForward;
- import javax.servlet.http.HttpServletRequest;
- import com.chinacannel.xlchemical.struts.Vo.ModelVo;
- import java.util.List;
- import com.chinacannel.xlchemical.service.ModelService;
- import org.apache.struts.action.ActionMapping;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.actions.DispatchAction;
- import java.util.ArrayList;
- import com.chinacannel.xlchemical.struts.ActionForm.RoleActionForm;
- import com.chinacannel.entity.Role;
- import com.chinacannel.xlchemical.service.RoleService;
- import java.util.Date;
- import com.chinacannel.xlchemical.service.MenuService;
- public class RoleAction extends DispatchAction {
- ModelService ms = new ModelService();
- RoleService rs = new RoleService();
- MenuService mes = new MenuService();
- public ActionForward OpenRole(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List list = null;
- List ModelList = new ArrayList();
- Role role = null;
- String Language = "CN";
- List menuList = null;
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- ms.beginTran();
- if (servletRequest.getParameter("RolID") != null) {
- role = rs.GetRoleById(new Long(servletRequest.getParameter(
- "RolID")));
- }
- list = ms.GetAllModel();
- for (int i = 0; i < list.size(); i++) {
- ModelVo mv = new ModelVo();
- Model model = new Model();
- model = (Model) list.get(i);
- mv.setMod_CnName(model.getMod_CnName());
- mv.setMod_EnName(model.getMod_EnName());
- mv.setMod_ID(model.getMod_ID());
- mv.setMod_Order(model.getMod_Order());
- mv.setMod_Superior(model.getMod_Superior());
- mv.setMod_Url(model.getMod_Url());
- mv.setMod_Key(model.getMod_Key());
- ModelList.add(mv);
- }
- menuList = mes.GetMenuBySuperior(new Long(0), Language);
- ms.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("role", role);
- servletRequest.setAttribute("ModelList", ModelList);
- servletRequest.setAttribute("menuList", menuList);
- return actionMapping.findForward("OpenRole");
- }
- public ActionForward OpenRoleList(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List list = null;
- try {
- rs.beginTran();
- list = rs.GetAllRole();
- rs.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ms.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("list", list);
- return actionMapping.findForward("OpenRoleList");
- }
- public ActionForward DeleteRole(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Role role = new Role();
- boolean b = false;
- String Message = "";
- try {
- rs.beginTran();
- role = rs.GetRoleById
- (new Long(servletRequest.getParameter("roleID")));
- b = rs.DeleteRole(role);
- Message = "删除成功,请返回!";
- rs.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/Role.do?todo=OpenRoleList");
- return actionMapping.findForward("DeleteRole");
- }
- public ActionForward EditRole(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- RoleActionForm raf = (RoleActionForm) actionForm;
- Role role = new Role();
- String fmodel = "";
- String cmodel = "";
- boolean b = false;
- String Message = "";
- String menu = "";
- try {
- rs.beginTran();
- if (!raf.getId().equals(new Long(0))) {
- role = rs.GetRoleById(raf.getId());
- }
- String[] fmodels = servletRequest.getParameterValues("fmodel");
- for (int i = 0; i < fmodels.length; i++) {
- if (fmodel.equals("")) {
- fmodel = fmodels[i];
- } else {
- fmodel += "," + fmodels[i];
- }
- String[] cmodels = servletRequest.getParameterValues(fmodels[i]);
- for (int j = 0; j < cmodels.length; j++) {
- if (cmodel.equals("")) {
- cmodel = cmodels[j];
- } else {
- cmodel += "," + cmodels[j];
- }
- }
- }
- String[] menus = servletRequest.getParameterValues("menus");
- for (int i = 0; i < menus.length; i++) {
- if (menu.equals("")) {
- menu = menus[i];
- } else {
- menu += "," + menus[i];
- }
- }
- role.setRol_Menu(menu);
- role.setRol_CModel(cmodel);
- role.setRol_FModel(fmodel);
- role.setRol_Name(raf.getName());
- role.setRol_Time(new Date());
- if (raf.getId().equals(new Long(0))) {
- b = rs.AddRole(role);
- Message = "添加成功,请返回!";
- } else {
- b = rs.UpdateRole(role);
- Message = "更新成功,请返回!";
- }
- rs.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("Url", "/Manage/Role.do?todo=OpenRoleList");
- servletRequest.setAttribute("Message", Message);
- return actionMapping.findForward("EditRole");
- }
- }