Ejemplo n.º 1
0
 private void addBtn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string isbn        = isbnTextBox.Text;
         string author      = authorTextBox.Text;
         string title       = titleTextBox.Text;
         string publisher   = publisherTextBox.Text;
         int    publishedAt = int.Parse(publishedAtTextBox.Text);
         int    pagesCount  = int.Parse(pagesCountTextBox.Text);
         string price       = priceTextBox.Text;
         Book   book        = new Book(isbn, author, title, publisher, publishedAt, pagesCount, price);
         foreach (Book otherBook in bookList.Books)
         {
             if (book.ISBN == otherBook.ISBN)
             {
                 if (book.Equals(otherBook))
                 {
                     break;
                 }
                 else
                 {
                     throw new FormatException("ISBN must be unique for different editions.");
                 }
             }
         }
         bookList.AddBook(book);
     }
     catch (OverflowException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(ex.ParamName);
     }
     catch (FormatException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch
     {
         MessageBox.Show("Wrong data");
     }
     return;
 }