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

📄 sm_deptinfoservlet.java

📁 J2ee开发的 人事管理系统 使用oracle数据库 myeclips平台开发
💻 JAVA
字号:
package com.galaxy.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.galaxy.dao.DeptInfoDAO;
import com.galaxy.vo.DeptInfoVO;
import com.galaxy.vo.LevelInfoVO;
import com.galaxy.util.PageHelp;

public class SM_DeptInfoServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public SM_DeptInfoServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		response.setContentType("text/html");
		response.setCharacterEncoding("gb2312");
		request.setCharacterEncoding("gb2312");
		String opflag = request.getParameter("opflag");
		if("init".equals(opflag)){
			showlist(request,response);
		}
		else if("add".equals(opflag)){
			adddept(request,response);
		}
		else if("del".equals(opflag)){
			deldept(request,response);
		}
		else if("edit".equals(opflag)){
			editdept(request,response);
		}
		else if("combine".equals(opflag)){
			combinedept(request,response);
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}
	
	private void showlist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		int currentPage=1;//当前显示的页面号
		if(request.getParameter("currentPage")!=null&&!"".equals(request.getParameter("currentPage"))){
			currentPage=Integer.parseInt(request.getParameter("currentPage"));
		}
		PageHelp pagehelp=new PageHelp();
		DeptInfoDAO deptinfodao = new DeptInfoDAO();
		
		String deptname = request.getParameter("deptname");
		String deptmanager = request.getParameter("deptmanager");
		String deptstate = request.getParameter("depstate");
		String cond = " and di_state='可用' ";
		if(request.getParameter("cond")!=null && !"".equals(request.getParameter("cond")))
		{
			cond=request.getParameter("cond");	
		}
		if(deptname!=null && !"".equals(deptname)){
			cond += "and di_name like '%" + deptname + "%'";
		}
		if(deptmanager != null && !"".equals(deptmanager)){
			cond += "and di_manager like '%" + deptmanager + "%'";
		}

		if(deptstate !=null && !"0".equals(deptstate)){
			switch(Integer.parseInt(deptstate)){
			case(1):
				cond += "and di_state = '可用'";
				break;
			case(2):
				cond = "and di_state = '不可用'";
				break;
			case(3):
				cond = "and di_state = '被合并'";
				break;
			}
		}

		
		String jmpFlag = (String)request.getAttribute("jmpFlag");
		if("noCondition".equals(jmpFlag))
		{
			cond = " and di_state='可用' ";
		}

		int pageSize = 5;
		pagehelp=deptinfodao.getList(cond, pageSize, currentPage);
		request.setAttribute("pagehelp",pagehelp);
		request.getRequestDispatcher("sys_manage\\sys_dptmaintain_delete.jsp").forward(request, response);
	}
	
	private void adddept(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		DeptInfoVO deptinfovo = new DeptInfoVO();
		DeptInfoDAO deptinfodao = new DeptInfoDAO();
		LevelInfoVO levelinfovo = new LevelInfoVO();
		
		deptinfovo.setDiName(request.getParameter("deptname"));
		deptinfovo.setDiUp(Long.parseLong(request.getParameter("updept")));
		deptinfovo.setDiManager(request.getParameter("managername"));
		deptinfovo.setDiNumber(Long.parseLong(request.getParameter("numb")));
		deptinfovo.setDiExtend("");
		
		String state = request.getParameter("state");
		if("1".equals(state))
			deptinfovo.setDiState("可用");
		else
			deptinfovo.setDiState("不可用");
		
		levelinfovo.setLiId(Long.parseLong(request.getParameter("deptlevel")));
		deptinfovo.setLevelInfo(levelinfovo);
		
		int i = 0;
		i = deptinfodao.addObject(deptinfovo);
		if(i !=0 )
		{
			request.setAttribute("jmpFlag", "noCondition");
			request.getRequestDispatcher("SM_DeptInfoServlet?opflag=init").forward(request, response);
		}
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
	
	private void deldept(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String deptinfo[] = request.getParameterValues("checkbox");
		DeptInfoDAO deptinfodao = new DeptInfoDAO();
		int j = 0;
		for(int i = 0; i < deptinfo.length; i++)
		{
			DeptInfoVO deptvo = new DeptInfoVO();
			String cond = " and d.di_id="+deptinfo[i];
			List list = deptinfodao.queryByCondition(cond);
			deptvo = (DeptInfoVO)list.get(0);
			deptvo.setDiState("不可用");
			j = deptinfodao.updateObject(deptvo);
		}
		
		if(j !=0 )
		{
			request.setAttribute("jmpFlag", "noCondition");
			request.getRequestDispatcher("SM_DeptInfoServlet?opflag=init").forward(request, response);
		}
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
	
	private void editdept(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		DeptInfoVO deptinfovo = new DeptInfoVO();
		DeptInfoDAO deptinfodao = new DeptInfoDAO();
		deptinfovo.setDiId(Long.parseLong(request.getParameter("deptid")));
		deptinfovo.setDiName(request.getParameter("deptname"));
		deptinfovo.setDiManager(request.getParameter("managername"));
		deptinfovo.setDiUp(Long.parseLong(request.getParameter("updept")));
		deptinfovo.setDiNumber(Long.parseLong(request.getParameter("numb")));
		deptinfovo.setDiExtend("");
		String state = request.getParameter("state");
		if("1".equals(state))
			deptinfovo.setDiState("可用");
		else if("0".equals(state))
			deptinfovo.setDiState("不可用");
		else if("2".equals(state))
			deptinfovo.setDiState("被合并");
		
		LevelInfoVO levelinfovo = new LevelInfoVO();
		levelinfovo.setLiId(Long.parseLong(request.getParameter("deptlevel")));
		deptinfovo.setLevelInfo(levelinfovo);
		int i = 0;
		i = deptinfodao.updateObject(deptinfovo);
		if(i !=0 )
		{
			request.setAttribute("jmpFlag", "noCondition");
			request.getRequestDispatcher("SM_DeptInfoServlet?opflag=init").forward(request, response);
		}
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
	
	private void combinedept(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String deptsid = request.getParameter("deptsid");
		DeptInfoVO deptinfovo = new DeptInfoVO();
		DeptInfoDAO deptdao = new DeptInfoDAO();

		deptinfovo.setDiName(request.getParameter("deptname"));
		deptinfovo.setDiManager(request.getParameter("managername"));
		deptinfovo.setDiUp(Long.parseLong(request.getParameter("updept")));
		deptinfovo.setDiExtend("");
		String state = request.getParameter("state");
		if("1".equals(state))
			deptinfovo.setDiState("可用");
		else
			deptinfovo.setDiState("不可用");
		
		LevelInfoVO levelinfovo = new LevelInfoVO();
		levelinfovo.setLiId(Long.parseLong(request.getParameter("deptlevel")));
		deptinfovo.setLevelInfo(levelinfovo);
		
		int i = 0;
		i = deptdao.combine(deptsid, deptinfovo);
		if(i !=0 )
		{
			request.setAttribute("jmpFlag", "noCondition");
			request.getRequestDispatcher("SM_DeptInfoServlet?opflag=init").forward(request, response);
		}
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
}












⌨️ 快捷键说明

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