Borrow.java
上传用户:ycdfsj258
上传日期:2022-08-04
资源大小:1094k
文件大小:10k
源码类别:

图形图象

开发平台:

Java

  1. package com.action;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import com.actionForm.BorrowForm;
  8. import org.apache.struts.action.Action;
  9. import com.dao.BorrowDAO;
  10. import com.dao.ReaderDAO;
  11. import com.dao.BookDAO;
  12. import com.actionForm.ReaderForm;
  13. import com.actionForm.BookForm;
  14. public class Borrow extends Action {
  15.     private BorrowDAO borrowDAO = null;
  16.     private ReaderDAO readerDAO=null;
  17.     private BookDAO bookDAO=null;
  18.     private ReaderForm readerForm=new ReaderForm();
  19.    public Borrow() {
  20.        this.borrowDAO = new BorrowDAO();
  21.        this.readerDAO=new ReaderDAO();
  22.        this.bookDAO=new BookDAO();
  23.    }
  24.     public ActionForward perform(ActionMapping mapping, ActionForm form,
  25.                                  HttpServletRequest request,
  26.                                  HttpServletResponse response) {
  27.         BorrowForm borrowForm = (BorrowForm) form;
  28.         String action =request.getParameter("action");
  29.         System.out.println("nborrow*********************action="+action);
  30.         if(action==null||"".equals(action)){
  31.             request.setAttribute("error","您的操作有误!");
  32.             return mapping.findForward("error");
  33.         }else if("bookBorrowSort".equals(action)){
  34.             return bookBorrowSort(mapping,form,request,response);
  35.         }else if("readerBorrowSort".equals(action)){
  36.             return readerBorrowSort(mapping,form,request,response);
  37.         }else if("bookborrow".equals(action)){
  38.             return bookborrow(mapping,form,request,response);
  39.         }else if("bookrenew".equals(action)){
  40.             return bookrenew(mapping,form,request,response);
  41.         }else if("bookback".equals(action)){
  42.             return bookback(mapping,form,request,response);
  43.         }else if("Bremind".equals(action)){
  44.             return bremind(mapping,form,request,response);
  45.         }else if("borrowQuery".equals(action)){
  46.             return borrowQuery(mapping,form,request,response);
  47.         }
  48.         request.setAttribute("error","操作失败!");
  49.         return mapping.findForward("error");
  50.     }
  51.     /*********************图书借阅排行***********************/
  52.     private ActionForward bookBorrowSort(ActionMapping mapping, ActionForm form,
  53.                                  HttpServletRequest request,
  54.                                  HttpServletResponse response){
  55.         request.setAttribute("bookBorrowSort",borrowDAO.bookBorrowSort());
  56.         return mapping.findForward("bookBorrowSort");
  57.     }
  58.  /*********************图书借阅查询***********************/
  59.     private ActionForward borrowQuery(ActionMapping mapping, ActionForm form,
  60.                                  HttpServletRequest request,
  61.                                  HttpServletResponse response){
  62.         String str=null;
  63.         String flag[]=request.getParameterValues("flag");
  64.         if (flag!=null){
  65.             String aa = flag[0];
  66.             if ("a".equals(aa)) {
  67.                 if (request.getParameter("f") != null) {
  68.                     str = request.getParameter("f") + " like '%" +
  69.                           request.getParameter("key") + "%'";
  70.                 }
  71.             }
  72.             if ("b".equals(aa)) {
  73.                 String sdate = request.getParameter("sdate");
  74.                 String edate = request.getParameter("edate");
  75.                 if (sdate != null && edate != null) {
  76.                     str = "borrowTime between '" + sdate + "' and '" + edate +
  77.                           "'";
  78.                 }
  79.                 System.out.println("日期" + str);
  80.             }
  81.             //同时选择日期和条件进行查询
  82.             if (flag.length == 2) {
  83.                 if (request.getParameter("f") != null) {
  84.                     str = request.getParameter("f") + " like '%" +
  85.                           request.getParameter("key") + "%'";
  86.                 }
  87.                 System.out.println("日期和条件");
  88.                 String sdate = request.getParameter("sdate");
  89.                 String edate = request.getParameter("edate");
  90.                 String str1 = null;
  91.                 if (sdate != null && edate != null) {
  92.                     str1 = "borrowTime between '" + sdate + "' and '" + edate +
  93.                            "'";
  94.                 }
  95.                 str = str + " and borr." + str1;
  96.                 System.out.println("条件和日期:" + str);
  97.             }
  98.         }
  99.         request.setAttribute("borrowQuery",borrowDAO.borrowQuery(str));
  100.        System.out.print("条件查询图书借阅信息时的str:"+str);
  101.         return mapping.findForward("borrowQuery");
  102.     }
  103.     /*********************到期提醒***********************/
  104.     private ActionForward bremind(ActionMapping mapping, ActionForm form,
  105.                                  HttpServletRequest request,
  106.                                  HttpServletResponse response){
  107.         request.setAttribute("Bremind",borrowDAO.bremind());
  108.         return mapping.findForward("Bremind");
  109.     }
  110.      /*********************读者借阅排行***********************/
  111.     private ActionForward readerBorrowSort(ActionMapping mapping, ActionForm form,
  112.                                  HttpServletRequest request,
  113.                                  HttpServletResponse response){
  114.         request.setAttribute("readerBorrowSort",borrowDAO.readerBorrowSort());
  115.         return mapping.findForward("readerBorrowSort");
  116.     }
  117.     /*********************图书借阅***********************/
  118.     private ActionForward bookborrow(ActionMapping mapping, ActionForm form,
  119.                                  HttpServletRequest request,
  120.                                  HttpServletResponse response){
  121.         //查询读者信息
  122.         //ReaderForm readerForm=(ReaderForm)form;  //此处一定不能使用该语句进行转换
  123.         readerForm.setBarcode(request.getParameter("barcode"));
  124.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  125.         request.setAttribute("readerinfo", reader);
  126.         //查询读者的借阅信息
  127.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  128.         //完成借阅
  129.         String f = request.getParameter("f");
  130.         String key = request.getParameter("inputkey");
  131.         if (key != null && !key.equals("")) {
  132.             String operator = request.getParameter("operator");
  133.             BookForm bookForm=bookDAO.queryB(f, key);
  134.             if (bookForm!=null){
  135.                 int ret = borrowDAO.insertBorrow(reader, bookDAO.queryB(f, key),
  136.                                                  operator);
  137.                 if (ret == 1) {
  138.                     request.setAttribute("bar", request.getParameter("barcode"));
  139.                     return mapping.findForward("bookborrowok");
  140.                 } else {
  141.                     request.setAttribute("error", "添加借阅信息失败!");
  142.                     return mapping.findForward("error");
  143.                 }
  144.             }else{
  145.                 request.setAttribute("error", "没有该图书!");
  146.                 return mapping.findForward("error");
  147.             }
  148.         }
  149.         return mapping.findForward("bookborrow");
  150.     }
  151.     /*********************图书继借***********************/
  152.     private ActionForward bookrenew(ActionMapping mapping, ActionForm form,
  153.                                  HttpServletRequest request,
  154.                                  HttpServletResponse response){
  155.         //查询读者信息
  156.         readerForm.setBarcode(request.getParameter("barcode"));
  157.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  158.         request.setAttribute("readerinfo", reader);
  159.         //查询读者的借阅信息
  160.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  161.          if(request.getParameter("id")!=null){
  162.              int id = Integer.parseInt(request.getParameter("id"));
  163.              if (id > 0) { //执行继借操作
  164.                  int ret = borrowDAO.renew(id);
  165.                  if (ret == 0) {
  166.                      request.setAttribute("error", "图书继借失败!");
  167.                      return mapping.findForward("error");
  168.                  } else {
  169.                      request.setAttribute("bar", request.getParameter("barcode"));
  170.                      return mapping.findForward("bookrenewok");
  171.                  }
  172.              }
  173.          }
  174.         return mapping.findForward("bookrenew");
  175.     }
  176.     /*********************图书归还***********************/
  177.     private ActionForward bookback(ActionMapping mapping, ActionForm form,
  178.                                  HttpServletRequest request,
  179.                                  HttpServletResponse response){
  180.         //查询读者信息
  181.         readerForm.setBarcode(request.getParameter("barcode"));
  182.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  183.         request.setAttribute("readerinfo", reader);
  184.         //查询读者的借阅信息
  185.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  186.          if(request.getParameter("id")!=null){
  187.              int id = Integer.parseInt(request.getParameter("id"));
  188.              String operator=request.getParameter("operator");
  189.              if (id > 0) { //执行归还操作
  190.                  int ret = borrowDAO.back(id,operator);
  191.                  if (ret == 0) {
  192.                      request.setAttribute("error", "图书归还失败!");
  193.                      return mapping.findForward("error");
  194.                  } else {
  195.                      request.setAttribute("bar", request.getParameter("barcode"));
  196.                      return mapping.findForward("bookbackok");
  197.                  }
  198.              }
  199.          }
  200.         return mapping.findForward("bookback");
  201.     }
  202. }