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

📄 materialmaintaintableservlet.java

📁 JSP移动商品管理平台源代码.........
💻 JAVA
字号:
package imis_mate.servlet;

import imis_mate.DAO.HousBuildingAndRoom;
import imis_mate.DAO.MaterialMaintainDAO;
import imis_mate.bean.MaterialChangeBean;
import imis_mate.bean.MaterialMaintainBean;

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

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

public class MaterialMaintainTableServlet extends HttpServlet {

	/**
	 * 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 {
		String pattern = request.getParameter("pattern");

		if(pattern.equals("insert")) {
			this.insertMaterialMaintain(request, response);
		}
//		else if(pattern.equals("search")) {
//			this.search(request, response);
//		}
		else if(pattern.equals("getMaterialMaintain")) {
			this.getMaterialMaintain(request, response);
		}else if(pattern.equals("modify")) {
			this.modify(request, response);
		}else if(pattern.equals("delete")) {
			this.delete(request, response); 
		}
		else if(pattern.equals("search")) {
			this.search(request, response); 
		} else if(pattern.equals("getValue")) {
			//刷新页面 传递值
			this.getVlaue(request, response);
		}
	}

	private void getVlaue(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 刷新页面 传递值
		String pag = request.getParameter("pag");
		String url = null;
		ArrayList list = null;
		HousBuildingAndRoom hbr = new HousBuildingAndRoom();
		//MaterialChangeBean mcb = new MaterialChangeBean();
		MaterialMaintainBean mmb = new MaterialMaintainBean();
		mmb.setMaintainID(request.getParameter("maintainID"));
		mmb.setMaterialName(request.getParameter("materialName"));
		mmb.setMaModel(request.getParameter("maModel"));
		mmb.setMaBrand(request.getParameter("maBrand"));
		mmb.setMaMadeIn(request.getParameter("maMadeIn"));
		mmb.setMaterialTypeNo(request.getParameter("materialTypeNo"));
		mmb.setMaintainCount(request.getParameter("maintainCount"));
		mmb.setMaintainDate(request.getParameter("maintainDate"));
		mmb.setUserCode(request.getParameter("userCode"));
		mmb.setMaintainDep(request.getParameter("maintainDep"));
		mmb.setManagerBy(request.getParameter("managerBy"));
		mmb.setUseBy(request.getParameter("useBy"));
		mmb.setRoomNu(request.getParameter("roomNu"));
		mmb.setBuildingNu(request.getParameter("buildingNu"));
		mmb.setMaintainCause(request.getParameter("maintainCause"));
		mmb.setMaintainFee(request.getParameter("maintainFee"));
		mmb.setReMark(request.getParameter("remark"));
		
		list = hbr.getRoomListForBuildingNu(mmb.getBuildingNu());
		
		if(pag.equals("insert")) {
			url = "../imis_mate/MaterialMaintainTable_insert.jsp";
		} else if(pag.equals("update")) {
			url = "../imis_mate/MaterialMaintainTable_modify.jsp";
		}
		request.setAttribute("mmb", mmb);
		request.setAttribute("roomList", list);
		request.getRequestDispatcher(url).forward(request, response);		
	}

	private void insertMaterialMaintain(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		boolean flag = false;
		MaterialMaintainBean mmb = new MaterialMaintainBean();
		mmb.setMaterialName(request.getParameter("materialName"));
		mmb.setMaModel(request.getParameter("maModel"));
		mmb.setMaBrand(request.getParameter("maBrand"));
		mmb.setMaMadeIn(request.getParameter("maMadeIn"));
		mmb.setMaterialTypeNo(request.getParameter("materialTypeNo"));
		
		mmb.setMaintainCount(request.getParameter("maintainCount"));
		mmb.setMaintainDate(request.getParameter("maintainDate"));
		mmb.setUserCode(request.getParameter("userCode"));
		mmb.setMaintainDep(request.getParameter("maintainDep"));
		mmb.setManagerBy(request.getParameter("managerBy"));
		mmb.setUseBy(request.getParameter("useBy"));
		mmb.setRoomNu(request.getParameter("roomNu"));
		mmb.setBuildingNu(request.getParameter("buildingNu"));
		mmb.setMaintainCause(request.getParameter("maintainCause"));
		mmb.setMaintainFee(request.getParameter("maintainFee"));
		mmb.setReMark(request.getParameter("remark"));
		
		MaterialMaintainDAO mmd = new MaterialMaintainDAO();
		if((request.getSession().getAttribute("new"))!=null){
			flag = mmd.save(mmb)?true:false;
			request.getSession().removeAttribute("new");
		}
		
		
		
		if(flag == true) {
			request.setAttribute("success", "维修信息录入成功!");
			request.getRequestDispatcher("../imis_mate/successful.jsp").forward(request, response);
		} else {
			request.setAttribute("fail", "维修信息录入失败");
			request.getRequestDispatcher("../imis_mate/fail.jsp").forward(request, response);
			}
		}

	/**
	 *
	
	 * 
	 * @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 getMaterialMaintain(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException{
		MaterialMaintainBean mmb = new MaterialMaintainBean();
		int  maintainID  = Integer.parseInt(request.getParameter("smaintainID"));
		
		MaterialMaintainDAO dao = new MaterialMaintainDAO();
		
		try {
			mmb = dao.getMaterialMaintainBeanOfMaintainID(maintainID);
		} catch (Exception e) {
			e.printStackTrace();
		}			
		
		if(mmb != null) {
			HousBuildingAndRoom hbr = new HousBuildingAndRoom();
			ArrayList list = hbr.getRoomListForBuildingNu(mmb.getBuildingNu());
			request.setAttribute("roomList", list);
			request.setAttribute("mmb", mmb);
		} else {
			request.setAttribute("MaterialMaintainBeanUnexisted", "该维修单不存在!" );
		}
		
		if(request.getParameter("page").equals("modify")) {
			request.getRequestDispatcher("./MaterialMaintainTable_modify.jsp").forward(request, response);
		} else if(request.getParameter("page").equals("delete")) {
			request.getRequestDispatcher("./MaterialMaintainTable_delete.jsp").forward(request, response);
		}
	}
	
	/**
	 *
	 * 
	 * 
	 * @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 modify(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException{
				
		boolean flag = false;
		MaterialMaintainBean mmb = new MaterialMaintainBean();
		int  maintainID  = Integer.parseInt(request.getParameter("maintainID"));
		
		MaterialMaintainDAO dao = new MaterialMaintainDAO();
		mmb.setMaintainID(maintainID);
		mmb.setMaterialName(request.getParameter("materialName"));
		mmb.setMaModel(request.getParameter("maModel"));
		mmb.setMaBrand(request.getParameter("maBrand"));
		mmb.setMaMadeIn(request.getParameter("maMadeIn"));
		mmb.setMaterialTypeNo(request.getParameter("materialTypeNo"));

		mmb.setMaintainCount(request.getParameter("maintainCount"));
		mmb.setMaintainDate(request.getParameter("maintainDate"));
		mmb.setUserCode(request.getParameter("userCode"));
		mmb.setMaintainDep(request.getParameter("maintainDep"));
		mmb.setManagerBy(request.getParameter("managerBy"));
		mmb.setUseBy(request.getParameter("useBy"));
		mmb.setRoomNu(request.getParameter("roomNu"));
		mmb.setBuildingNu(request.getParameter("buildingNu"));
		mmb.setMaintainCause(request.getParameter("maintainCause"));
		mmb.setMaintainFee(request.getParameter("maintainFee"));
		mmb.setReMark(request.getParameter("remark"));
		
				
		
		try {
			flag = dao.update(mmb);
		} catch (Exception e) {
			e.printStackTrace();
		}			
		
		if(flag == true) {
			request.setAttribute("success", "您已成功修改信息!");
			request.getRequestDispatcher("../imis_mate/successful.jsp").forward(request, response);
		} else {
			request.setAttribute("fail", "您的修改失败!");
			request.getRequestDispatcher("../imis_mate/fail.jsp").forward(request, response);
		}
	}
	

	/**
	 *
	 * 这个方法向表“ElecDev_Type”中删除数据
	 * 
	 * @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 delete(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException{
				
		boolean flag = false;
		
		int  maintainID  = Integer.parseInt(request.getParameter("maintainID").trim());
		
		
		MaterialMaintainDAO dao = new MaterialMaintainDAO();
		try {
			flag = dao.delete(maintainID);
		} catch (Exception e) {
			e.printStackTrace();
		}			
		
		if(flag == true) {
			request.setAttribute("success", "您已成功删除信息!");
			request.getRequestDispatcher("../imis_mate/successful.jsp").forward(request, response);
		} else {
			request.setAttribute("fail", "您的删除失败了!");
			request.getRequestDispatcher("../imis_mate/fail.jsp").forward(request, response);
		}

	}
	
	/**
	 *
	 *
	 * 
	 * @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 search(HttpServletRequest request, HttpServletResponse response) 
	throws ServletException, IOException{
	
	ArrayList list = new ArrayList();
	
	String materialName =  request.getParameter("materialName");
	String userCode = request.getParameter("userCode");
	String startDate = request.getParameter("startDate") ;
	String endDate = request.getParameter("endDate") ;
	String managerBy = request.getParameter("managerBy");
	String useBy= request.getParameter("useBy");
	
	MaterialMaintainDAO dao = new MaterialMaintainDAO();
	try {
		list = dao.searchMaterialMaintain(materialName, userCode, startDate, endDate, managerBy, useBy);
		
	} catch (Exception e) {
		e.printStackTrace();
	}			
	
	request.getSession().setAttribute("MaterialMaintainTableList", list);
	request.getRequestDispatcher("../imis_mate/MaterialMaintainTable_bysearch.jsp").forward(request, response);
}

	

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}
}

⌨️ 快捷键说明

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