private void btnSave_Click(object sender, RoutedEventArgs e) { //valittu Book-olio tallennetaan kantaan try { Book current = (Book)SpBook.DataContext; BookShop.UpdateBook(current); MessageBox.Show(string.Format("Kirja {0} päivitetty kantaan onnistuneesti", current.ToString())); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 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 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); } }