private void btn_edit_book_Click(object sender, EventArgs e) { string sid = tb_id_book.Text.Trim(); string name = tb_name_book.Text.ToString().Trim(); string author = tb_author_book.Text.ToString().Trim(); string category = cb_category_book.SelectedItem.ToString().Trim(); string sstock = tb_stock_book.Text.ToString().Trim(); if (category.Equals("Select")) { category = ""; } if (!isValidString(sid)) { sid = "0"; } if (isValidString(sid) && isValidString(name) && isValidString(author) && isValidString(category) && isValidString(sstock)) { int id = int.Parse(sid); int stock = int.Parse(sstock); BookControls bookControls = new BookControls(); Book book = bookControls.SearchBook(id); if (book != null) { book = new Book(id, name, author, category, stock); bookControls = new BookControls(book); bool isEdited = bookControls.EditBook(); if (isEdited) { if (cb_search_book.SelectedIndex == cb_search_book.FindStringExact(book.Category.Trim())) { LoadBooks(); } else { cb_search_book.SelectedIndex = cb_search_book.FindStringExact(book.Category.Trim()); } ClearViews(); MessageBox.Show("Book Edited."); } else { MessageBox.Show("Book can not be Edited."); } } else { MessageBox.Show("Book Doesn't Exist."); } } else { MessageBox.Show("Please Enter All Info."); } }