Borrow.java~134~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:10k
源码类别:

Jsp/Servlet

开发平台:

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.                 System.out.println("条件1111111111*" + str);
  72.             }
  73.             if ("b".equals(aa)) {
  74.                 String sdate = request.getParameter("sdate");
  75.                 String edate = request.getParameter("edate");
  76.                 if (sdate != null && edate != null) {
  77.                     str = "borrowTime between '" + sdate + "' and '" + edate +
  78.                           "'";
  79.                 }
  80.                 System.out.println("日期" + str);
  81.             }
  82.             //同时选择日期和条件进行查询
  83.             if (flag.length == 2) {
  84.                 if (request.getParameter("f") != null) {
  85.                     str = request.getParameter("f") + " like '%" +
  86.                           request.getParameter("key") + "%'";
  87.                 }
  88.                 System.out.println("日期和条件");
  89.                 String sdate = request.getParameter("sdate");
  90.                 String edate = request.getParameter("edate");
  91.                 String str1 = null;
  92.                 if (sdate != null && edate != null) {
  93.                     str1 = "borrowTime between '" + sdate + "' and '" + edate +
  94.                            "'";
  95.                 }
  96.                 str = str + " and borr." + str1;
  97.                 System.out.println("条件和日期:" + str);
  98.             }
  99.         }
  100.         request.setAttribute("borrowQuery",borrowDAO.borrowQuery(str));
  101.        System.out.print("条件查询图书借阅信息时的str:"+str);
  102.         return mapping.findForward("borrowQuery");
  103.     }
  104.     /*********************到期提醒***********************/
  105.     private ActionForward bremind(ActionMapping mapping, ActionForm form,
  106.                                  HttpServletRequest request,
  107.                                  HttpServletResponse response){
  108.         request.setAttribute("Bremind",borrowDAO.bremind());
  109.         return mapping.findForward("Bremind");
  110.     }
  111.      /*********************读者借阅排行***********************/
  112.     private ActionForward readerBorrowSort(ActionMapping mapping, ActionForm form,
  113.                                  HttpServletRequest request,
  114.                                  HttpServletResponse response){
  115.         request.setAttribute("readerBorrowSort",borrowDAO.readerBorrowSort());
  116.         return mapping.findForward("readerBorrowSort");
  117.     }
  118.     /*********************图书借阅***********************/
  119.     private ActionForward bookborrow(ActionMapping mapping, ActionForm form,
  120.                                  HttpServletRequest request,
  121.                                  HttpServletResponse response){
  122.         //查询读者信息
  123.         //ReaderForm readerForm=(ReaderForm)form;  //此处一定不能使用该语句进行转换
  124.         readerForm.setBarcode(request.getParameter("barcode"));
  125.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  126.         request.setAttribute("readerinfo", reader);
  127.         //查询读者的借阅信息
  128.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  129.         //完成借阅
  130.         String f = request.getParameter("f");
  131.         String key = request.getParameter("inputkey");
  132.         if (key != null && !key.equals("")) {
  133.             String operator = request.getParameter("operator");
  134.             BookForm bookForm=bookDAO.queryB(f, key);
  135.             if (bookForm!=null){
  136.                 int ret = borrowDAO.insertBorrow(reader, bookDAO.queryB(f, key),
  137.                                                  operator);
  138.                 if (ret == 1) {
  139.                     request.setAttribute("bar", request.getParameter("barcode"));
  140.                     return mapping.findForward("bookborrowok");
  141.                 } else {
  142.                     request.setAttribute("error", "添加借阅信息失败!");
  143.                     return mapping.findForward("error");
  144.                 }
  145.             }else{
  146.                 request.setAttribute("error", "没有该图书!");
  147.                 return mapping.findForward("error");
  148.             }
  149.         }
  150.         return mapping.findForward("bookborrow");
  151.     }
  152.     /*********************图书继借***********************/
  153.     private ActionForward bookrenew(ActionMapping mapping, ActionForm form,
  154.                                  HttpServletRequest request,
  155.                                  HttpServletResponse response){
  156.         //查询读者信息
  157.         readerForm.setBarcode(request.getParameter("barcode"));
  158.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  159.         request.setAttribute("readerinfo", reader);
  160.         //查询读者的借阅信息
  161.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  162.          if(request.getParameter("id")!=null){
  163.              int id = Integer.parseInt(request.getParameter("id"));
  164.              if (id > 0) { //执行继借操作
  165.                  int ret = borrowDAO.renew(id);
  166.                  if (ret == 0) {
  167.                      request.setAttribute("error", "图书继借失败!");
  168.                      return mapping.findForward("error");
  169.                  } else {
  170.                      request.setAttribute("bar", request.getParameter("barcode"));
  171.                      return mapping.findForward("bookrenewok");
  172.                  }
  173.              }
  174.          }
  175.         return mapping.findForward("bookrenew");
  176.     }
  177.     /*********************图书归还***********************/
  178.     private ActionForward bookback(ActionMapping mapping, ActionForm form,
  179.                                  HttpServletRequest request,
  180.                                  HttpServletResponse response){
  181.         //查询读者信息
  182.         readerForm.setBarcode(request.getParameter("barcode"));
  183.         ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm);
  184.         request.setAttribute("readerinfo", reader);
  185.         //查询读者的借阅信息
  186.         request.setAttribute("borrowinfo",borrowDAO.borrowinfo(request.getParameter("barcode")));
  187.          if(request.getParameter("id")!=null){
  188.              int id = Integer.parseInt(request.getParameter("id"));
  189.              String operator=request.getParameter("operator");
  190.              if (id > 0) { //执行继借操作
  191.                  int ret = borrowDAO.back(id,operator);
  192.                  if (ret == 0) {
  193.                      request.setAttribute("error", "图书归还失败!");
  194.                      return mapping.findForward("error");
  195.                  } else {
  196.                      request.setAttribute("bar", request.getParameter("barcode"));
  197.                      return mapping.findForward("bookbackok");
  198.                  }
  199.              }
  200.          }
  201.         return mapping.findForward("bookback");
  202.     }
  203. }