예제 #1
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile  = FileScrubber.ScrubMovies("../../movies.csv");
            string    albumFileName = "../../albums.csv";
            string    bookFileName  = "../../books.csv";
            MovieFile movieFile     = new MovieFile(scrubbedFile);
            AlbumFile albumFile     = new AlbumFile(albumFileName);
            BookFile  bookFile      = new BookFile(bookFileName);

            string choice = "";

            do
            {
                // display choices to user
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display All Movies");
                Console.WriteLine("3) Add Album");
                Console.WriteLine("4) Display All Albums");
                Console.WriteLine("5) Add Book");
                Console.WriteLine("6) Display All Books");
                Console.WriteLine("7) Search Movie titles");
                Console.WriteLine("8) Search Album titles");
                Console.WriteLine("9) Display Book titles");
                Console.WriteLine("Enter to quit");
                // input selection
                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);
                if (choice == "1")
                {
                    // Add movie
                    Movie movie = new Movie();
                    // ask user to input movie title
                    Console.WriteLine("Enter movie title");
                    // input title
                    movie.title = Console.ReadLine();
                    // verify title is unique
                    if (movieFile.isUniqueTitle(movie.title))
                    {
                        // input genres
                        string input;
                        do
                        {
                            // ask user to enter genre
                            Console.WriteLine("Enter genre (or done to quit)");
                            // input genre
                            input = Console.ReadLine();
                            // if user enters "done"
                            // or does not enter a genre do not add it to list
                            if (input != "done" && input.Length > 0)
                            {
                                movie.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (movie.genres.Count == 0)
                        {
                            movie.genres.Add("(no genres listed)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter movie director");
                        input          = Console.ReadLine();
                        movie.director = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter running time
                        Console.WriteLine("Enter running time (h:m:s)");
                        input             = Console.ReadLine();
                        movie.runningTime = input.Length == 0 ? new TimeSpan(0) : TimeSpan.Parse(input);
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                    else
                    {
                        Console.WriteLine("Movie title already exists\n");
                    }
                }
                else if (choice == "2")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    // Add Album
                    Album album = new Album();
                    // ask user to input album title
                    Console.WriteLine("Enter album title");
                    // input title
                    album.title = Console.ReadLine();
                    // verify title is unique
                    if (albumFile.isUniqueTitle(album.title))
                    {
                        // input genres
                        string input;
                        do
                        {
                            // ask user to enter genre
                            Console.WriteLine("Enter genre (or done to quit)");
                            // input genre
                            input = Console.ReadLine();
                            // if user enters "done"
                            // or does not enter a genre do not add it to list
                            if (input != "done" && input.Length > 0)
                            {
                                album.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (album.genres.Count == 0)
                        {
                            album.genres.Add("(no genres listed)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter album artist");
                        input        = Console.ReadLine();
                        album.artist = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter record label
                        Console.WriteLine("Enter record label");
                        input             = Console.ReadLine();
                        album.recordLabel = input.Length == 0 ? "unassigned" : input;
                        // add album
                        albumFile.AddAlbum(album);
                    }
                    else
                    {
                        Console.WriteLine("Album title already exists\n");
                    }
                }
                else if (choice == "4")
                {
                    // Display All Albums
                    foreach (Album a in albumFile.Albums)
                    {
                        Console.WriteLine(a.Display());
                    }
                }
                else if (choice == "5")
                {
                    // Add Book
                    Book book = new Book();
                    // ask user to input book title
                    Console.WriteLine("Enter book title");
                    // input title
                    book.title = Console.ReadLine();
                    // verify title is unique
                    if (bookFile.isUniqueTitle(book.title))
                    {
                        // input genres
                        string input;
                        do
                        {
                            // ask user to enter genre
                            Console.WriteLine("Enter genre (or done to quit)");
                            // input genre
                            input = Console.ReadLine();
                            // if user enters "done"
                            // or does not enter a genre do not add it to list
                            if (input != "done" && input.Length > 0)
                            {
                                book.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (book.genres.Count == 0)
                        {
                            book.genres.Add("(no genres listed)");
                        }
                        // ask user to enter author
                        Console.WriteLine("Enter book author");
                        input       = Console.ReadLine();
                        book.author = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter publisher
                        Console.WriteLine("Enter publisher");
                        input          = Console.ReadLine();
                        book.publisher = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter number of pages
                        Console.WriteLine("Enter number of pages");
                        input          = Console.ReadLine();
                        book.pageCount = input.Length == 0 ? (UInt16)0 : UInt16.Parse(input);
                        // add book
                        bookFile.AddBook(book);
                    }
                    else
                    {
                        Console.WriteLine("Book title already exists\n");
                    }
                }
                else if (choice == "6")
                {
                    // Display All Books
                    foreach (Book b in bookFile.Books)
                    {
                        Console.WriteLine(b.Display());
                    }
                }
                else if (choice == "7")
                {
                    string userChoice = "";
                    do
                    {
                        Console.WriteLine("What Movie title would you like to search for?(or done to quit):");
                        userChoice = Console.ReadLine();
                        var Movies = movieFile.Movies.Where(m => m.title.Contains(userChoice));
                        Console.WriteLine($"There are {Movies.Count()} movies with that name.");
                        foreach (Movie m in Movies)
                        {
                            Console.WriteLine(m.Display());
                        }
                    } while (userChoice != "done");
                }
                else if (choice == "8")
                {
                    string userChoice = "";
                    do
                    {
                        Console.WriteLine("What album title would you like to search for?(or done to quit):");
                        userChoice = Console.ReadLine();
                        var Albums = albumFile.Albums.Where(a => a.title.Contains(userChoice));
                        Console.WriteLine($"There are {Albums.Count()} movies with that name.");
                        foreach (Album a in Albums)
                        {
                            Console.WriteLine(a.Display());
                        }
                    } while (userChoice != "done");
                }
                else if (choice == "9")
                {
                    string userChoice = "";
                    do
                    {
                        Console.WriteLine("What Movie title would you like to search for?(or done to quit):");
                        userChoice = Console.ReadLine();
                        var Books = bookFile.Books.Where(m => m.title.Contains(userChoice));
                        Console.WriteLine($"There are {Books.Count()} movies with that name.");
                        foreach (Book b in Books)
                        {
                            Console.WriteLine(b.Display());
                        }
                    } while (userChoice != "done");
                }
            } while (choice == "1" || choice == "2" || choice == "3" || choice == "4" || choice == "5" || choice == "6" || choice == "7" || choice == "8" || choice == "9");

            logger.Info("Program ended");
        }
예제 #2
0
        public static void Main(string[] args)
        {
            string file   = "../../movies.scrubbed.csv";
            string bkfile = "books.csv";
            string cdfile = "cd.csv";

            logger.Info("Program started");

            MovieFile movieFile = new MovieFile(file);
            BookFile  bookFile  = new BookFile(bkfile);
            AlbumFile albumFile = new AlbumFile(cdfile);
            string    choice    = "";
            string    mchoice   = "";
            string    bchoice   = "";
            string    achoice   = "";

            do
            {
                Console.WriteLine("1) Movie");
                Console.WriteLine("2) Book");
                Console.WriteLine("3) Album");
                Console.WriteLine("Enter to quit");
                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);

                if (choice == "1")
                {
                    do
                    {
                        Console.WriteLine("1) Add Movie");
                        Console.WriteLine("2) Display All Movies");
                        Console.WriteLine("3) Enter to quit");
                        mchoice = Console.ReadLine();
                        logger.Info("User choice: {Choice}", mchoice);
                        if (mchoice == "1")
                        {
                            Movie movie = new Movie();
                            Console.WriteLine("Enter movie title");
                            movie.title = Console.ReadLine();
                            if (movieFile.isUniqueTitle(movie.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit)");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        movie.genres.Add(input);
                                    }
                                } while (input != "done");
                                if (movie.genres.Count == 0)
                                {
                                    movie.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter movie Director");
                                movie.director = Console.ReadLine();
                                Console.WriteLine("Enter running time");
                                movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                                movieFile.AddMovie(movie);
                            }
                            else
                            {
                                Console.WriteLine("Movie title already exists\n");
                            }
                        }
                        else if (mchoice == "2")
                        {
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                    } while (mchoice == "1" || mchoice == "2");
                }
                else if (choice == "2")
                {
                    Console.WriteLine("1) Add Book");
                    Console.WriteLine("2) Display All Books");
                    Console.WriteLine("3) Enter to quit");
                    bchoice = Console.ReadLine();
                    logger.Info("User choice: {Choice}", bchoice);
                    do
                    {
                        if (mchoice == "1")
                        {
                            Book book = new Book();
                            Console.WriteLine("Enter book title");
                            book.title = Console.ReadLine();
                            if (bookFile.isUniqueTitle(book.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        book.genres.Add(input);
                                    }
                                } while (input != "done");

                                if (book.genres.Count == 0)
                                {
                                    book.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter book author");
                                book.author = Console.ReadLine();
                                Console.WriteLine("Enter book publisher");
                                book.publisher = Console.ReadLine();
                                Console.WriteLine("Enter the amount of pages");
                                book.pageCount = UInt16.Parse(Console.ReadLine());
                                bookFile.AddBook(book);
                            }
                            else
                            {
                                Console.WriteLine("Book title already exists\n");
                            }
                        }
                        else if (bchoice == "2")
                        {
                            foreach (Book b in bookFile.Books)
                            {
                                Console.WriteLine(b.Display());
                            }
                        }
                    } while (bchoice == "1" || bchoice == "2");
                }
                else if (choice == "3")
                {
                    Console.WriteLine("1) Add Album");
                    Console.WriteLine("2) Display All Albums");
                    Console.WriteLine("3) Enter to quit");
                    bchoice = Console.ReadLine();
                    logger.Info("User choice: {Choice}", bchoice);
                    do
                    {
                        if (achoice == "1")
                        {
                            Album album = new Album();
                            Console.WriteLine("Enter Album title");
                            album.title = Console.ReadLine();
                            if (albumFile.isUniqueTitle(album.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        album.genres.Add(input);
                                    }
                                } while (input != "done");

                                if (album.genres.Count == 0)
                                {
                                    album.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter album artist");
                                album.artist = Console.ReadLine();
                                Console.WriteLine("Enter record label");
                                album.recordLabel = Console.ReadLine();
                                albumFile.AddAlbum(album);
                            }
                            else
                            {
                                Console.WriteLine("Album title already exists\n");
                            }
                        }
                        else if (achoice == "2")
                        {
                            foreach (Album a in albumFile.Albums)
                            {
                                Console.WriteLine(a.Display());
                            }
                        }
                    } while (achoice == "1" || achoice == "2");
                }
            } while ((choice == "1" || choice == "2" || choice == "3"));
            logger.Info("Program Ended");
        }