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