Example #1
0
        //Update Book *** NOT WORKING - Don't know what to do ***
        private void btnUpdateBook_Click(object sender, EventArgs e)
        {
            string bookType      = cmbBookType.Text;
            string title         = txtTitle.Text;
            double price         = double.Parse(txtPrice.Text);
            string publisher     = txtPublisher.Text;
            int    yearPublished = int.Parse(txtYearPublished.Text);
            int    isbn          = int.Parse(txtISBN.Text);
            int    numberOfPages = int.Parse(txtNumberOfPages.Text);
            int    fileSize      = int.Parse(txtFileSize.Text);
            string textbookType  = cmbTextbookType.Text;

            EBook    newEbook    = new EBook(title, price, publisher, yearPublished, isbn, numberOfPages, fileSize);
            Textbook newTextbook = new Textbook(title, price, publisher, yearPublished, isbn, numberOfPages);

            int isbnSearch = int.Parse(txtISBN.Text);

            if (UpdateBook(newEbook, isbnSearch) || UpdateBook(newTextbook, isbnSearch))
            {
                MessageBox.Show("Update Completed");
            }
            else
            {
                MessageBox.Show("Update Failed");
            }
        }
Example #2
0
        //Add Book
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            string bookType      = cmbBookType.Text;
            string title         = txtTitle.Text;
            double price         = double.Parse(txtPrice.Text);
            string publisher     = txtPublisher.Text;
            int    yearPublished = int.Parse(txtYearPublished.Text);
            int    isbn          = int.Parse(txtISBN.Text);
            int    numberOfPages = int.Parse(txtNumberOfPages.Text);

            if (bookType == "E-Book")
            {
                int fileSize = int.Parse(txtFileSize.Text);

                EBook newEbook = new EBook(title, price, publisher, yearPublished, isbn, numberOfPages, fileSize);
                if (AddNewBook(newEbook))
                {
                    MessageBox.Show("Successful Insertion");
                }
                else
                {
                    MessageBox.Show("Fail Insertion");
                }
            }
            else if (bookType == "Textbook")
            {
                BookTypeEnum textBookType = (BookTypeEnum)cmbTextbookType.SelectedItem;

                Textbook newTextbook = new Textbook(title, price, publisher, yearPublished, isbn, numberOfPages, textBookType);
                if (AddNewBook(newTextbook))
                {
                    MessageBox.Show("Successful Insertion");
                }
                else
                {
                    MessageBox.Show("Fail Insertion");
                }
            }

            txtTitle.Clear();
            txtPrice.Clear();
            txtPublisher.Clear();
            txtYearPublished.Clear();
            txtISBN.Clear();
            txtNumberOfPages.Clear();
            txtFileSize.Clear();

            #region Manual Data Input Test
            //Test - input sample date manually first
            //EBook eb = new EBook(title, price, publisher, yearPublished, isbn, numberOfPages, fileSize);

            //eb.Title = "Book1";
            //eb.Price = 6.50;
            //eb.Publisher = "Thien";
            //eb.YearPublished = 1999;
            //eb.ISBN = 1234;
            //eb.NumberOfPages = 50;
            //eb.FileSize = 1000;

            //MessageBox.Show(eb.ToString());
            #endregion
        }