private void save(string str) { //int id = Int32.Parse(textBoxId.Text); string name = textBoxName.Text; string author = textBoxAuthor.Text; string description = textBoxDescription.Text; model.Book book = new model.Book(name, author, description); if (str.Equals("添加")) { bookDao.Save(book); //执行保存 } else if (str.Equals("更新")) { if (null != dataGridViewBooks.CurrentRow.Cells[0].Value.ToString() && !dataGridViewBooks.CurrentRow.Cells[0].Value.ToString().Equals("")) { //user.Id = Int32.Parse(gridViewUser.CurrentRow.Cells[0].Value.ToString()); book.Id = idFlag; bookDao.Modify(book);//执行更新 buttonUpdate.Enabled = false; } else { MessageBox.Show("请选中你要更新的对象!"); } } }
private void FillText(model.Book book) { textBoxId.Text = "" + book.Id;; textBoxName.Text = book.Name; textBoxAuthor.Text = book.Author; textBoxDescription.Text = book.Description; }
private void buttonDelete_Click(object sender, EventArgs e) { ///获取操作对象标识 // MessageBox.Show(gridViewUser.CurrentRow.Cells[0].Value.ToString()); string id = dataGridViewBooks.CurrentRow.Cells[0].Value.ToString(); if (null != id && !id.Equals("")) { model.Book book = new model.Book(); book.Id = Int32.Parse(id); bookDao.Delete(book); ///刷新数据 List <model.Book> list = bookDao.findAll(); showData(list); } else { MessageBox.Show("请选中你要操作的对象!"); } }
private void buttonEdit_Click(object sender, EventArgs e) { buttonUpdate.Enabled = true; string id = dataGridViewBooks.CurrentRow.Cells[0].Value.ToString(); if (null != id && !id.Equals("")) { model.Book book = bookDao.Get(Int32.Parse(id)); idFlag = book.Id;///保存ID /// FillText(book); ///刷新数据 List <model.Book> list = bookDao.findAll(); showData(list); } else { MessageBox.Show("请选中你要操作的对象!"); } }