/// <summary> /// 条码框失去焦点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtBarCode_Leave(object sender, EventArgs e) { if (this.txtBarCode.Text.Trim().Length != 0) { //3判断是否达到借阅上限 if (borrowList.Select(o => o.BorrowCount).Sum() == Convert.ToInt32(this.lbl_Remainder.Text.Trim())) { MessageBox.Show("当前借阅证已达到借阅上限了哦!", "借阅提示"); return; } Book book = null; try { //1.查询图书信息 book = bookManager.GetBookInfoByBarCode(this.txtBarCode.Text.Trim()); } catch (Exception exception) { MessageBox.Show("查询异常:" + exception.Message, "异常提示"); } if (book == null) { MessageBox.Show("未查询到当前图书", "借阅提示"); return; } //2.保存到列表中 var borrowDetail = borrowList.Where(o => o.BookId == book.BookId).FirstOrDefault(); if (borrowDetail != null) { borrowDetail.BorrowCount++; this.dgvBookList.Refresh(); } else { borrowList.Add(new BorrowDetail { BookId = book.BookId, BookName = book.BookName, BarCode = book.BarCode, BorrowCount = 1, Expire = DateTime.Now.AddDays(reader.AllowDay) }); this.dgvBookList.DataSource = null; this.dgvBookList.DataSource = borrowList; this.btnDel.Enabled = true; this.btnSave.Enabled = true; } } }
//TxtBarCode失去焦点 private void TxtBarCode_Leave(object sender, EventArgs e) { if (this.txtBarCode.Text.Trim().Length != 0) { try { var bookInfo = bookManager.GetBookInfoByBarCode(this.txtBarCode.Text.Trim()); if (bookInfo == null) { MessageBox.Show("未查询到该图书信息", "查询信息"); this.txtBarCode.SelectAll(); this.txtBarCode.Focus(); } else { this.lblBookName.Text = bookInfo.BookName; this.lblCategory.Text = bookInfo.CategoryName; this.lblBookPosition.Text = bookInfo.BookPosition; this.lblBookId.Text = bookInfo.BookId.ToString(); this.lblBookCount.Text = bookInfo.BookCount.ToString(); this.pbImage.Image = (Image)SerializeObjectToString.DeserializeObject(bookInfo.BookImage); this.txtAddCount.Enabled = true; this.btnSave.Enabled = true; this.txtAddCount.Focus(); var isExists = books.Where(o => o.BarCode == bookInfo.BarCode).Count(); if (isExists == 0) { books.Add(bookInfo); this.dgvBookList.DataSource = null; this.dgvBookList.DataSource = books; } } } catch (Exception ex) { MessageBox.Show("查询图书信息异常:" + ex.Message, "异常提示"); } } }