package com.action; import org.apache.struts.action.*; import javax.servlet.http.*; import com.dao.*; import com.actionForm.*; public class Borrow extends Action { /******************在构造方法中实例化Borrow类中应用的持久层类的对象**************************/ private BorrowDAO borrowDAO = null; private ReaderDAO readerDAO=null; private BookDAO bookDAO=null; private ReaderForm readerForm=new ReaderForm(); public Borrow() { this.borrowDAO = new BorrowDAO(); this.readerDAO=new ReaderDAO(); this.bookDAO=new BookDAO(); } /******************************************************************************************/ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { BorrowForm borrowForm = (BorrowForm) form; String action =request.getParameter("action"); if(action==null||"".equals(action)){ request.setAttribute("error","您的操作有误!"); return mapping.findForward("error"); }else if("bookBorrowSort".equals(action)){ return bookBorrowSort(mapping,form,request,response); }else if("bookborrow".equals(action)){ return bookborrow(mapping,form,request,response); //图书借阅 }else if("bookrenew".equals(action)){ return bookrenew(mapping,form,request,response); //图书续借 }else if("bookback".equals(action)){ return bookback(mapping,form,request,response); //图书归还 }else if("Bremind".equals(action)){ return bremind(mapping,form,request,response); //借阅到期提醒 }else if("borrowQuery".equals(action)){ return borrowQuery(mapping,form,request,response); //借阅信息查询 } request.setAttribute("error","操作失败!"); return mapping.findForward("error"); } /*********************图书借阅排行***********************/ private ActionForward bookBorrowSort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ request.setAttribute("bookBorrowSort",borrowDAO.bookBorrowSort()); return mapping.findForward("bookBorrowSort"); } /*********************图书借阅查询***********************/ private ActionForward borrowQuery(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ String str=null; String flag[]=request.getParameterValues("flag"); if (flag!=null){ String aa = flag[0]; if ("a".equals(aa)) { if (request.getParameter("f") != null) { str = request.getParameter("f") + " like '%" + request.getParameter("key") + "%'"; } } if ("b".equals(aa)) { String sdate = request.getParameter("sdate"); String edate = request.getParameter("edate"); if (sdate != null && edate != null) { str = "borrowTime between '" + sdate + "' and '" + edate + "'"; } System.out.println("日期" + str); } //同时选择日期和条件进行查询 if (flag.length == 2) { if (request.getParameter("f") != null) { str = request.getParameter("f") + " like '%" + request.getParameter("key") + "%'"; } System.out.println("日期和条件"); String sdate = request.getParameter("sdate"); String edate = request.getParameter("edate"); String str1 = null; if (sdate != null && edate != null) { str1 = "borrowTime between '" + sdate + "' and '" + edate + "'"; } str = str + " and borr." + str1; System.out.println("条件和日期:" + str); } } request.setAttribute("borrowQuery",borrowDAO.borrowQuery(str)); System.out.print("条件查询图书借阅信息时的str:"+str); return mapping.findForward("borrowQuery"); } /*********************到期提醒***********************/ private ActionForward bremind(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ request.setAttribute("Bremind",borrowDAO.bremind()); return mapping.findForward("Bremind"); } /*********************图书借阅***********************/ private ActionForward bookborrow(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ //查询读者信息 //ReaderForm readerForm=(ReaderForm)form; //此处一定不能使用该语句进行转换 readerForm.setBarcode(request.getParameter("barcode")); ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm); request.setAttribute("readerinfo", reader); //查询读者的借阅信息 request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode"))); //完成借阅 String f = request.getParameter("f"); String key = request.getParameter("inputkey"); if (key != null && !key.equals("")) { String operator = request.getParameter("operator"); BookForm bookForm=bookDAO.queryB(f, key); if (bookForm!=null){ int ret = borrowDAO.insertBorrow(reader, bookDAO.queryB(f, key), operator); if (ret == 1) { request.setAttribute("bar", request.getParameter("barcode")); return mapping.findForward("bookborrowok"); } else { request.setAttribute("error", "添加借阅信息失败!"); return mapping.findForward("error"); } }else{ request.setAttribute("error", "没有该图书!"); return mapping.findForward("error"); } } return mapping.findForward("bookborrow"); } /*********************图书继借***********************/ private ActionForward bookrenew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ //查询读者信息 readerForm.setBarcode(request.getParameter("barcode")); ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm); request.setAttribute("readerinfo", reader); //查询读者的借阅信息 request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode"))); if(request.getParameter("id")!=null){ int id = Integer.parseInt(request.getParameter("id")); if (id > 0) { //执行继借操作 int ret = borrowDAO.renew(id); if (ret == 0) { request.setAttribute("error", "图书继借失败!"); return mapping.findForward("error"); } else { request.setAttribute("bar", request.getParameter("barcode")); return mapping.findForward("bookrenewok"); } } } return mapping.findForward("bookrenew"); } /*********************图书归还***********************/ private ActionForward bookback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ //查询读者信息 readerForm.setBarcode(request.getParameter("barcode")); ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm); request.setAttribute("readerinfo", reader); //查询读者的借阅信息 request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode"))); if(request.getParameter("id")!=null){ int id = Integer.parseInt(request.getParameter("id")); String operator=request.getParameter("operator"); if (id > 0) { //执行归还操作 int ret = borrowDAO.back(id,operator); if (ret == 0) { request.setAttribute("error", "图书归还失败!"); return mapping.findForward("error"); } else { request.setAttribute("bar", request.getParameter("barcode")); return mapping.findForward("bookbackok"); } } } return mapping.findForward("bookback"); } }
最近下载更多
卑微大学生在线学java LV1
6月30日
柳咪华沙 LV7
6月28日
RAINK_L LV3
2023年12月12日
hfkdny LV2
2023年6月6日
dmyafda LV5
2023年3月26日
想飞的大肥猪 LV9
2023年3月10日
微信网友_5925912300212224 LV1
2023年1月29日
微信网友_6254095067451392 LV3
2022年12月9日
askjhfasf LV1
2022年11月5日
ARTICLE LV3
2022年10月28日
最近浏览更多
xiao peppa
11月10日
暂无贡献等级
微信网友_7225075969921024
10月25日
暂无贡献等级
252537406
10月25日
暂无贡献等级
1220261962d
10月15日
暂无贡献等级
krispeng LV13
10月2日
微信网友_7161495321989120 LV1
9月10日
dsczs666
8月18日
暂无贡献等级
暂无贡献等级
54ty1212
8月6日
暂无贡献等级
小小小小白
7月15日
暂无贡献等级