Ejemplo n.º 1
0
 private void btnBookAdd_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrWhiteSpace(txtISBN.Text) || String.IsNullOrWhiteSpace(txtBookTitle.Text) || String.IsNullOrWhiteSpace(txtBookAuthor.Text) ||
         String.IsNullOrWhiteSpace(txtPublisher.Text) || String.IsNullOrWhiteSpace(txtYearOfPublication.Text) || String.IsNullOrWhiteSpace(txtURIL.Text) ||
         String.IsNullOrWhiteSpace(txtURIM.Text) || String.IsNullOrWhiteSpace(txtURIS.Text))
     {
         MessageBox.Show("Information cannot be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     else
     {
         int year = 0;
         Int32.TryParse(txtYearOfPublication.Text, out year);
         Book book = new Book()
         {
             ISBN              = txtISBN.Text,
             BookTitle         = txtBookTitle.Text,
             BookAuthor        = txtBookAuthor.Text,
             Publisher         = txtPublisher.Text,
             YearOfPublication = year,
             ImageURI_L        = txtURIL.Text,
             ImageURI_M        = txtURIM.Text,
             ImageURI_S        = txtURIS.Text
         };
         var addBookResponse = SqlHandler.AddBook(book);
         if (addBookResponse.Success)
         {
             MessageBox.Show("Successfully added " + book.BookTitle + ".", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
             lbxBook.Items.Add(book);
         }
         else
         {
             MessageBox.Show("Error adding " + book.BookTitle + ".\n\n" + addBookResponse.ErrorText, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }