Borrow.java~132~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:10k
- package com.action;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import com.actionForm.BorrowForm;
- import org.apache.struts.action.Action;
- import com.dao.BorrowDAO;
- import com.dao.ReaderDAO;
- import com.dao.BookDAO;
- import com.actionForm.ReaderForm;
- import com.actionForm.BookForm;
- public class Borrow extends Action {
- 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 perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- BorrowForm borrowForm = (BorrowForm) form;
- String action =request.getParameter("action");
- System.out.println("nborrow*********************action="+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("readerBorrowSort".equals(action)){
- return readerBorrowSort(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){
- return mapping.findForward("borrowQuery");
- }
- String aa=flag[0];
- if("a".equals(aa)){
- if(request.getParameter("f")!=null){
- str = request.getParameter("f") + " like '%" +
- request.getParameter("key") + "%'";
- }
- System.out.println("条件1111111111*"+str);
- }
- 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);
- /* for(int i=0;i<flag.length;i++){
- System.out.println(flag[i]+"sss"+flag.length);
- }*/
- }
- 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 readerBorrowSort(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response){
- request.setAttribute("readerBorrowSort",borrowDAO.readerBorrowSort());
- return mapping.findForward("readerBorrowSort");
- }
- /*********************图书借阅***********************/
- 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");
- }
- }