📄 elecuseinfo.java
字号:
} else {
request.setAttribute("fail", "信息录入失败!");
request.getRequestDispatcher(url).forward(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 search(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
ArrayList list = new ArrayList();
ElecUseInfoTO elecUseInfoTO = new ElecUseInfoTO();
elecUseInfoTO.setUseId(-1);
elecUseInfoTO.setElecMeterRegNo(request.getParameter("ElecMeterRegNo"));
elecUseInfoTO.setNowReading(0);
elecUseInfoTO.setElecMeterReading(0);
elecUseInfoTO.setReadOn("");
elecUseInfoTO.setXianLoss(0);
elecUseInfoTO.setBianLoss(0);
elecUseInfoTO.setTuiBu(0);
elecUseInfoTO.setSumElec(0);
elecUseInfoTO.setPriceUnit(0);
elecUseInfoTO.setReadDate(request.getParameter("StartDate"));
elecUseInfoTO.setReMark(0);
elecUseInfoTO.setMemo(request.getParameter("organidof"));
elecUseInfoTO.setUserId(request.getParameter("UserId"));
ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
try {
list = elecUseInfoDAO.searchElecUseInfos(elecUseInfoTO, request.getParameter("EndDate"));
} catch (Exception e) {
e.printStackTrace();
}
request.getSession().setAttribute("ElecUseInfoList", list);
request.getRequestDispatcher("../imis_elec/elecUseInfoBySearch.jsp").forward(request, response);
}
/**
*
* 这个方法向表“Elec_Use_Info”中得到信息,这个方法会被修改和删除页面调用,根据参数“page”来判断
* 是哪个页面。
*
* @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 getElecInfo(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
ElecUseInfoTO elecUseInfoTO = null;
String elecMeterRegNo = request.getParameter("ElecMeterRegNo");
String year = "";
String month = "";
if(request.getParameter("Year") != null) {
year = request.getParameter("Year");
}
if(request.getParameter("Month") != null) {
month = request.getParameter("Month");
}
ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
try {
if( !year.equals("") ) {
String date = year + "-" + month;
elecUseInfoTO = elecUseInfoDAO.getElecUseInfoByDate(elecMeterRegNo, date);
} else {
elecUseInfoTO = elecUseInfoDAO.getElecUseInfo(elecMeterRegNo, true);
}
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("ElecMeterRegNoUnexisted", "该电表编号的数据不存在!");
}
if(elecUseInfoTO != null) {
request.setAttribute("ElecUseInfo", elecUseInfoTO);
} else {
request.setAttribute("ElecMeterRegNoUnexisted", "该电表编号的数据不存在!");
}
if(request.getParameter("page").equals("modify")) {
request.getRequestDispatcher("../imis_elec/elecUseInfo_modify.jsp").forward(request, response);
} else if(request.getParameter("page").equals("delete")) {
request.getRequestDispatcher("../imis_elec/elecUseInfo_delete.jsp").forward(request, response);
} else if(request.getParameter("page").equals("insert")) {
request.getRequestDispatcher("../imis_elec/elecUseInfo_insert.jsp").forward(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 modify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
boolean flag = false;
TreeDemo demo = new TreeDemo();
String url = "../imis_elec/fail.jsp";
ElecUseInfoTO elecUseInfoTO = new ElecUseInfoTO();
elecUseInfoTO.setUseId(Integer.parseInt(request.getParameter("UseId").trim()));
elecUseInfoTO.setElecMeterRegNo(request.getParameter("ElecMeterRegNo"));
elecUseInfoTO.setNowReading(Double.parseDouble(request.getParameter("NowReading")));
elecUseInfoTO.setElecMeterReading(Double.parseDouble(request.getParameter("ElecMeterReading")));
elecUseInfoTO.setReadOn(request.getParameter("ReadOn"));
elecUseInfoTO.setXianLoss(Double.parseDouble(request.getParameter("XianLoss")));
elecUseInfoTO.setBianLoss(Double.parseDouble(request.getParameter("BianLoss")));
elecUseInfoTO.setTuiBu(Double.parseDouble(request.getParameter("TuiBu")));
double sumElec = (elecUseInfoTO.getNowReading() - elecUseInfoTO.getElecMeterReading()) * demo.getElecMulties(elecUseInfoTO.getElecMeterRegNo())
+ elecUseInfoTO.getXianLoss() + elecUseInfoTO.getBianLoss() + elecUseInfoTO.getTuiBu();
elecUseInfoTO.setSumElec(sumElec);
elecUseInfoTO.setPriceUnit(Double.parseDouble(request.getParameter("PriceUnit")));
elecUseInfoTO.setReadDate(request.getParameter("ReadDate").toString());
elecUseInfoTO.setReMark(0);
elecUseInfoTO.setMemo(request.getParameter("Memo"));
if(sumElec < 0) {
String message = "计费电量不能小于 0 !";
request.setAttribute("ErrorMessage", message);
elecUseInfoTO.setSumElec(Double.parseDouble(request.getParameter("SumElec")));
request.setAttribute("ElecUseInfo", elecUseInfoTO);
request.getRequestDispatcher("../imis_elec/elecUseInfo_modify.jsp").forward(request, response);
return;
}
ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
try {
flag = elecUseInfoDAO.updateElecUseInfo(elecUseInfoTO);
} catch (Exception e) {
e.printStackTrace();
}
if(flag == true) {
request.setAttribute("success", "您已成功修改信息!");
request.getRequestDispatcher("../imis_elec/successful.jsp").forward(request, response);
} else {
request.setAttribute("fail", "您的修改失败了!");
request.getRequestDispatcher(url).forward(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 delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
boolean flag = false;
String elecMeterRegNo = request.getParameter("ElecMeterRegNo");
ElecUseInfoDAOImpl elecUseInfoDAO = (ElecUseInfoDAOImpl) DAOFactory.getInstance().getElecUseInfoDAO();
try {
flag = elecUseInfoDAO.deleteElecUseInfo(Integer.parseInt(request.getParameter("UseId")));
} catch (Exception e) {
e.printStackTrace();
}
if(flag == true) {
request.setAttribute("success", "您已成功删除信息!");
request.getRequestDispatcher("../imis_elec/successful.jsp").forward(request, response);
} else {
request.setAttribute("fail", "您的删除失败了!");
request.getRequestDispatcher("../imis_elec/fail.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 + -