本站消息

站长简介/公众号


站长简介:逗比程序员,理工宅男,前每日优鲜python全栈开发工程师,利用周末时间开发出本站,欢迎关注我的微信公众号:幽默盒子,一个专注于搞笑,分享快乐的公众号

  价值13000svip视频教程,java大神匠心打造,零基础java开发工程师视频教程全套,基础+进阶+项目实战,包含课件和源码

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2020-11(384)

2020-12(458)

2021-01(419)

2021-02(258)

2021-03(334)

练习——图书管理系统十四(借阅的还书)

发布于2021-06-12 13:57     阅读(961)     评论(0)     点赞(26)     收藏(2)


borrowinfolist.html

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

	<div name="action" width="120" headerAlign="center" align="center"
				renderer="onActionRenderer" cellStyle="padding:0;">操作按钮</div>
function onActionRenderer(e) {
			var record = e.record;
			var uid = record._uid;
			/* 如果图书尚未归还,展示“还书”按钮,点击后可以归还当前的图书,同时更新“借阅信息表”中的“归还时间”为当
			前时间(精确到秒)、更新“图书信息表”中剩余数量+1。(2)、如果图书已归还,则展示“删除”按钮,则点击后,可删
			除借阅信息。 */
			if(record.returnTime != undefined){
				return '<a class="mini-button" οnclick="del(\'' + uid
				+ '\')">删除</a>'
			}else{
				return '<a class="mini-button" οnclick="returnBook(\'' + uid
				+ '\')">还书</a>'
			}
		}
	//还书
		function returnBook(row_uid) {
			var row = grid.getRowByUID(row_uid);
			var json = mini.encode(row);
			mini.confirm("确定还书?", "确定?",
	            function (action) {
	                if (action == "ok") {
	                	$.ajax({
	    					url : "../../BorrowInfoAction?action=borrowInfoReturn",
	    					type : 'POST',
	    					data : {
	    						data : json
	    					},
	    					cache : false,
	    					success : function(text) {
	    						grid.reload();
	    						mini.showTips({
									content : text,
									state : 'success',
									x : 'center',
									y : 'top',
									timeout : 5000
								});
	    					},
	    					error : function() {
	    					}
	    				});
	                }
		    	});
			
		}

BorrowInfoAction.java

/**
	 * 还书
	 * @Description 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void borrowInfoReturn(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String borrowInfoStr = request.getParameter("data");
		BorrowInfo borrowInfo = JSONObject.parseObject(borrowInfoStr,BorrowInfo.class);
		
		borrowInfo.setReturnTime(new Timestamp(new Date().getTime()));
		
		int count = borrowInfoService.updateBorrowInfo(borrowInfo);
		if(-1 != count) {
			response.getWriter().print("还书成功");
		}else {
			response.getWriter().print("还书失败");
		}
		
	}

BorrowInfoService.java

/**
	 * 还书同时图书剩余数量加一
	 * @Description 
	 * @param bookInfo
	 * @return
	 */
	public int updateBorrowInfo(BorrowInfo borrowInfo) {
		return borrowInfoDao.updateBorrowInfo(borrowInfo);
	}

BorrowInfoDao.java

	/**
	 * 借阅图书并且修改图书数量
	 * @Description 
	 * @param borrowInfo
	 * @return
	 * @throws ParseException 
	 */
	public int addBorrowInfo(BorrowInfo borrowInfo) {
		Connection connection = JDBCUtil.getConnection();

		PreparedStatement pStatement = null;
		
		int count = -1;
		
		try {
			
			String sql = "insert into borrowinfo(borrowid,bookid,borrower,phone,borrowtime,returntime) values (?,?,?,?,?,?)";
			String bookSql = "update bookinfo set remain = remain-1 where bookid = ?";
			//开启事务
			connection.setAutoCommit(false);
			pStatement = connection.prepareStatement(sql);
			//填充占位符
			pStatement.setString(1, borrowInfo.getBorrowId());
			pStatement.setString(2, borrowInfo.getBookId());
			pStatement.setString(3, borrowInfo.getBorrower());
			pStatement.setString(4, borrowInfo.getPhone());
			pStatement.setTimestamp(5, new Timestamp(borrowInfo.getBorrowTime().getTime()));
			if(null != borrowInfo.getReturnTime()) {
				pStatement.setTimestamp(6, new Timestamp(borrowInfo.getReturnTime().getTime()));
			}else {
				pStatement.setDate(6, null);
			}
			
			count = pStatement.executeUpdate();
			
			pStatement = connection.prepareStatement(bookSql);
			pStatement.setString(1, borrowInfo.getBookId());
			count = pStatement.executeUpdate();
			//提交事务
			connection.commit();
			
		} catch (Exception e) {
			//回滚事务
			try {
				connection.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally {
			JDBCUtil.closeConnection(connection, pStatement, null);
		}
		
		return count;
	}

在这里插入图片描述

原文链接:https://blog.csdn.net/qq_45554909/article/details/117719826



所属网站分类: 技术文章 > 博客

作者:java战神

链接:http://www.javaheidong.com/blog/article/222338/07403832e7e755340d03/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

26 0
收藏该文
已收藏

评论内容:(最多支持255个字符)