private void buttonBEdit_Click(object sender, EventArgs e) { if (!isSelectedBook()) { MessageBox.Show("Please select a book to edit"); return; } if (buttonBEdit.Text == "Finish") { Book b = new Book(); b.BookNumber = int.Parse(txtBookNumber.Text); b.Title = txtTitle.Text; b.Authors = txtAuthors.Text; b.Publisher = txtPublisher.Text; BookBL.Update(b); refreshBook(); } else { buttonBEdit.Text = "Finish"; txtBookNumber.Enabled = false; txtTitle.Enabled = true; txtAuthors.Enabled = true; txtPublisher.Enabled = true; } }
private void buttonBAdd_Click(object sender, EventArgs e) { txtBookNumber.Enabled = false; txtTitle.Enabled = true; txtAuthors.Enabled = true; txtPublisher.Enabled = true; if (buttonBAdd.Text == "Finish") { Book b = new Book(); b.BookNumber = int.Parse(txtBookNumber.Text); b.Title = txtTitle.Text; b.Authors = txtAuthors.Text; b.Publisher = txtPublisher.Text; BookBL.Insert(b); refreshBook(); buttonBAdd.Text = "Add"; } else { buttonBAdd.Text = "Finish"; int max = ++BookBL.bookNumberMax; txtBookNumber.Text = max.ToString(); txtTitle.Focus(); } }
private void buttonBDelete_Click(object sender, EventArgs e) { if (!isSelectedBook()) { MessageBox.Show("Please select a book to delete"); return; } Book b = new Book(); b.BookNumber = int.Parse(dataGridViewBook.SelectedRows[0].Cells["bookNumber"].Value.ToString()); BookBL.Delete(b); refreshBook(); }
public static bool Delete(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Delete Book where bookNumber = @bookNumber", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Insert(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert into Book(bookNumber, title, authors, publisher)"+"values(@bookNumber, @title, @authors, @publisher)", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cmd.Parameters.AddWithValue("@title", b.Title); cmd.Parameters.AddWithValue("@authors", b.Authors); cmd.Parameters.AddWithValue("@publisher", b.Publisher); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (System.Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Update(Book b) { return BookDA.Update(b); }
public static bool Insert(Book b) { return BookDA.Insert(b); }
public static bool Delete(Book b) { return BookDA.Delete(b); }
public static bool Update(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Update Book set title = @title, " + "authors = @authors, publisher = @publisher where bookNumber = @bookNumber", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cmd.Parameters.AddWithValue("@title", b.Title); cmd.Parameters.AddWithValue("@authors", b.Authors); cmd.Parameters.AddWithValue("@publisher", b.Publisher); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }