Пример #1
0
        public static void Main(string[] args)
        {
            BookCatalog[] objBook = new BookCatalog[1];
            int           userChoice;

            //menu

            Console.WriteLine("Welcome to the Brogrammer Library\n");

            do
            {
                Console.WriteLine("1)Display Book List");
                Console.WriteLine("2)Search by Title or Author");
                Console.WriteLine("3)Return Book");
                Console.WriteLine("4)Checkout Book");
                Console.WriteLine("5) Exit");
                //Console.WriteLine("Please Press 1 to load the data");
                Console.Write("Enter Choice (1 - 5):");
                userChoice = Convert.ToInt32(Console.ReadLine());

                switch (userChoice)
                {
                //Displays List Of Books
                case 1:
                    BookCatalog.LoadData(ref objBook);     //pass by reference

                    BookCatalog.DisplayAllBooks(objBook);  //pass by value

                    break;

                //Search by Title or Author
                case 2:
                    BookCatalog.LoadData(ref objBook);     //pass by reference
                    Console.WriteLine("Please enter an author or book title");
                    BookCatalog.BookSearchAuthorOrTitle(ref objBook);
                    Console.WriteLine("___________________________");
                    break;

                case 3:
                    BookCatalog.ReturnBook(ref objBook);

                    break;

                case 4:
                    BookCatalog.BookCheckout(ref objBook);
                    break;


                default:
                    break;
                }
            } while (userChoice != 5);
        }
Пример #2
0
        //RETURN BOOKS
        public static void ReturnBook(ref BookCatalog[] objBooks)
        {
            // StreamWriter write = new StreamWriter("Books.txt"); // Allows you to write over

            //writ(objBooks.Length + 1); // Allows to write a new book to text file

            Console.WriteLine("Thank you for choosing the Brogrammer's Library. To return your book press any key...");
            Console.ReadKey();

            BookCatalog temp = new BookCatalog(); // creates new object of book

            Console.WriteLine("Enter Title: ");
            temp.Title = Console.ReadLine(); // takes user input and store it in the variable

            Console.WriteLine("Enter Author: ");
            temp.Author = Console.ReadLine(); // takes user input and store it in the variable

            //Console.WriteLine("Enter Book Number: ");
            //temp.BookNumberInCatalog = Convert.ToInt32(Console.ReadLine()); // takes user input and store it in the variable

            Console.WriteLine("Enter Status: ");
            temp.Status = Console.ReadLine(); // takes user input and store it in the variable

            //write new data to text file

            System.IO.File.WriteAllText(@"C:\Users\Student\Documents\Visual Studio 2015\Projects\MidTermProject_Brogrammers\MidTermProject_Brogrammers/Books.txt", temp.Title);
            System.IO.File.WriteAllText(@"C:\Users\Student\Documents\Visual Studio 2015\Projects\MidTermProject_Brogrammers\MidTermProject_Brogrammers/Books.txt", temp.Author);
            System.IO.File.WriteAllText(@"C:\Users\Student\Documents\Visual Studio 2015\Projects\MidTermProject_Brogrammers\MidTermProject_Brogrammers/Books.txt", temp.Status);
            // write.WriteLine(temp.Title);
            //write.WriteLine(temp.Author);
            //write.WriteLine(temp.BookNumberInCatalog);
            //write.WriteLine(temp.Status);

            ////put old Books back in the text file
            //for (int i = 0; i < objBooks.Length; i++)
            //{
            //    write.WriteLine(objBooks[i].Title);
            //    write.WriteLine(objBooks[i].Author);
            //    write.WriteLine(objBooks[i].BookNumberInCatalog);
            //    write.WriteLine(objBooks[i].Status);

            //}
            //write.Flush();
            //write.Close(); // close the file after the write

            LoadData(ref objBooks); // updates the array
        }
Пример #3
0
        //METHODS

        //LOADS THE DATA FROM TEXTFILE


        public static void LoadData(ref BookCatalog[] objBook)
        {
            StreamReader reader = new StreamReader("Books.txt"); //setting up stream reader
            int          size   = Convert.ToInt32(reader.ReadLine());

            objBook = new BookCatalog[size]; //dynamic array

            for (int i = 0; i < objBook.Length; i++)
            {
                objBook[i] = new BookCatalog();
                //objBook[i].BookNumberInCatalog = Convert.ToInt16(reader.ReadLine());
                objBook[i].Title  = reader.ReadLine();
                objBook[i].Author = reader.ReadLine();
                objBook[i].Status = reader.ReadLine();
            }

            reader.Close();


            //DESPLAYS ALL BOOKS TO SCREEN
        }