Exemple #1
0
 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);
     }
 }
Exemple #2
0
 private void btnHaeSQL_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         myGrid.DataContext = Bookshop.GetBooks(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
 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);
     }
 }
Exemple #5
0
 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);
     }
 }
Exemple #6
0
 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);
     }
 }
Exemple #7
0
 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";
     }
 }
Exemple #8
0
 private void btnHaeTesti_Click(object sender, RoutedEventArgs e)
 {
     myGrid.DataContext = Bookshop.GetTestBooks();
 }