Пример #1
0
        static void Main(string[] args)
        {
            string      fileName = SetFileName();
            CardCatalog cc       = new CardCatalog(fileName);
            string      result   = "";

            while (result != "3")
            {
                Console.Clear();

                Console.WriteLine("Greetings, \n\n");
                Console.WriteLine("Please select an option:");
                Console.WriteLine("1) List All Books");
                Console.WriteLine("2) Add a Book");
                Console.WriteLine("3) Save and Exit");

                result = Console.ReadLine();
                if (result == "1")
                {
                    cc.ListBooks();
                }
                if (result == "2")
                {
                    cc.AddBook("");
                }
                if (result == "3")
                {
                    cc.Save();
                }
            }

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter the Name of a File: ");
            string fileToUse = Console.ReadLine();

            CardCatalog currentCardCatalog = new CardCatalog(fileToUse);

            Console.Clear();

            bool stillGoing = true;

            while (stillGoing == true)
            {
                Console.WriteLine("CHOOSE AN OPTION 1 - 3 for {0}\n\n1. List All books\n2. Add A Book\n3. Save and Exit", fileToUse);
                int userInput = MakeItTheRightInt(Console.ReadKey(true).KeyChar.ToString());
                switch (userInput)
                {
                case 1:
                    currentCardCatalog.ListBooks();
                    break;

                case 2:
                    currentCardCatalog.AddBook();
                    break;

                case 3:
                    currentCardCatalog.Save();
                    stillGoing = false;
                    break;

                default:
                    break;
                }
            }
        }
Пример #3
0
        public static bool MainMenu(List <Book> myBooks, string FileName)//all of the methods now are given access to the list myBooks through the argument of the method
        {
            Console.WriteLine("Welcome to the digital library, choose an option:");
            Console.WriteLine("1) List Current Books");
            Console.WriteLine("2) To Add A Book");
            Console.WriteLine("3) To Save and Exit");
            Console.WriteLine("4) To Retrieve List");
            string a = Console.ReadLine();
            int    x;

            int.TryParse(a, out x);


            if (x == 1)
            {
                Console.Clear();
                CardCatalog.ListBooks(myBooks); //when invoking the method ListBooks I need to pass myBooks into the argument
                Console.WriteLine("Press enter to continue.");
                Console.ReadLine();
                Console.Clear();
                return(true);
            }
            else if (x == 2)
            {
                Console.Clear();
                CardCatalog.AddBook(myBooks); // Same deal as ListBooks we need to pass myBooks in the argument
                Console.WriteLine("Press enter to continue.");
                Console.ReadLine();
                Console.Clear();
                return(true);
            }
            else if (x == 3)
            {
                Console.Clear();
                CardCatalog.BookSave(myBooks, FileName);//calling the Save method
                Console.Clear();
                return(false);
            }
            else if (x == 4)
            {
                Console.Clear();
                myBooks = CardCatalog.CallList(FileName);
                Console.WriteLine("Press enter to continue.");
                Console.ReadLine();
                Console.Clear();
                return(true);
            }


            else
            {
                Console.Clear();
                Console.WriteLine("Option not available.");
                Console.WriteLine("Press enter to continue."); // Added this option so if the user puts a random number it won't crash.
                Console.ReadLine();
                Console.Clear();
                return(true);
            }
        }
Пример #4
0
        static private void PromptMenuForUser(CardCatalog cardCatalog)
        {
            int userChoice;

            while (true)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("1. List All Books\n" +
                                  "2. Add A Book\n" +
                                  "3. Save And Exit");

                Console.Write("Input your choice: ");

                if (int.TryParse(Console.ReadLine(), out userChoice))
                {
                    if (userChoice == 1)
                    {
                        //List all the books
                        //replay the menu
                        cardCatalog.ListBooks();
                    }
                    else if (userChoice == 2)
                    {
                        //Add a book to the userfile
                        //replay the menu
                        cardCatalog.AddBook();
                    }
                    else if (userChoice == 3)
                    {
                        //Save all the books added to the userfile
                        //close the menu
                        cardCatalog.Save();
                        break;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Please choose from the above!\n" +
                                          "Thank you!");
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Reads the user's selection and calls the appropriate CardCatalog action
        /// </summary>
        /// <param name="c">current CardCatalog object</param>
        /// <param name="userSelection">User's menu choice (could be 1, 2, or 3.</param>
        private static void RouteUserRequest(CardCatalog c, int userSelection)
        {
            while (userSelection != 3)
            {
                if (userSelection == 1)
                {
                    c.ListBooks();
                }
                else if (userSelection == 2)
                {
                    c.AddBook(c.CreateBook());
                }

                userSelection = GetValidUserInput();
            }
            if (userSelection == 3)
            {
                c.Save();
            }
        }