/// <summary> /// Populates the book list and adds book object to the box /// </summary> private void PopulateBookList() { List <Book> allBooks = BookDB.GetAllBooks(); //allBooks = allBooks.OrderByDescending(b => b.Title).ToList(); // Start with a blank list bookNameBx.Items.Clear(); // Add the books to the list foreach (Book b in allBooks) { bookNameBx.Items.Add(b); } }
private void PopulateBookList() { cboxBook.Items.Clear(); try { List <Book> books = BookDB.GetAllBooks(); foreach (Book b in books) { cboxBook.Items.Add(b); } } catch (SqlException ex) { MessageBox.Show("We are having trouble loading data, try again later"); Application.Exit(); } }
/// <summary> /// AddBook button on the addbook form, sets variables from boxes and creates a new book under conditions of not failing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddBookFormBtn_Click(object sender, EventArgs e) { Book b = new Book() { ISBN = addBookIsbnTxt.Text, Price = Convert.ToDecimal(addBookPriceTxt.Text), Title = addBookTitleTxt.Text }; NewBook = b; try { BookDB.Add(b); DialogResult = DialogResult.OK; MessageBox.Show("The book was added?"); } catch { MessageBox.Show("There are currently server issues"); } }
private void btnAddBook_Click(object sender, EventArgs e) { Book addBook = new Book() { ISBN = txtISBN.Text , Title = txtTitle.Text , Price = Convert.ToDecimal(txtPrice.Text) }; try { if (bookToBeAdded == null) { BookDB.AddBook(addBook); MessageBox.Show("Book added!!!"); } } catch (SqlException ex) { MessageBox.Show("We are having server issues, please try again later"); } this.Close(); }