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; } }
private void MenuItem_ExportMovies(object sender, RoutedEventArgs e) { var dlg = new SaveFileDialog(); dlg.DefaultExt = ".xml"; dlg.Filter = "XML Files (*.xml)|*.xml"; var result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; var serializer = new XMLSerializer <MovieCollection>(filename); var movieCollection = new MovieCollection(); movieCollection.Movies = MoviesList.ToList(); try { serializer.Serialize(movieCollection); } catch (InvalidOperationException) { return; } } }
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); }
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; } }
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!"); } }
public static void TestAmount(int length) { for (int i = 0; i < length; i++) { MovieCollection.AddMovie(Movie.Random()); } Console.WriteLine("Sorting"); Utils.Test.OrderedTest("QuickSort", Utils.Test.SpeedTest("QuickSort", () => MovieCollection.GetQuickSort()), m => m.GetAllTime()); Console.WriteLine(); }
static void Main(string[] args) { MovieCollection movieCollection = new MovieCollection(); MemberCollection memberCollection = new MemberCollection(); int userOption; // print main menu userOption = MainMenu(); MainMenuOptions(userOption, movieCollection, memberCollection); }
private static void ReturnDVDMember3(MovieCollection movieList, Member member) { Console.Write("Enter movie title: "); string returnTitle = Console.ReadLine(); Movie toBeReturned = movieList.SearchMovie(movieList.root, returnTitle); if (toBeReturned != null) { toBeReturned.ReturnItem(); member.ReturnDVD(toBeReturned); Console.WriteLine("You returned {0}\n", toBeReturned.GetTitle()); } else { Console.WriteLine("Cannot return movie!\n"); } }
private static void BorrowDVDMember2(MovieCollection movieList, Member member) { Console.Write("Enter movie title: "); string borrowTitle = Console.ReadLine(); Movie toBeBorrowed = movieList.SearchMovie(movieList.root, borrowTitle); if (toBeBorrowed != null && toBeBorrowed.GetCopies() != 0) { toBeBorrowed.BorrowItem(); member.RentDVD(toBeBorrowed); Console.WriteLine("You borrowed {0}\n", toBeBorrowed.GetTitle()); } else { Console.WriteLine("Cannot borrow movie!\n"); } }
private void MenuItem_ImportMovies(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".xml"; dlg.Filter = "XML Files (*.xml)|*.xml"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; var deserializer = new XMLSerializer <MovieCollection>(filename); MovieCollection movieCollection = null; try { movieCollection = deserializer.Deserialize(); } catch (InvalidOperationException ex) { return; } if (movieCollection != null) { var movies = movieCollection.Movies; if (movies != null) { foreach (var movie in movies) { MoviesList.Add(movie); } } } } }
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; } }
/// <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; } } }
private static void DisplayTop10Member5(MovieCollection movieList) { movieList.DisplayTop10Borrowed(); Console.WriteLine(); }
private static void DisplayAllDVDMember1(MovieCollection movieList) { movieList.DisplayAllMovies(movieList.root); }
private static void AddMovieStaff1(MovieCollection movieList) { Console.Write("Enter the movie title: "); string title = Console.ReadLine(); Movie checkExist = null; // search only if root is not null if (movieList.root != null) { checkExist = movieList.SearchMovie(movieList.root, title); } // already exists if (checkExist != null) { Console.Write("Enter the number of copies you would like to add: "); Int32.TryParse(Console.ReadLine(), out int addCopies); checkExist.AddCopies(addCopies); Console.WriteLine("Added {0} new copies of {1}\n", addCopies, movieList.SearchMovie(movieList.root, title).GetTitle()); } else { Console.Write("Enter the starring actor(s): "); string starring = Console.ReadLine(); Console.Write("Enter the director(s): "); string director = Console.ReadLine(); Dictionary <int, string> genres = new Dictionary <int, string> { { 1, "Drama" }, { 2, "Adventure" }, { 3, "Family" }, { 4, "Action" }, { 5, "Sci-Fi" }, { 6, "Comedy" }, { 7, "Thriller" }, { 8, "Other" }, }; Console.WriteLine("Select the genre:"); foreach (var pair in genres) { Console.WriteLine("{0}. {1}", pair.Key, pair.Value); } Console.Write("Make selection (1-8): "); Int32.TryParse(Console.ReadLine(), out int selectedGenre); Dictionary <int, string> classifications = new Dictionary <int, string> { { 1, "General (G)" }, { 2, "Parental Guidance (PG)" }, { 3, "Mature (M15+)" }, { 4, "Mature Accompanied (MA15+)" } }; Console.WriteLine("Select the classification:"); foreach (var pair in classifications) { Console.WriteLine("{0}. {1}", pair.Key, pair.Value); } Console.Write("Make selection (1-4): "); Int32.TryParse(Console.ReadLine(), out int selectedClassification); Console.Write("Enter the duration (minutes): "); Int32.TryParse(Console.ReadLine(), out int duration); Console.Write("Enter the release date (year): "); Int32.TryParse(Console.ReadLine(), out int year); Console.Write("Enter the number of copies available: "); Int32.TryParse(Console.ReadLine(), out int copies); Movie newMovie = new Movie (title, director, starring, genres[selectedGenre], classifications[selectedClassification], duration, year, copies); movieList.Insert(newMovie); } }