Exemple #1
0
        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));
            }
        }
Exemple #2
0
        /// <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;
                }
            }
        }