发布于2021-06-12 13:57 阅读(974) 评论(0) 点赞(26) 收藏(2)
<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() {
}
});
}
});
}
/**
* 还书
* @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("还书失败");
}
}
/**
* 还书同时图书剩余数量加一
* @Description
* @param bookInfo
* @return
*/
public int updateBorrowInfo(BorrowInfo borrowInfo) {
return borrowInfoDao.updateBorrowInfo(borrowInfo);
}
/**
* 借阅图书并且修改图书数量
* @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黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!