Esempio n. 1
0
        /// <summary>
        /// Adds a single book to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddBookBtn_Click(object sender, EventArgs e)
        {
            //If user enters valid data
            if (isDataValid() == true)
            {
                MessageBox.Show("Saved the book to the database");

                //Creates a single book object
                Book b = new Book()
                {
                    ISBN  = isbnTxt.Text,
                    Title = titleTxt.Text,
                    Price = Convert.ToDecimal(priceTxt.Text)
                };

                //Once a book object has been created,
                //set the new book into that property (Book.cs)
                NewBook = b;

                try
                {
                    //Add the book to the database
                    BookDB.Add(b); //This .add is from BookDB's add method
                    DialogResult = DialogResult.OK;
                }
                catch
                {
                    MessageBox.Show("We're having server issues");
                }
            }
        }