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

📄 elecuseinfo.java

📁 JSP移动商品管理平台源代码.........
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package imis_elec;

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 ElecUseInfo extends HttpServlet {

	/**
	 * 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 {

		this.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.insert(request, response);
		}else if(pattern.equals("search")) {
			this.search(request, response);
		}else if(pattern.equals("getElecUseInfo")) {
			this.getElecInfo(request, response);
		}else if(pattern.equals("modify")) {
			this.modify(request, response);
		}else if(pattern.equals("delete")) {
			this.delete(request, response);
		}
	}
		
	/**
	 *
	 * 这个方法向表“Elec_Use_Info”中插入数据
	 * 
	 * @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 insert(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException{
		
		boolean flag = false;
		String url = "../imis_elec/fail.jsp";
		TreeDemo demo = new TreeDemo();
		String message = "";
//		try {			
//			System.out.println(request.getSession().getAttribute("length").toString());
//		int length = Integer.parseInt(request.getSession().getAttribute("length").toString());
//		for(int i = 0; i < length; i++) {
//			System.out.println(request.getParameter("ElecMeterRegNo" + i));			
//		}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
			
		try {
			int length = Integer.parseInt(request.getSession().getAttribute("length").toString());
			ElecUseInfoTO[] elec = new ElecUseInfoTO[length];
			
			for(int i = 0; i < length; i++) {				
				String elecMeterRegNo = request.getParameter("ElecMeterRegNo" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkElecMeterRegNo(elecMeterRegNo);
				if(!ElecUseInfoCheck.check) {
					break;					
				}

				String nowReading = request.getParameter("NowReading" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkNowReading(nowReading);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String elecMeterReading = request.getParameter("ElecMeterReading" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkElecMeterReading(elecMeterReading);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String readOn = request.getParameter("ReadOn").trim();
				
				String xianLoss = request.getParameter("XianLoss" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkXianLoss(xianLoss);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String bianLoss = request.getParameter("BianLoss" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkBianLoss(bianLoss);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String tuiBu = request.getParameter("TuiBu" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkTuiBu(tuiBu);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String priceUnit = request.getParameter("PriceUnit" + i).trim();
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkPriceUnit(priceUnit);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				String memo = request.getParameter("Memo");
				message = "电表编号为 " + elecMeterRegNo + " 的" + ElecUseInfoCheck.checkMemo(memo);
				if(!ElecUseInfoCheck.check) {
					break;
				}
				
				elec[i] = new ElecUseInfoTO();
				elec[i].setUseId(-1);
				elec[i].setElecMeterRegNo(elecMeterRegNo);
				elec[i].setNowReading(Double.parseDouble(nowReading));
				elec[i].setElecMeterReading(Double.parseDouble(elecMeterReading));
				elec[i].setReadOn(readOn);
				elec[i].setXianLoss(Double.parseDouble(xianLoss));
				elec[i].setBianLoss(Double.parseDouble(bianLoss));
				elec[i].setTuiBu(Double.parseDouble(tuiBu));
				double sumElec = (elec[i].getNowReading() - elec[i].getElecMeterReading()) * demo.getElecMulties(elec[i].getElecMeterRegNo()) 
									+ elec[i].getXianLoss() + elec[i].getBianLoss() + elec[i].getTuiBu();
				elec[i].setSumElec(sumElec);
				elec[i].setPriceUnit(Double.parseDouble(priceUnit));
				elec[i].setReadDate(request.getParameter("ReadDate").toString());
				//elecUseInfoTO.setReMark(Integer.parseInt(request.getParameter("ReMark")));
				elec[i].setReMark(0);
				elec[i].setMemo(memo);
				
				if(sumElec < 0) {
					message = "电表编号为 " + elecMeterRegNo + " 的计费电量不能小于 0 !";
					ElecUseInfoCheck.check = false;
					break;
				}
			}
			
			if(ElecUseInfoCheck.check) {
				ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
				for(int i = 0; i < length; i++) {			
					boolean b = elecUseInfoDAO.getElecUseInfo(elec[i].getElecMeterRegNo(), elec[i].getReadDate());
					if(b) {
						message = "电表编号为 " + elec[i].getElecMeterRegNo() + " 的" + "该月份的数据已存在";
						ElecUseInfoCheck.check = false;
						break;
					}
				}
			}
			
			if(ElecUseInfoCheck.check) {
				ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
				for(int i = 0; i < length; i++) {			
						flag = elecUseInfoDAO.insertElecUseInfo(elec[i]);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}			
		
		if(!ElecUseInfoCheck.check) {
			ElecUseInfoCheck.setCheck();
			request.removeAttribute("ErrorMessage");
			request.setAttribute("ErrorMessage", message);
			String userId = request.getSession().getAttribute("UserId").toString();
			String href = "../imis_elec/elecUseInfo_insert.jsp?UserId=" + userId;
			request.getSession().removeAttribute("UserId");
			request.getSession().removeAttribute("ErrorMessage");
			request.getRequestDispatcher(href).forward(request, response);
		} else if(flag == true) {
			request.setAttribute("success", "信息录入成功!");
			request.getRequestDispatcher("../imis_elec/successful.jsp").forward(request, response);

⌨️ 快捷键说明

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