コード例 #1
0
        private void txtReadingCard_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.txtReadingCard.Text.Length != 0 && e.KeyValue == 13)
            {
                objReader = readerService.GetReaderByReadingCard(this.txtReadingCard.Text.Trim());
                if (objReader != null)
                {
                    if (objReader.StatusId == 1)
                    {
                        //显示读者信息
                        this.lblReaderName.Text  = objReader.ReaderName;
                        this.lblRoleName.Text    = objReader.RoleName;
                        this.lblAllowCounts.Text = objReader.AllowCounts.ToString();
                        this.pbReaderImage.Image = objReader.ReaderImage != "" ? (Image) new Common.SerializeObjectToString().DeserializeObject(this.objReader.ReaderImage) : null;

                        //开启图书条码扫描文本框已经还书按钮
                        this.txtBarCode.Enabled       = true;
                        this.btnConfirmReturn.Enabled = true;
                        //显示读者未归还的图书
                        nonReturnList = borrowService.GetBorrowDetailByReadingCard(this.txtReadingCard.Text.Trim());
                        this.dgvNonReturnList.DataSource = null;
                        this.dgvNonReturnList.DataSource = nonReturnList;

                        //显示已借阅图书总数和剩余可借图书总数

                        /* int borrowCount = borrowService.GetBorrowCount(this.txtReadingCard.Text.Trim());
                         * this.lblBorrowCount.Text = borrowCount.ToString();
                         * this.lbl_Remainder.Text = (objReader.AllowCounts - borrowCount).ToString();*/

                        //基于linq实现
                        int borrowCount = (from n in nonReturnList select n).Sum(u => u.NonReturnCount);
                        int remainder   = objReader.AllowCounts - borrowCount;
                        this.lblBorrowCount.Text = borrowCount.ToString();
                        this.lbl_Remainder.Text  = remainder.ToString();
                    }
                    else
                    {
                        MessageBox.Show("当前借阅证已经被挂失,目前不能拿继续使用!", "还书提示");
                    }
                }
                else
                {
                    MessageBox.Show("当前借阅证号不存在!!!", "查询提示");
                    this.txtReadingCard.SelectAll();
                }
            }
        }