private void btnSearchBook_Click(object sender, EventArgs e) { string keywords = txtSearchKeywords.Text.Trim(); if (string.IsNullOrEmpty(keywords)) { MessageBox.Show("关键字不能为空", "操作提示"); return; } DataSetLibrarySystem.bookDataTable dtBook = new DataSetLibrarySystem.bookDataTable(); string query = string.Format(" WHERE title LIKE '%{0}%' OR author LIKE '%{0}%' ", keywords); if (this.dbHelper.DataSetBookFill(dtBook, query) >= 0) { this.lblOperateInfo.Text = string.Format("查询结果:符合要求记录共 {0} 条。", dtBook.Count); this.btnBorrowBook.Enabled = false; this.lblBookInfos.Text = ""; this.dgvBookList.SuspendLayout(); this.dgvBookList.ClearSelection(); this.dgvBookList.Rows.Clear(); DataSetLibrarySystem.bookRow currentBook = dtBook.NewbookRow(); for (int i = 0; i < dtBook.Rows.Count; i++) { currentBook = (DataSetLibrarySystem.bookRow)dtBook.Rows[i]; this.dgvBookList.Rows.Add(); this.dgvBookList.Rows[i].Cells["colBID"].Value = currentBook.b_id.ToString(); this.dgvBookList.Rows[i].Cells["colTitle"].Value = currentBook.title.ToString(); this.dgvBookList.Rows[i].Cells["colAuthor"].Value = currentBook.author.ToString(); this.dgvBookList.Rows[i].Cells["colPress"].Value = currentBook.presscompany.ToString(); this.dgvBookList.Rows[i].Cells["colCategory"].Value = currentBook.category.ToString(); this.dgvBookList.Rows[i].Cells["colPublishDate"].Value = currentBook.publishdate.ToString(); this.dgvBookList.Rows[i].Cells["colCount"].Value = currentBook.count.ToString(); this.dgvBookList.Rows[i].Cells["colPosition"].Value = currentBook.position.ToString(); this.dgvBookList.Rows[i].Cells["colAbstract"].Value = currentBook._abstract.ToString(); } this.dgvBookList.ResumeLayout(); } else { this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。"; } }
private void btnBookAdd_Click(object sender, EventArgs e) { if (this.dgvBookList.SelectedRows.Count > 0) { // 检查是否漏填信息 if (!CheckPanelTextBoxFill()) { MessageBox.Show("请填写完整书籍信息", "操作提示"); return; } DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable(); DataSetLibrarySystem.bookRow newBook = dtBooks.NewbookRow(); newBook.b_id = -1; newBook.title = this.txtTitle.Text.Trim(); newBook.author = this.txtAuthor.Text.Trim(); newBook.presscompany = this.txtPress.Text.Trim(); newBook.category = this.txtCategory.Text.Trim(); newBook.publishdate = this.dtpPublishDate.Value; newBook.inlibdate = this.dtpInlabDate.Value; newBook.count = Convert.ToInt32(this.numCount.Value); newBook.position = this.txtPosition.Text.Trim(); newBook._abstract = this.txtAbstract.Text.Trim(); newBook.isbn = this.txtISBN.Text.Trim(); newBook.imageurl = ""; newBook.bookremark = ""; dtBooks.Rows.Add(newBook.ItemArray); if (this._dbHelper.UpdateTableBook(dtBooks) > 0) { MessageBox.Show("书籍新增成功", "操作提示"); RefreshBookList(); EmptyPanelTextBox(); } else { MessageBox.Show("书籍新增失败,原因:系统操作存在问题", "操作提示"); } } }