private void btnReturnBook_Click(object sender, EventArgs e) { if (this.dgvBorrowList.SelectedRows.Count > 0 && !string.IsNullOrEmpty(this.txtBookID.Text)) { // 确认是否结算了逾期费用 float fee = Convert.ToSingle(this.dgvBorrowList.SelectedRows[0].Cells["colFee"].Value.ToString()); if (fee > 0) { MessageBox.Show("该书已逾期,需先结算费用后才能归还,请联系管理员", "操作提示"); return; } DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable(); string query = string.Format(" WHERE uid = {0} AND b_id = {1} ", this._dbHelper.CurrentUser.uid, this.txtBookID.Text.Trim()); if (this._dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) > 0) { dtBorrowRecord[0].Delete(); if (this._dbHelper.UpdateTableBorrowRecord(dtBorrowRecord) >= 0) { MessageBox.Show("还书成功", "操作提示"); RefreshBorrowRecord(); } else { MessageBox.Show("还书失败,原因:系统操作存在问题,请联系管理员处理", "操作提示"); } } } }
private void btnBorrowAgain_Click(object sender, EventArgs e) { if (this.dgvBorrowList.SelectedRows.Count > 0) { float fee = Convert.ToSingle(this.dgvBorrowList.SelectedRows[0].Cells["colFee"].Value.ToString()); if (fee > 0) { MessageBox.Show("该书已逾期,需先结算费用后才能续借,请联系管理员", "操作提示"); return; } int reborrow = 0; if (!int.TryParse(this.dgvBorrowList.SelectedRows[0].Cells["colReborrow"].Value.ToString(), out reborrow)) { reborrow = 0; } // 仅允许续借一次 if (reborrow >= 1) { MessageBox.Show("该书已续借一次,请先归还后再借出", "操作提示"); return; } string bookID = this.dgvBorrowList.SelectedRows[0].Cells["colBID"].Value.ToString(); DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable(); string query = string.Format(" WHERE b_id = {0} ", bookID); if (this._dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) > 0) { // 续借1个月 dtBorrowRecord[0].returndate = dtBorrowRecord[0].validdate = dtBorrowRecord[0].validdate.AddMonths(1); dtBorrowRecord[0].reborrow += 1; if (this._dbHelper.UpdateTableBorrowRecord(dtBorrowRecord) >= 0) { MessageBox.Show("续借成功", "操作提示"); RefreshBorrowRecord(); } else { MessageBox.Show("续借失败,原因:系统操作存在问题,请联系管理员处理", "操作提示"); } } } }
/// <summary> /// 填充数据表[Borrow_Record]。 /// </summary> /// <param name="dataTable">填充数据表</param> /// <param name="where">查询条件</param> /// <param name="top">前多少行</param> /// <param name="clearBeforeFill">是否填充前清空</param> /// <returns>查询记录数目</returns> public int DataSetBorrowRecordFill(DataSetLibrarySystem.borrow_recordDataTable dataTable, string where = "", int top = 1000, bool clearBeforeFill = true) { int returnValue = 0; bool success = false; try { dataAdapterBorrow_RecordSelect.SelectCommand.CommandText = string.Format("SELECT TOP {0} uid, b_id, borrowcount, borrowdate, returndate, " + "validdate, status, fee, reborrow FROM dbo.borrow_record {1} ", top, where); if (clearBeforeFill) { dataTable.Clear(); } returnValue = dataAdapterBorrow_RecordSelect.Fill(dataTable); success = true; } catch (System.Exception ex) { Console.WriteLine(ex.Message); } return(success ? returnValue : -1); }
private void RefreshBorrowRecord() { this.dgvBorrowList.ClearSelection(); this.btnReturnBook.Enabled = false; // 查询借阅书籍 DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable(); string query = string.Format(" WHERE uid = {0} ", this._dbHelper.CurrentUser.uid); if (this._dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) >= 0) { this.lblOperateInfo.Text = string.Format("查询结果: 共找到 {0} 条借阅记录。", dtBorrowRecord.Count); // 逾期费用 float borrowFee = 0; // 是否逾期 bool outOfDate = false; int bookIndex = 0; this.dgvBorrowList.SuspendLayout(); this.dgvBorrowList.Rows.Clear(); this.txtBookID.Text = ""; this.numReturnCount.Value = 0; foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows) { this.dgvBorrowList.Rows.Add(); int outDateCount = (DateTime.Now - row.validdate).Days; if (outDateCount > 0) { outOfDate = true; // 逾期费用:1元/天/本 borrowFee += Math.Abs(outDateCount) * 1.0f; // 修改费用 row.fee = Convert.ToDecimal(Math.Abs(outDateCount) * 1.0f); row.status = "逾期"; } this.dgvBorrowList.Rows[bookIndex].Cells["colBID"].Value = row.b_id; // 书籍信息 DataSetLibrarySystem.bookDataTable dtCurrentBook = new DataSetLibrarySystem.bookDataTable(); query = string.Format(" WHERE b_id = {0} ", row.b_id); if (this._dbHelper.DataSetBookFill(dtCurrentBook, query) > 0) { this.dgvBorrowList.Rows[bookIndex].Cells["colTitle"].Value = dtCurrentBook[0].title; this.dgvBorrowList.Rows[bookIndex].Cells["colAuthor"].Value = dtCurrentBook[0].author; } else { this.dgvBorrowList.Rows[bookIndex].Cells["colTitle"].Value = "未知"; this.dgvBorrowList.Rows[bookIndex].Cells["colAuthor"].Value = "未知"; } this.dgvBorrowList.Rows[bookIndex].Cells["colBorrowCount"].Value = row.borrowcount; this.dgvBorrowList.Rows[bookIndex].Cells["colBorrowDate"].Value = row.borrowdate.ToString("yyyy-MM-dd"); this.dgvBorrowList.Rows[bookIndex].Cells["colValidDate"].Value = row.validdate.ToString("yyyy-MM-dd"); this.dgvBorrowList.Rows[bookIndex].Cells["colFee"].Value = row.fee.ToString("F2"); bookIndex++; } this.dgvBorrowList.ResumeLayout(); } else { this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。"; } }
private void RefreshBookList() { string userInfo = "管理员信息\n\n欢迎您,{0}\n账户:{1}\n馆藏书籍:{2} 本\n已借出书籍:{3} 本"; this.dgvBookList.ClearSelection(); this.btnBookDelete.Enabled = false; this.btnBookModify.Enabled = false; int booksCount = 0; int borrowedCount = 0; // 查询借阅书籍 DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable(); string query = ""; if (this._dbHelper.DataSetBookFill(dtBooks, query) >= 0) { //this.lblOperateInfo.Text = string.Format("查询结果: 共找到 {0} 条借阅记录。", dtBorrowRecord.Count); int bookIndex = 0; this.dgvBookList.SuspendLayout(); this.dgvBookList.Rows.Clear(); foreach (DataSetLibrarySystem.bookRow row in dtBooks.Rows) { this.dgvBookList.Rows.Add(); this.dgvBookList.Rows[bookIndex].Cells["colBID"].Value = row.b_id; this.dgvBookList.Rows[bookIndex].Cells["colTitle"].Value = row.title; this.dgvBookList.Rows[bookIndex].Cells["colAuthor"].Value = row.author; this.dgvBookList.Rows[bookIndex].Cells["colPress"].Value = row.presscompany; this.dgvBookList.Rows[bookIndex].Cells["colCategory"].Value = row.category; this.dgvBookList.Rows[bookIndex].Cells["colPublishDate"].Value = row.publishdate.ToString("yyyy-MM-dd"); this.dgvBookList.Rows[bookIndex].Cells["colInlabDate"].Value = row.inlibdate.ToString("yyyy-MM-dd"); this.dgvBookList.Rows[bookIndex].Cells["colCount"].Value = row.count; this.dgvBookList.Rows[bookIndex].Cells["colPosition"].Value = row.position; this.dgvBookList.Rows[bookIndex].Cells["colAbstract"].Value = row._abstract; this.dgvBookList.Rows[bookIndex].Cells["colImageUrl"].Value = row.imageurl; this.dgvBookList.Rows[bookIndex].Cells["colISBN"].Value = row.isbn; bookIndex++; // 书籍总量 booksCount += row.count; } this.dgvBookList.ResumeLayout(); } else { //this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。"; } DataSetLibrarySystem.borrow_recordDataTable dtBorrowed = new DataSetLibrarySystem.borrow_recordDataTable(); this._dbHelper.DataSetBorrowRecordFill(dtBorrowed); borrowedCount = dtBorrowed.Count; lblUserInfo.Text = string.Format(userInfo, this._dbHelper.CurrentUser.name, this._dbHelper.CurrentUser.account, booksCount, borrowedCount); }
private void btnBorrowBook_Click(object sender, EventArgs e) { if (!this.dbHelper.CurrentUser.isUserLogin) { if (loginDialog.ShowDialog() != DialogResult.OK) { MessageBox.Show("借书操作需要先登录账户!", "操作提示"); } else { this.dbHelper.CurrentUser.isUserLogin = true; } lblLoginStatus.Text = string.Format("状态:{0} {1}", this.dbHelper.CurrentUser.isUserLogin ? "已登录" : "未登录", this.dbHelper.CurrentUser.isUserLogin ? (this.dbHelper.CurrentUser.isAdminRole ? "(管理员)" : "(用户)") : ""); } if (this.dbHelper.CurrentUser.isUserLogin && this.dgvBookList.SelectedRows.Count > 0) { string bookId = this.dgvBookList.SelectedRows[0].Cells["colBID"].Value.ToString(); int bookCount = 0; if (!int.TryParse(this.dgvBookList.SelectedRows[0].Cells["colCount"].Value.ToString(), out bookCount)) { bookCount = 0; } // 查询书籍是否被借完 DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable(); string query = string.Format(" WHERE b_id = {0} ", bookId); if (this.dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) >= 0) { int borrowOutCount = 0; foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows) { borrowOutCount += row.borrowcount; } if (borrowOutCount >= bookCount) { MessageBox.Show("该书籍在馆藏本均已借出,暂时无法借阅", "操作提示"); return; } // 可借阅,查询账户是否欠费 query = string.Format(" WHERE uid = {0} ", this.dbHelper.CurrentUser.uid); // 逾期费用 float borrowFee = 0; // 是否逾期 bool outOfDate = false; // 是否已经借阅该书 bool alreadyHave = false; if (this.dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) > 0) { foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows) { int outDateCount = (DateTime.Now - row.validdate).Days; if (outDateCount > 0) { outOfDate = true; // 逾期费用:1元/天/本 borrowFee += Math.Abs(outDateCount) * 1.0f; // 修改费用 row.fee = Convert.ToDecimal(Math.Abs(outDateCount) * 1.0f); row.status = "逾期"; } if (row.b_id.ToString() == bookId) { alreadyHave = true; } } } // 逾期提醒 if (outOfDate) { MessageBox.Show(string.Format("您的账户内存在逾期费用未结算,共 {0} 元,暂时无法借阅", borrowFee.ToString("F2")), "操作提示"); return; } // 已借阅 if (alreadyHave) { MessageBox.Show("您的已经借阅了该书,尚未归还,如需续借请前往[用户管理]操作", "操作提示"); return; } // 符合借阅条件 dtBorrowRecord.Clear(); DataSetLibrarySystem.borrow_recordRow newBorrowRecord = dtBorrowRecord.Newborrow_recordRow(); newBorrowRecord.uid = this.dbHelper.CurrentUser.uid; newBorrowRecord.b_id = int.Parse(bookId); newBorrowRecord.borrowcount = 1; newBorrowRecord.borrowdate = DateTime.Now; // 借阅期限1个月 newBorrowRecord.returndate = newBorrowRecord.validdate = DateTime.Now.AddMonths(1); newBorrowRecord.status = "正常"; newBorrowRecord.fee = 0; newBorrowRecord.reborrow = 0; dtBorrowRecord.Rows.Add(newBorrowRecord.ItemArray); if (this.dbHelper.UpdateTableBorrowRecord(dtBorrowRecord) >= 0) { MessageBox.Show("书籍借阅成功!", "操作提示"); } else { MessageBox.Show("书籍借阅失败,系统操作存在问题,请联系管理员处理!", "操作提示"); } } } }