//更新图书总数 private void btnSave_Click(object sender, EventArgs e) { //数据验证 if (this.txtAddCount.Text.Trim().Length == 0) { MessageBox.Show("请输入新增图书量", "信息提示"); this.txtAddCount.Focus(); this.txtAddCount.SelectAll(); return; } if (!DataValidate.IsInteger(this.txtAddCount.Text.Trim())) { MessageBox.Show("新增总数非法,必须为整数", "错误提示"); return; } //数据更新 try { int addCount = Convert.ToInt32(this.txtAddCount.Text.Trim()); //更新数据库图书总数 int result = objBookManager.AddBookCount(this.txtBarCode.Text.Trim(), addCount); //更新列表中图书总数 if (result == 1) { var bookListTemp = bookList.Where(b => b.BarCode == this.txtBarCode.Text.Trim()).First(); bookListTemp.BookCount += addCount; this.dgvBookList.Refresh(); //清空图书信息的显示 this.lblBookName.Text = ""; this.lblBookCount.Text = ""; this.lblBookPosition.Text = ""; this.lblCategory.Text = ""; this.lblBookId.Text = ""; this.pbImage.Image = null; //图书条码文本框获取焦点 this.txtBarCode.Clear(); this.txtAddCount.Clear(); this.txtAddCount.Enabled = false; this.txtBarCode.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnSave_Click(object sender, EventArgs e) { if (this.txtBarCode.Text.Trim().Length == 0) { MessageBox.Show("请输入图书条码", "提示信息"); this.txtBarCode.Focus(); return; } if (!Common.DataValidate.IsInteger(this.txtAddCount.Text.Trim())) { MessageBox.Show("请输入正整数的图书新增总数", "提示信息"); this.txtAddCount.SelectAll(); this.txtAddCount.Focus(); return; } try { int result = objBookManager.AddBookCount(this.txtBarCode.Text.Trim(), Convert.ToInt32(this.txtAddCount.Text.Trim())); if (result == 1) { MessageBox.Show("新增成功", "提示信息"); Book objBook = (from b in this.bookList where b.BarCode == this.txtBarCode.Text.Trim() select b).First <Book>(); objBook.BookCount += Convert.ToInt32(this.txtAddCount.Text.Trim()); objBook.Remainder += Convert.ToInt32(this.txtAddCount.Text.Trim()); this.dgvBookList.Refresh(); this.txtAddCount.Enabled = false; this.lblBookName.Text = ""; this.lblCategory.Text = ""; this.lblBookCount.Text = ""; this.lblBookPosition.Text = ""; this.lblBookId.Text = ""; this.pbImage.Image = null; this.txtBarCode.Clear(); this.txtAddCount.Clear(); } else { MessageBox.Show("新增失败,请刷新后重试", "提示信息"); } } catch (Exception ex) { MessageBox.Show("新增失败,具体原因:" + ex.Message, "提示信息"); } }