コード例 #1
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static string MemberLogin(MovieCollection movieList, MemberCollection memberList)
        {
            Console.Write("\nEnter username (LastnameFirstname): ");
            string username = Console.ReadLine();

            int userID = -1;

            while (userID < 0)
            {
                for (int i = 0; i < memberList.GetNumMembers(); i++)
                {
                    if (memberList.GetMember(i).GetUsername() == username)
                    {
                        userID = i;
                        break;
                    }
                }
                if (userID < 0)
                {
                    Console.Write("Wrong username! Enter username: "******"Enter Password: "******"Wrong password! Enter password: ");
                inputPass = Console.ReadLine();
            }
            return(username);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void MainMenuOptions(int option, MovieCollection movieList, MemberCollection memberList)
        {
            switch (option)
            {
            case 1:
                // login method
                bool staffLoggedIn = StaffLogin(new Staff("staff", "today123"));
                if (staffLoggedIn)
                {
                    StaffMenuOptions(movieList, memberList);
                }
                break;

            // member login
            case 2:
                if (memberList.GetNumMembers() > 0)
                {
                    string user = MemberLogin(movieList, memberList);
                    MemberMenuOptions(movieList, memberList, user);
                }
                else
                {
                    Console.WriteLine("No members registered!");
                    MainMenuOptions(MainMenu(), movieList, memberList);
                }
                break;

            default:
                // user press 0 to exit
                Console.WriteLine("Goodbye!");
                break;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void StaffMenuOptions(MovieCollection movieList, MemberCollection memberList)
        {
            StaffMenu();
            Int32.TryParse(Console.ReadLine(), out int staffOption);
            switch (staffOption)
            {
            case 0:     //return to main menu
                MainMenuOptions(MainMenu(), movieList, memberList);
                break;

            case 1:     // add a new movie dvd
                AddMovieStaff1(movieList);
                StaffMenuOptions(movieList, memberList);
                break;

            case 2:     // remove movie dvd
                RemoveMovieStaff2(movieList, memberList);
                StaffMenuOptions(movieList, memberList);
                break;

            case 3:     // register new member
                AddMemberStaff3(memberList);
                StaffMenuOptions(movieList, memberList);
                break;

            case 4:     // find a registered member's phone number
                MemberContactStaff4(memberList);
                StaffMenuOptions(movieList, memberList);
                break;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void RemoveMovieStaff2(MovieCollection movieList, MemberCollection memberList)
        {
            Console.Write("Enter movie title: ");
            string removeTitle = Console.ReadLine();
            Movie  checkExist  = null;

            // search only if root is not null
            if (movieList.root != null)
            {
                checkExist = movieList.SearchMovie(movieList.root, removeTitle);
            }

            if (checkExist != null)
            {
                for (int i = 0; i < memberList.GetNumMembers(); i++)
                {
                    memberList.GetMember(i).ReturnDVD(checkExist);
                }
                movieList.Remove(checkExist);
                Console.WriteLine("You removed {0}", checkExist.GetTitle());
            }
            else
            {
                Console.WriteLine("No movies to remove!");
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        static void Main(string[] args)
        {
            MovieCollection  movieCollection  = new MovieCollection();
            MemberCollection memberCollection = new MemberCollection();

            int userOption;

            // print main menu
            userOption = MainMenu();
            MainMenuOptions(userOption, movieCollection, memberCollection);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void MemberContactStaff4(MemberCollection memberList)
        {
            Console.Write("Enter member's first name: ");
            string first = Console.ReadLine();

            Console.Write("Enter member's last name: ");
            string last = Console.ReadLine();

            if (memberList.GetPhoneNumber(first, last) != 0)
            {
                Console.WriteLine("{0} {1}'s phone number is: {2}", first, last, memberList.GetPhoneNumber(first, last));
            }
            else
            {
                Console.WriteLine("User does not exist!");
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void AddMemberStaff3(MemberCollection members)
        {
            Console.Write("Enter member's first name: ");
            string first = Console.ReadLine();

            Console.Write("Enter member's last name: ");
            string last = Console.ReadLine();

            // check if user exists
            int memberExists = -1;

            for (int i = 0; i < members.GetNumMembers(); i++)
            {
                Member memberToCheck = members.GetMember(i);
                // already exists
                if (first == memberToCheck.GetFirstName() && last == memberToCheck.GetLastName())
                {
                    memberExists = i;
                    break;
                }
            }
            if (memberExists >= 0) // exist
            {
                Console.WriteLine("{0} {1} has already registered.", first, last);
            }
            else // does not exist
            {
                Console.Write("Enter member's address: ");
                string address = Console.ReadLine();
                Console.Write("Enter member's phone number: ");
                Int32.TryParse(Console.ReadLine(), out int phone);
                Console.Write("Enter member's password (4 digits): ");

                string password = Console.ReadLine();
                int    pass;
                while (!Int32.TryParse(password, out pass) || (pass > 9999 && pass < 0) || password.Length != 4)
                {
                    Console.Write("Needs to be 4 digit : ");
                    password = Console.ReadLine();
                }
                members.RegisterMember(new Member(first, last, address, phone, pass));
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Wesleyzxc/MovieConsoleApp
        private static void MemberMenuOptions(MovieCollection movieList, MemberCollection memberList, string user)
        {
            Member loggedInUser = memberList.GetMember(user);

            MemberMenu();
            Int32.TryParse(Console.ReadLine(), out int memberOption);
            switch (memberOption)
            {
            case 1:     // display all dvds
                DisplayAllDVDMember1(movieList);
                MemberMenuOptions(movieList, memberList, user);
                break;

            case 2:     // borrow a dvd
                BorrowDVDMember2(movieList, loggedInUser);
                MemberMenuOptions(movieList, memberList, user);
                break;

            case 3:     // return a dvd
                ReturnDVDMember3(movieList, loggedInUser);
                MemberMenuOptions(movieList, memberList, user);
                break;

            case 4:     // list current borrowed dvd
                ListBorrowedMember4(loggedInUser);
                MemberMenuOptions(movieList, memberList, user);
                break;

            case 5:     // display top 10 most popular dvd
                DisplayTop10Member5(movieList);
                MemberMenuOptions(movieList, memberList, user);
                break;

            case 0:     // return main menu
                MainMenuOptions(MainMenu(), movieList, memberList);
                break;
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Davina-T/CAB301
        /// <summary>
        /// Calls all the methods and runs the program
        /// </summary>
        static void RunProgram()
        {
            // Initialise MemberCollection
            MemberCollection member_collection = new MemberCollection();

            // Initialise MovieCollection
            MovieCollection movie_collection = new MovieCollection();

            string username;

            while (true)
            {
                // Main menu screen
                int main_menu_selection = MainMenu();

                // Staff menu
                if (main_menu_selection == 1)
                {
                    bool login_success = StaffLogin();
                    while (login_success)
                    {
                        isInStaffMenu = true;
                        while (isInStaffMenu)
                        {
                            int staff_menu_selection = StaffMenu();

                            // if choice is 0 then return to main menu
                            if (staff_menu_selection == 0)
                            {
                                isInStaffMenu = false;
                                login_success = false;
                            }
                            // if choice is 1 then add a movie
                            else if (staff_menu_selection == 1)
                            {
                                // Get move title
                                Console.WriteLine("Enter the movie title: ");
                                string movie_title = Console.ReadLine();

                                // Check if the movie already exists
                                if (movie_collection.HasMovie(movie_title))
                                {
                                    // Add more copies
                                    Console.WriteLine("Enter the number of copies you would like to add: ");
                                    string copies_added_input = Console.ReadLine();

                                    int copies_added = Int32.Parse(copies_added_input);

                                    movie_collection.searchMovie(movie_title, movie_collection.Root).Data.num_copies_available      += copies_added;
                                    movie_collection.searchMovie(movie_title, movie_collection.Root).Data.original_copies_available += copies_added;

                                    Console.ForegroundColor = ConsoleColor.Green;
                                    if (copies_added > 1)
                                    {
                                        Console.WriteLine("\nAdded {0} more copies of {1}", copies_added, movie_title);
                                    }
                                    else if (copies_added == 1)
                                    {
                                        Console.WriteLine("\nAdded {0} more copy of {1}", copies_added, movie_title);
                                    }
                                    else
                                    {
                                        Console.WriteLine("\nNo copies were added");
                                    }
                                    Console.ResetColor();
                                }
                                else
                                {
                                    // Add a new movie
                                    Movie movie = generateAddMovie(movie_title);
                                    movie_collection.AddMovie(movie);

                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine("\nSuccessfully added {0}", movie_title);
                                    Console.ResetColor();
                                }
                            }
                            // if choice is 2 then remove a movie
                            else if (staff_menu_selection == 2)
                            {
                                Movie movie = generateRemoveMovie();

                                // Check if the movie exists
                                if (!movie_collection.HasMovie(movie.movie_title))
                                {
                                    PrintColorMessage(ConsoleColor.Red, "\nThat movie does not exist in the library");
                                }
                                // Check if all movies have been returned before removing it
                                else if (movie_collection.searchMovie(movie.movie_title, movie_collection.Root).Data.num_copies_available != movie_collection.searchMovie(movie.movie_title, movie_collection.Root).Data.original_copies_available)
                                {
                                    PrintColorMessage(ConsoleColor.Red, "\nNot all copies have been returned!");
                                }
                                else
                                {
                                    // Remove the movie
                                    movie_collection.RemoveMovie(movie);

                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine("\nSuccessfully removed {0}", movie.movie_title);
                                    Console.ResetColor();
                                }
                            }
                            // if choice is 3 then register a member
                            else if (staff_menu_selection == 3)
                            {
                                isInStaffMenu = member_collection.RegisterMember();
                            }
                            // if choice is 4 then find a member's phone number
                            else if (staff_menu_selection == 4)
                            {
                                member_collection.FindPhoneNumber();
                            }
                        }
                    }

                    // Member menu
                }
                else if (main_menu_selection == 2)
                {
                    bool login_success = member_collection.MemberLogin();
                    if (login_success)
                    {
                        username = member_collection.getUserName(); // get the current member's username
                        while (true)
                        {
                            int member_menu_selection = MemberMenu();

                            // if choice is 0 then return to main menu
                            if (member_menu_selection == 0)
                            {
                                break;
                            }
                            // if choice is 1 then display all movies
                            else if (member_menu_selection == 1)
                            {
                                movie_collection.DisplayMovies(movie_collection.Root);
                            }
                            // if choice is 2 then borrow a movie
                            else if (member_menu_selection == 2)
                            {
                                Console.WriteLine("Enter movie title: ");
                                string name = Console.ReadLine();

                                // Check if the movie exists
                                if (!movie_collection.HasMovie(name))
                                {
                                    PrintColorMessage(ConsoleColor.Red, "\nThat movie does not exist in the library");
                                }
                                else
                                {
                                    // Check if the movie still has copies available
                                    if (movie_collection.searchMovie(name, movie_collection.Root).Data.num_copies_available > 0)
                                    {
                                        // Check if the member has already borrowed it
                                        if (member_collection.getMemberByName(username).CheckBorrowed(name))
                                        {
                                            PrintColorMessage(ConsoleColor.Red, "\nYou're already borrowing this movie!");
                                        }
                                        // or else borrow the movie
                                        else
                                        {
                                            // check if the user has borrowed 10 movies
                                            if (member_collection.getMemberByName(username).movies_borrowed < 10)
                                            {
                                                member_collection.getMemberByName(username).BorrowMovie(movie_collection.searchMovie(name, movie_collection.Root).Data);

                                                movie_collection.searchMovie(name, movie_collection.Root).Data.num_copies_available--;
                                                movie_collection.searchMovie(name, movie_collection.Root).Data.num_times_borrowed++;
                                                member_collection.getMemberByName(username).movies_borrowed++;

                                                Console.ForegroundColor = ConsoleColor.Green;
                                                Console.WriteLine("\nYou have borrowed {0}", name);
                                                Console.ResetColor();
                                            }
                                            else
                                            {
                                                PrintColorMessage(ConsoleColor.Red, "\nYou can only borrow 10 movies");
                                            }
                                        }
                                    }
                                    // No more copies available
                                    else
                                    {
                                        PrintColorMessage(ConsoleColor.Red, "\nThere are no more copies available.");
                                    }
                                }
                            }
                            // if choice is 3 then return a movie
                            else if (member_menu_selection == 3)
                            {
                                Console.WriteLine("Enter movie title: ");
                                string name = Console.ReadLine();

                                // Check if the movie exists
                                if (!movie_collection.HasMovie(name))
                                {
                                    PrintColorMessage(ConsoleColor.Red, "\nThat movie does not exist in the library");
                                }
                                // Check if the user has borrowed the movie
                                else if (!member_collection.getMemberByName(username).CheckBorrowed(name))
                                {
                                    PrintColorMessage(ConsoleColor.Red, "\nYou are not currently borrowing this movie.");
                                }
                                else
                                {
                                    // Return the movie
                                    member_collection.getMemberByName(username).ReturnMovie(movie_collection.searchMovie(name, movie_collection.Root).Data);
                                    movie_collection.searchMovie(name, movie_collection.Root).Data.num_copies_available++;
                                    member_collection.getMemberByName(username).movies_borrowed--;

                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine("\nYou have returned {0}", name);
                                    Console.ResetColor();
                                }
                            }
                            // if choice is 4 then list borrowed movies
                            else if (member_menu_selection == 4)
                            {
                                member_collection.getMemberByName(username).ListBorrowedMovies();
                            }
                            // if choice is 5 then display top 10 most popular movies
                            else if (member_menu_selection == 5)
                            {
                                movie_collection.DisplayTopTenMovies();
                            }
                        }
                    }


                    // Exit program
                }
                else if (main_menu_selection == 0)
                {
                    ExitProgram();
                    break;
                }
            }
        }