static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Tech Elevator Bookstore");
            Console.WriteLine();

            // Step Three: Test the properties

            Book readyPlayerOne = new Book();

            readyPlayerOne.Author = "Ernest Kline";
            readyPlayerOne.Title  = "Ready Player 1";
            readyPlayerOne.Price  = 24.99;

            Book cosmos = new Book("Cosmos", "Carl Sagan", 45.99);

            Console.WriteLine(cosmos.BookInfo());
            Console.WriteLine(readyPlayerOne.BookInfo());

            // Step Five: Test the Book constructor



            // Step Nine: Test the ShoppingCart class

            ShoppingCart cart = new ShoppingCart();

            cart.Add(cosmos);
            cart.Add(readyPlayerOne);
            double shoppingCartTotal = cart.TotalPrice;

            Console.WriteLine(cart.PrintReceipt(true));
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Tech Elevator Bookstore");
            Console.WriteLine();

            // Step Three: Test the properties
            Book twoCities = new Book("A Tale of Two Cities", "Charles Dickens", 14.99M);

            Console.WriteLine($"Title: {twoCities.Title}, Author: {twoCities.author}, Price: {twoCities.price:C2}");

            // Step Five: Test the Book constructor
            Book threeMusketeers = new Book("The Three Musketeers", "Alexandre Dumas", 12.95M);

            Console.WriteLine(threeMusketeers.BookInfo());
            Book firstInTheSeries = new Book("Harry Potter and the Sorcerer's Stone", "J.K. Rowling", 152.00M);

            Console.WriteLine(firstInTheSeries.BookInfo());
            // Step Nine: Test the ShoppingCart class
            ShoppingCart myCart = new ShoppingCart();

            myCart.budget = 1700.00M;
            myCart.Add(firstInTheSeries);
            Console.WriteLine(myCart.TotalPrice);
            myCart.Add(twoCities);
            Console.WriteLine(myCart.TotalPrice);
            myCart.Add(threeMusketeers);
            Console.WriteLine(myCart.TotalPrice);
            myCart.Add(threeMusketeers);
            Console.WriteLine(myCart.TotalPrice);

            Console.WriteLine(myCart.PrintReceipt());
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Tech Elevator Bookstore");
            Console.WriteLine();

            // Step Three: Test the properties
            Book twoCities = new Book();

            twoCities.Title  = "A Tale of Two Cities";
            twoCities.Author = "Charles Dickens";
            twoCities.Price  = 14.99;
            //Console.WriteLine("Title: " + twoCities.Title + ", Author: " + twoCities.Author + ", Price: $" + twoCities.Price);
            Console.WriteLine(twoCities.BookInfo());

            // Step Five: Test the Book constructor
            Book threeMusketeers = new Book("The Three Musketeers", "Alexandre Dumas", 12.95);
            Book childhoodEnd    = new Book("Childhood's End", "Arthur C. Clark", 5.99);

            //Console.WriteLine("Title: " + threeMusketeers.Title + ", Author: " + threeMusketeers.Author + ", Price: $" + threeMusketeers.Price);
            //Console.WriteLine("Title: " + childhoodEnd.Title + ", Author: " + childhoodEnd.Author + ", Price: $" + childhoodEnd.Price);
            Console.WriteLine(threeMusketeers.BookInfo());
            Console.WriteLine(childhoodEnd.BookInfo());

            // Step Nine: Test the ShoppingCart class
            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Add(twoCities);
            shoppingCart.Add(threeMusketeers);
            shoppingCart.Add(childhoodEnd);
            Console.WriteLine(shoppingCart.PrintReceipt());
        }
Exemple #4
0
 //Look up an ISBN number in our bookList file. Calls bookSearch in FileHandler class. Updates display for users.
 private void btnISBNSearch_Click(object sender, EventArgs e)
 {
     if (!Regex.IsMatch(txtISBNNumLookUp.Text, validation[0]))
     {
         MessageBox.Show("Invalid ISBN number, please re enter." + validation[0], "Invalid ISBN");
         return;
     }
     if (fh.bookSearch(ref currentBook, txtISBNNumLookUp.Text))
     {
         UpdateDisplayInfo(currentBook.BookInfo());
     }
     else//Cant find ISBN number
     {
         MessageBox.Show("ISBN not found", "ISBN Error");
     }
 }
Exemple #5
0
        //Handles searching the book file for the specified book, as well as deleting/updating files.
        //Flags are "delete"/"update". Add is handled with a boolean and then calling the addBook method.
        //Doing it this way prevents having to re-search/scan the file for deleting/updating.
        //While you could do delete/update in similar ways it revolves around constantly keeping track
        //of the Reader/Writer which I feel is more difficult to follow than this method.
        //However, this method does kind of do a lot and is a pain to read through.
        public bool bookSearch(ref Book book, string isbn, string flag = "")
        {
            sw          = new StreamWriter(tempFile);
            sr          = new StreamReader(sourceFile);
            currentBook = book; //Store original book passed
            string line;
            bool   found = false;

            flag.ToLower();

            while ((line = sr.ReadLine()) != null)
            {
                string[] bookInfo = line.Split('|');
                //ISBN ID Validatio(Two groups of 3 digits delimited by hyphen)
                if (Book.ValidateISBNFormat(bookInfo[0]))
                {
                    if (bookInfo[0] == isbn && flag == "")    //Just a search, return the book that was being looked for/dont modify file
                    {
                        book  = new Book(bookInfo);
                        found = true;
                        sw.Close();
                        sr.Close();
                        return(found);
                    }
                    else if (bookInfo[0] == isbn && flag == "delete")   //Record found, delete it? If yes, just skip writing.
                    {
                        Book         deleteBook = new Book(bookInfo);
                        DialogResult dr         = MessageBox.Show("Book with ISBN: " + isbn + " found.\r\n" +
                                                                  String.Join(Environment.NewLine, deleteBook.BookInfo()) + "\r\nIs this the book you wish to delete?",
                                                                  "Delete Book", MessageBoxButtons.YesNo);
                        if (dr == DialogResult.Yes)
                        {
                            found = true;
                        }
                    }
                    else if (bookInfo[0] == isbn && flag == "update")    //Update a record
                    {
                        sw.WriteLine(currentBook.ToString());
                        found = true;
                    }
                    else    //This book doesn't match the book being searched for, safe to just write it.
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            sw.WriteLine(line);
                        }
                    }
                }
                else    //What to do if we have invalid entry in txt file/data corruption
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        MessageBox.Show("Inventory file has issue at ISBN: " + bookInfo[0],
                                        "Data Corruption");//Move to form code probably
                        return(false);
                    }
                }
            }
            sr.Close();
            sw.Close();
            return(found);
        }
Exemple #6
0
        /*
         * Writes the contents of one Book record to the updatedBookFile
         */
        public void writeOneRecord(Book book)
        {
            String line = book.BookInfo();

            BookStore.updatedBookFile.writeToFile(line);
        }