private void btnGetBooksSQL_Click(object sender, RoutedEventArgs e) { try { dgBooks.DataContext = Bookshop.GetBooks(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { Book current = (Book)spInfo.DataContext; if (Bookshop.UpdateBook(current) > 0) { MessageBox.Show(string.Format("Kirja {0} päivitetty tietokantaan onnistuneesti", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnGetSQLbooks_Click(object sender, RoutedEventArgs e) { try { // Haetaan kirjat BL-kerroksesta dgBooks.DataContext = Bookshop.GetBooks(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { Book current = (Book)spContent.DataContext; if (Bookshop.UpdateBook(current) > 0) { MessageBox.Show(string.Format("Book {0} updated successfully", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { //poistetaan valittu kirja Book current = (Book)spInfo.DataContext; var retval = MessageBox.Show("Haluatko varmasti poistaa kirjan " + current.ToString(), "Wanhat kirjat kysyy", MessageBoxButton.YesNo); if (retval == MessageBoxResult.Yes) { Bookshop.DeleteBook(current); dgBooks.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Kirja {0} poistetaan", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnCreateNew_Click(object sender, RoutedEventArgs e) { if (btnCreateNew.Content.ToString() == "Uusi") { //luodaan uusi kirja-olio Book newBook = new Book(0); newBook.Name = "Anna kirjan nimi"; spInfo.DataContext = newBook; btnCreateNew.Content = "Tallenna uusi kantaan"; } else { //tallennetaan Book current = (Book)spInfo.DataContext; Bookshop.InsertBook(current); dgBooks.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Kirja {0} tallennettu kantaan onnistuneesti", current.ToString())); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { // Poistetaan valittu kirja Book current = (Book)spContent.DataContext; var retval = MessageBox.Show("Do you really want to delete book" + current.ToString(), "QUESTION", MessageBoxButton.YesNo); if (retval == MessageBoxResult.Yes) { Bookshop.DeleteBook(current); dgBooks.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Book {0} deleted from the database successfully", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnNew_Click(object sender, RoutedEventArgs e) { if (btnNew.Content.ToString() == "New") { // Luodaan uusi olio Book newBook = new Book(0); newBook.Name = "Anna kirjan nimi"; spContent.DataContext = newBook; btnNew.Content = "Insert to database"; } else { // Tallennetaan Book current = (Book)spContent.DataContext; Bookshop.InsertBook(current); dgBooks.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Book {0} inserted to database successfully", current.ToString())); } }
private void btnGetTestBooks_Click(object sender, RoutedEventArgs e) { dgBooks.DataContext = Bookshop.GetTestBooks(); }