private void btnNew_Click(object sender, RoutedEventArgs e) { try { if (btnNew.Content.ToString() == "Uusi") { Book newBook = new Book(0); newBook.Name = "Anna kirjan nimi"; spBook.DataContext = newBook; btnNew.Content = "Tallenna uusi kantaan"; } else { //Tallennetaan Book current = (Book)spBook.DataContext; Bookshop.InsertBook(current); myGrid.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Kirja {0} tallennettu kantaan onnistuneesti", current.ToString())); btnNew.Content = "Uusi"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnHaeSQL_Click(object sender, RoutedEventArgs e) { try { myGrid.DataContext = Bookshop.GetBooks(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnHaeSQLServer_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)spBook.DataContext; if (Bookshop.UpdateBook(current) > 0) { MessageBox.Show(string.Format("Kirja {0} päivitetty tietokantaa onnustuneesti", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnTallenna_Click(object sender, RoutedEventArgs e) { //mistä tiedetään mitä muokata --> Book-olion ID:stä! try { Book current = (Book)spBook.DataContext; if (Bookshop.UpdateBook(current) > 0) { tbMessage.Text = string.Format("Kirja {0} päivitetty tietokantaan onnistuneesti", current.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { //Poistetaan valittu kirja Book current = (Book)spBook.DataContext; var retval = MessageBox.Show("Haluatko varmasti poistaa kirjan " + current.ToString(), "Wanhat kirjat kysyy", MessageBoxButton.YesNo); if (retval == MessageBoxResult.Yes) { Bookshop.DeleteBook(current); myGrid.DataContext = Bookshop.GetBooks(true); MessageBox.Show(string.Format("Kirja {0} poistettu kannasta onnistuneesti", current.ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUusi_Click(object sender, RoutedEventArgs e) { if (btnUusi.Content.ToString() == "Uusi") { //luodaan uusi kirja -olio Book newBook = new Book(0); newBook.Name = "Anna kirjan nimi"; spBook.DataContext = newBook; btnUusi.Content = "Tallenna uusi kantaan"; } else { //tallennetaan Book current = (Book)spBook.DataContext; Bookshop.InsertBook(current); dgBooks.DataContext = Bookshop.GetBooks(true); tbMessage.Text = string.Format("Kirja {0} tallennettu kantaan onnistuneesti", current.ToString()); btnUusi.Content = "Uusi"; } }
private void btnHaeTesti_Click(object sender, RoutedEventArgs e) { myGrid.DataContext = Bookshop.GetTestBooks(); }