AdminAction.java~56~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:9k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.actions.DispatchAction;
- import com.chinacannel.entity.Admin;
- import com.chinacannel.xlchemical.struts.ActionForm.AdminActionForm;
- import com.chinacannel.xlchemical.service.AdminService;
- import com.chinacannel.entity.Role;
- import com.chinacannel.xlchemical.service.RoleService;
- import com.chinacannel.common.PageInfo;
- import java.util.Date;
- import java.util.List;
- import java.io.IOException;
- import java.net.URLEncoder;
- public class AdminAction extends DispatchAction {
- AdminService as = new AdminService();
- public ActionForward CheckLogin(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- AdminActionForm aaf = (AdminActionForm) actionForm;
- Admin admin = null;
- try {
- as.beginTran();
- admin = as.CheckLogin(aaf.getUsername(), aaf.getPassword());
- as.commit();
- servletRequest.getSession().setAttribute("admin", admin);
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (admin != null) {
- return actionMapping.findForward("LoginOK");
- } else {
- servletRequest.setAttribute("Message", "登陆失败,请返回");
- servletRequest.setAttribute("Url", "Manage/Index.jsp");
- return actionMapping.findForward("LoginDefeat");
- }
- }
- public ActionForward AddNewAdmin(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Admin admin = new Admin();
- RoleService rs = new RoleService();
- Role role = null;
- AdminActionForm aaf = (AdminActionForm) actionForm;
- String Message = "";
- boolean b = false;
- try {
- as.beginTran();
- if (!aaf.getId().equals(new Long(0))) {
- admin = as.GetAdminById(aaf.getId());
- }
- admin.setAdm_Name(aaf.getName());
- role = rs.GetRoleById(aaf.getRole());
- admin.setRole(role);
- admin.setAdm_Pwd("123456");
- admin.setAdm_Time(new Date());
- if (aaf.getId().equals(new Long(0))) {
- b = as.AddAdmin(admin);
- Message = "添加新用户成功,默认密码为 123456 ,请返回!";
- } else {
- b = as.UpdateAdmin(admin);
- Message = "更新用户角色成功,请返回!";
- }
- as.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "操作失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "Manage/Admin.do?todo=OpenAdminList");
- return actionMapping.findForward("AddNewAdmin");
- }
- public ActionForward OpenAdminInfo(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- RoleService rs = new RoleService();
- Admin admin = new Admin();
- Long admID = new Long(0);
- List roleList = null;
- try {
- if (servletRequest.getParameter("AdmID") != null) {
- admID = new Long(servletRequest.getParameter("AdmID"));
- }
- rs.beginTran();
- if (!admID.equals(new Long(0))) {
- admin = as.GetAdminById(admID);
- }
- roleList = rs.GetAllRole();
- rs.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("roleList", roleList);
- servletRequest.setAttribute("admin", admin);
- return actionMapping.findForward("OpenAdminInfo");
- }
- public ActionForward OpenAdminList(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- int pageNo = 0;
- Role role = null;
- RoleService rs = new RoleService();
- AdminActionForm aaf = (AdminActionForm) actionForm;
- PageInfo pageInfo = null;
- String condition = "";
- List roleList = null;
- try {
- pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
- } catch (Exception ex1) {}
- try {
- if (aaf.getCondition().equals("")) {
- if (!aaf.getHidCondition().equals("")) {
- condition = aaf.getHidCondition();
- }
- } else {
- condition = aaf.getCondition();
- }
- as.beginTran();
- role = rs.GetRoleById(aaf.getRole());
- pageInfo = as.getPageInfo(condition, role, pageNo);
- roleList = rs.GetAllRole();
- as.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("roleList", roleList);
- servletRequest.setAttribute("role", role);
- servletRequest.setAttribute("pageInfo", pageInfo);
- return actionMapping.findForward("OpenAdminList");
- }
- public ActionForward DeleteAdmin(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Admin adm = new Admin();
- boolean b = false;
- String Message = "";
- try {
- as.beginTran();
- adm = as.GetAdminById(new Long(servletRequest.getParameter("AdmID")));
- b = as.DeleteAdmin(adm);
- Message = "删除成功,请返回!";
- as.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "Manage/Admin.do?todo=OpenAdminList");
- return actionMapping.findForward("DeleteAdmin");
- }
- public ActionForward UpdatePwd(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) throws
- IOException {
- AdminActionForm aaf = (AdminActionForm) actionForm;
- Admin admin = null;
- boolean b = false;
- try {
- if (servletRequest.getSession().getAttribute("admin") != null) {
- admin = (Admin) servletRequest.getSession().getAttribute(
- "admin");
- }
- if (admin.getAdm_Pwd().equals(aaf.getOldPwd())) {
- admin.setAdm_Pwd(aaf.getNewPwd1());
- as.beginTran();
- b = as.UpdateAdmin(admin);
- as.commit();
- }
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- as.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == true) {
- String message = "修改成功,请重新登陆";
- servletResponse.getWriter().write(
- "<script>alert('" + new String(message.getBytes("GBK"),"UTF-8") +
- "');parent.location='Index.jsp';</script>");
- }
- return null;
- }
- }