⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useraction.java

📁 该项目采用Struts框架
💻 JAVA
字号:
package com.cattsoft.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

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.cattsoft.DAOFactory.DAOFactory;
import com.cattsoft.vo.User;

public class UserAction extends DispatchAction {
	// 查询所有人员
	public ActionForward seeUser(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAll();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("seeUserSuccessed");
	}

	// 删除人员
	public ActionForward deleteUser(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String[] userId = request.getParameterValues("user_id");
		if (userId == null || userId.equals("")) {
			List<User> list = new ArrayList<User>();
			try {
				list = DAOFactory.getInstance().queryAll();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.setAttribute("list", list);
			request.setAttribute("error", "请选择要删除的人员");
			return mapping.findForward("deleteUserFailed");
		}
		for (int i = 0; i < userId.length; i++) {
			int user_id = Integer.parseInt(userId[i]);
			User user = new User();
			user.setUser_id(user_id);
			try {
				DAOFactory.getInstance().deleteUser(user_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAll();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("deleteUserSuccessed");
	}

	// 根据用户名查询对应人员的详细信息
	public ActionForward detailedUser(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String uname = request.getParameter("uname");
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAll(uname);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("detailedUserSuccessed");
	}

	// 查询所有员工
	public ActionForward seeEmployee(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAllEmployee();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (list == null || list.equals("")) {
			request.setAttribute("error","没有员工");
			return mapping.findForward("seeEmployeeFailed");			
		} else {
			request.setAttribute("list", list);
			return mapping.findForward("seeEmployeeSuccessed");
		}
	}
	
	// 删除员工
	public ActionForward deleteEmployee(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String[] userId = request.getParameterValues("user_id");
		if (userId == null || userId.equals("")) {
			request.setAttribute("error", "请选择要删除的员工");
			return mapping.findForward("deleteEmployeeFailed");
		}
		for (int i = 0; i < userId.length; i++) {
			int user_id = Integer.parseInt(userId[i]);
			User user = new User();
			user.setUser_id(user_id);
			try {
				DAOFactory.getInstance().deleteUser(user_id);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		List<User> list = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAllEmployee();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		return mapping.findForward("deleteEmployeeSuccessed");
	}
	
	//分配员工
	public ActionForward assignEmployee(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String uname =request.getParameter("username");
		List<User> list = new ArrayList<User>();
		List<User> list1 = new ArrayList<User>();
		try {
			list = DAOFactory.getInstance().queryAll(uname);
			list1 = DAOFactory.getInstance().queryAllManager();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
			request.setAttribute("list", list);
			request.setAttribute("list1", list1);
			return mapping.findForward("assignEmployeeSuccessed");
	}
	
	//分配完后改变员工信息
	public ActionForward assignEnd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int userId =Integer.parseInt(request.getParameter("user_id"));
		int managerId =Integer.parseInt(request.getParameter("manager_id"));
		String name = null;
		try {
			name = DAOFactory.getInstance().queryBy(managerId);
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		User user = new User();
		user.setManager_name(name);
		List<User> list = new ArrayList<User>();
		try {
			DAOFactory.getInstance().update(userId,managerId,user.getManager_name());
			list = DAOFactory.getInstance().queryAllEmployee();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list", list);
		request.setAttribute("info","分配成功");
		return mapping.findForward("assignEndSuccessed");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -