在Key_Down 事件中:
if (e.KeyCode == Keys.Enter)
{
Books book = bookBLL.GetBookInfoByBookNum(textBox7.Text);//根据图书条码查询图书信息
if (book != null)//判断是否有该条码的图书
{
button1.Enabled = true;
button1.BackColor = Color.SlateGray;
button2.Enabled = true;
button2.BackColor = Color.SlateGray;
BorrowBook bb = new BorrowBook();//存储借书信息的对象
bb.BookNum = book.BookNum;
bb.BookSum = 1;
bb.BorrowTime = DateTime.Now;
bb.CardId = member.CardId;
bb.EndTime = DateTime.Now.AddMonths(1);//最后还书日期
bb.State = 0;//未还
bb.BookName = book.BookName;
list.Add(bb);
}
else
{
MessageBox.Show("没有该图书信息!");
//textBox7.Text = "";
}
如果textBox7是多行模式(multiLine),则键盘输入enter后,后隐藏之前输入textBox7的内容,无法取到正确的数据,容易犯错的地方,记下来以备将来查看。