private static void RunRentalSystem() { MovieCollection = new MovieCollection(); MemberCollection = new MemberCollection(MaxMembers); while (true) { Console.Clear(); switch (WriteWelcome()) { case 0: break; case 1: Console.Clear(); if (StaffLogin()) { Console.Clear(); StaffMenu(); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect Username or Password!\r\n"); Console.ResetColor(); Console.WriteLine("Press enter to return to main menu... "); while (Console.ReadKey().Key != ConsoleKey.Enter) { } } break; case 2: Console.Clear(); Member member = MemberLogin(); if (member != null) { Console.Clear(); MemberMenu(member); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect Username or Password!\r\n"); Console.ResetColor(); Console.WriteLine("Press enter to return to main menu... "); while (Console.ReadKey().Key != ConsoleKey.Enter) { } } break; } } }
/* * parameters: * Movies = This is the movie collection to be passed down and accessed within the Staff class * Members = This is to be passed down to be be accessed within the Staff class * * This displays the Staff Menu options, and this also reads the input of the staff member. * * returns: nothing * */ static void STAFF(MovieCollection Movies, MemberCollection Members) { Console.Clear(); bool truth = true; while (truth) { Console.WriteLine("============Staff Menu==========="); Console.WriteLine("1. Add a new movie DVD"); Console.WriteLine("2. Remove a movie DVD"); Console.WriteLine("3. Register a new Member"); Console.WriteLine("4. Find a registered member's phone number"); Console.WriteLine("0. Return to main menu"); Console.WriteLine("================================"); Console.Write("Please make a selection (1-4, 0 to exit): "); string value = Console.ReadLine(); try { int result = Convert.ToInt32(value); truth = SWITCHSTAFF(result, Movies, Members); } catch { Console.WriteLine("ERROR: Please try again"); Console.WriteLine("Please press 'Enter' to continue..."); Console.ReadLine(); } Console.Clear(); } }
/* * parameters: * result = an integer value to determine the switchcase * Movies = This is the movie collection to be passed down and accessed within the Member object. * * This allows staff to traverse throughout the member menu, depending on the choosen number value they have inputted. * * returns: bool = To determine whenever to break out of the MEMBER menu. */ private bool SWITCHMEMBER(int result, MovieCollection Movies) { switch (result) { case 1: DisplayMovies(Movies); break; case 2: BorrowMovies(Movies); break; case 3: ReturnMovies(Movies); break; case 4: DisplayMovies(this.Movies); break; case 5: DisplayPopularMovies(Movies); break; case 0: return(false); default: throw new Exception(); } return(true); }
/* * paramters: * Movies = This is the movie collection to be passed down and accessed throughout the program * Members = This is to be passed down to be be accessed throughout the program * * displays the Main Menu and allows staff or members to traverse through the system. * * returns: Nothing */ static void MENU(MovieCollection Movies, MemberCollection Members) { int truth = 1; while (truth >= 1) { truth = 1; Console.Clear(); Console.WriteLine("Welcome to the Community Library"); Console.WriteLine("============Main Menu==========="); Console.WriteLine("1. Staff Login"); Console.WriteLine("2. Member Login"); Console.WriteLine("0. Exit"); Console.WriteLine("================================"); Console.Write("Please make a selection (1-2, 0 to exit): "); string value = Console.ReadLine(); try { int result = Convert.ToInt32(value); truth = SWITCHMENU(result, Movies, Members); } catch { Console.WriteLine("ERROR: Please try again"); } Console.WriteLine("Please press any key to continue..."); if (truth == 1) { Console.ReadLine(); } Console.Clear(); } }
/* * parameters: * result = an integer value to determine the switchcase * Movies = The Binary Search Tree to be passed down and accessed. * Members = The array of members to be passed and accessed. * * This allows staff and members to traverse throughout the program, depending on the choosen number value they have inputted. * * returns: int = To determine readline status on the 'MENU' method. * */ public static int SWITCHMENU(int result, MovieCollection Movies, MemberCollection Members) { int release; switch (result) { case 1: Console.Clear(); Staff.LOGIN(Movies, Members); release = 2; break; case 2: Console.Clear(); Member.Login(Members, Movies); release = 2; break; case 0: release = 0; break; default: throw new Exception(); } return(release); }
/* * parameters: * Movies = This is the movie collection to be passed down and accessed within the Member object. * * This displays the most Popular Movies withint the community library depending on view count. * * returns: nothing. */ private void DisplayPopularMovies(MovieCollection Movies) { Console.Clear(); Movies.DisplayMostPopular(); Console.WriteLine("Please press 'Enter' to continue..."); Console.ReadLine(); }
/* * parameters: * result = an integer value to determine the switchcase * Movies = The Binary Search Tree to be passed down and accessed. * Members = The array of members to be passed and accessed. * * This allows staff to traverse throughout the staff menu, depending on the choosen number value they have inputted. * * returns: int = To determine readline status on the 'MENU' method. */ public static bool SWITCHSTAFF(int result, MovieCollection Movies, MemberCollection Members) { switch (result) { case 1: AddMovie(Movies); break; case 2: RemoveMovie(Movies); break; case 3: RegisterMember(Members); break; case 4: MemberSearch(Members); break; case 0: return(false); default: throw new Exception(); } return(true); }
/* * parameters: * Movies = This is the movie collection to be passed down and accessed within the Member object. * * This displays the Member Menu options, and this also reads the input of the logged member. * * returns: nothing */ private void MEMBER(MovieCollection Movies) { Console.Clear(); bool truth = true; while (truth) { Console.WriteLine(string.Format("Welcome '{0}'", FullName)); Console.WriteLine("============Member Menu==========="); Console.WriteLine("1. Display all movies"); Console.WriteLine("2. Borrow a movie DVD"); Console.WriteLine("3. Return a movie DVD"); Console.WriteLine("4. List current borrowed movie DVD's"); Console.WriteLine("5. Display top 10 most popular movies"); Console.WriteLine("0. Return to main menu"); Console.WriteLine("================================"); Console.Write("Please make a selection (1-5, 0 to exit): "); string value = Console.ReadLine(); try { int result = Convert.ToInt32(value); truth = SWITCHMEMBER(result, Movies); } catch { Console.WriteLine("ERROR: Please try again: "); Console.WriteLine("Please press 'Enter' to continue..."); Console.ReadLine(); } Console.Clear(); } }
/* * paramters: None * * Runs main and executes the program. * * returns: Nothing */ static void Main() { MovieCollection Movies = new MovieCollection(); MemberCollection Members = new MemberCollection(); MENU(Movies, Members); }
//Decalre constructor and set all arguments to the object variables. public Member(string givenname, string surname, string residentialaddress, string phonenumber) { this.GivenName = givenname; this.Surname = surname; this.ResidentialAddress = residentialaddress; this.PhoneNumber = phonenumber; this.PasswordSet = false; Username = surname + givenname; FullName = givenname + " " + surname; Movies = new MovieCollection(); }
/* * paramters: * user = The username field. * pass = The password field. * Movies = This is the movie collection to be passed down and accessed within the Staff class * Members = This is to be passed down to be be accessed within the Staff class * * This is to validate if the provided inputs are correct. * * returns: nothing */ public static void LOGINCHECK(string user, string pass, MovieCollection Movies, MemberCollection Members) { if (user == "staff" && pass == "today123") { STAFF(Movies, Members); } else { throw new Exception(); } }
//Function for listing top ten most borrowed movies public void TopTen(MovieCollection movieCollection) { //If the root node is not null if (root != null) { //Setting the topTenMovies array to null topTenMovies = null; //Getting an array of each of the movies root.TopTen(movieCollection); //Sorting the borrowed array into descending order by number of times borrowed BubbleSort(topTenMovies); } }
/* * parameters: * Movies = This is the movie collection to be passed down and accessed within the Member object. * * This displays the Return Movie screen, and this takes in an input and searches for that movie within this member objects collection, and if found * the movie within the members collection will delete that movie found. * * returns: nothing. */ private void ReturnMovies(MovieCollection Movies) { Console.Clear(); Console.WriteLine(""); string value = Staff.LoopEnterCheck("Enter Movie to Return or press 'ENTER' to exit: "); if (value != "") { this.Movies.deleteKey(value, "Returned "); try { Movies.borrowRec(Movies._root, value).copies++; } catch { }// try parse and catch, as Movie might of been deleted from staff; Console.WriteLine(""); Console.WriteLine("Please press 'Enter' to continue..."); Console.ReadLine(); } }
/* * parameter: key = the input value from Readline(), Movies = the movie collection of a Member Object * * This method allows Members to borrow movies from the MovieCollection BST. * * returns: Movie = The movie object from the specific key input from Readline(); */ public Movie borrowKey(string key, MovieCollection Movies) { if (borrowRec(Movies._root, key) == null) { if (Movies.count > 9)//If the Member collection has 10 Movies already. { Console.WriteLine(""); Console.WriteLine("MAXIMUM OF 10 MOVIES ALLOWED"); return(null); } else if (borrowRec(_root, key) == null)//If the Movie does not exist. { Console.WriteLine(""); Console.WriteLine("No records found for " + "`" + key + "'"); return(null); } else {// If the movie exists, increase the view count of that movie, and return that Movie Object. Node contain = borrowRec(_root, key); if (contain.copies > 0) {//If copies exist for this movie. contain.Data.View++; contain.copies--; Node stuffs = new Node(contain.Data, 1); Movie Borrowing = new Movie(stuffs.Data.Title, stuffs.Data.Starring, stuffs.Data.Director, stuffs.Data.Duration, stuffs.Data.Genre, stuffs.Data.Classification, stuffs.Data.ReleaseDate); Borrowing.View = contain.Data.View; Console.WriteLine(""); Console.WriteLine("Borrowed '" + Borrowing.Title + "' from library collection"); return(Borrowing); } else {//If there are no more copies for this movie. Console.WriteLine(""); Console.WriteLine("No more copies for '" + key + "'"); return(null); } } } else {// If the Movie object is already found within the Member collection. Console.WriteLine(""); Console.WriteLine("'" + key + "' already exists in your collection"); return(null); } }
//Function for getting the top ten borrowed movies public void TopTen(MovieCollection movieCollection) { //Adding the current movie node to the borrowed array movieCollection.AddToBorrow(movie); //If the left subtree isn't empty, search through it if (leftNode != null) { //Searching the left subtree leftNode.TopTen(movieCollection); } //If the right subtree isn't empty, search through it if (rightNode != null) { //Searching the right subtree rightNode.TopTen(movieCollection); } }
/* * parameters: * Movies = This is the movie collection to be passed down and accessed within the Member object. * * This displays the Borrow Movie screen, and this takes in an input and searches for that movie within the community library, and if found * the movie within the community libraries collection, it will add that movie. * * returns: nothing. */ private void BorrowMovies(MovieCollection Movies) { Console.Clear(); Console.WriteLine(""); string value = Staff.LoopEnterCheck("Enter Movie to Borrow or press 'ENTER' to exit: "); if (value != "") { Movie MovVal = Movies.borrowKey(value, this.Movies); if (MovVal != null) { this.Movies.Insert(MovVal, true, 1); } Console.WriteLine(""); Console.WriteLine("Please press 'Enter' to continue..."); Console.ReadLine(); } }
/* * paramters: * Movies = This is the movie collection to be passed down and accessed within the Staff class * Members = This is to be passed down to be be accessed within the Staff class * * Authentication for logging into the Staff menu. * * returns: nothing * */ public static void LOGIN(MovieCollection Movies, MemberCollection Members) { Console.WriteLine("Welcome to the Community Library"); Console.WriteLine("============Staff Login==========="); Console.WriteLine("Please Enter Credentials"); Console.WriteLine(""); Console.Write("Username: "******"Password: "******"ERROR: Incorrect Credentials"); Console.ReadLine(); } Console.Clear(); }
private static void DisplayTop10Movies() { Console.Clear(); Movie[] sortedArray = QuickSortSystem.QuickSortArray(MovieCollection.ConvertToArray()); Console.WriteLine("Most Borrowed Movies:\r\n"); for (int i = sortedArray.Length - 1; i >= 0 && i >= sortedArray.Length - 10; i--) { Console.WriteLine("{0}. {1} \t| Borrowed {2} times", sortedArray.Length - i, sortedArray[i].Title, sortedArray[i].NumberOfBorrows); } Console.WriteLine("\r\nPlease press enter to return to member menu... "); while (Console.ReadKey().Key != ConsoleKey.Enter) { } }
/* * parameters: * Movies = Contains a binary search tree of Movie objects that are to be passed and accessed. * * This displays the RemoveMovie function where an input is taken and is searched through the BST of Movies, and promptly deletes that Movie. * * returns: nothing */ public static void RemoveMovie(MovieCollection Movies) { Console.Clear(); Movies.DisplayTree(); bool RemoveCatch = true; while (RemoveCatch) { RemoveCatch = false; Console.Write("Enter Movie Title to remove from Collection or press 'ENTER' to exit: "); string title = Console.ReadLine(); try { if (title != "") { Movies.deleteKey(title, "Removed "); Console.WriteLine(""); Console.WriteLine("press 'ENTER' to continue"); Console.ReadLine(); } } catch { Console.WriteLine("ERROR: Please enter valid input"); RemoveCatch = true; } } }
private static void RemoveDVD() { Console.Clear(); Console.Write("Please enter the name of the DVD you want to delete: "); // Movie to delete Movie deleteMovie = new Movie(); deleteMovie.Title = Console.ReadLine(); MovieCollection.RemoveMovie(deleteMovie); Console.Clear(); Console.WriteLine("{0} removed from the system.\r\n" + "Press enter to return to staff menu... ", deleteMovie.Title); while (Console.ReadKey().Key != ConsoleKey.Enter) { } }
/* * paramater: * Movies = This is the movie collection to be passed down and accessed for the particular member * Members = This is to be passed down to be be accessed for a particular member * * Checks if the member already has a password. * * return: bool = true or false to determine if the password has already been set. */ public static void Login(MemberCollection Members, MovieCollection Movies) { bool flag = false; Console.WriteLine("Welcome to the Community Library"); Console.WriteLine("============Member Login==========="); Console.WriteLine("Please Enter Credentials"); Console.WriteLine(""); Member logged; string user = Staff.LoopCheck("Username (LastnameFirstname): "); string pass = ""; logged = Members.UserSearch(user); try { if (logged.PassRego()) { string value = ""; bool link = true; while (link) { link = false; Console.Write("Set New Password (Must be 4 digits): "); value = Console.ReadLine(); try { if (value == "") { throw new Exception(); } else { if (value.Length != 4) { throw new Exception(); } else { Int32.Parse(value); pass = value; } } } catch { Console.WriteLine("ERROR: Please enter 4 digits"); link = true; } } } else { pass = Staff.LoopCheck("Enter Password: "******"User '{0}' not found", user)); flag = true; } if (!flag) { if (logged.PasswordCheck(pass)) { Console.WriteLine(String.Format("Succesfully Logged in, Welcome {0}, press 'ENTER' to continue", logged.FullName)); Console.ReadLine(); logged.MEMBER(Movies); } else { Console.WriteLine("Password Incorrect press 'ENTER' to exit"); Console.ReadLine(); } } else { Console.ReadLine(); } Console.Clear(); }
/* * parameters: * Movies = Contains a binary search tree of Movie objects that are to be passed and accessed. * * This displays the AddMovie function where several inputs are taken and a new Movie Object is added into the BST. * * returns: nothing */ public static void AddMovie(MovieCollection Movies) { bool truth = true; while (truth) { Console.Clear(); truth = false; string Title; string Starring; string Director; string ReleaseDate = ""; string Genre = ""; string Classification = ""; float Duration = 0; int Copies = 0; Console.WriteLine("============Add Movie==========="); Title = LoopCheck("Enter Title: "); Starring = LoopCheck("Enter Starring Role: "); Director = LoopCheck("Enter Director: "); bool DurationCatch = true; while (DurationCatch) { DurationCatch = false; Console.Write("Enter Duration in hours (e.g 1h30m is 1.5): "); string duration = Console.ReadLine(); try { Duration = float.Parse(duration); } catch { Console.WriteLine("ERROR: Please enter valid input"); DurationCatch = true; } } bool GenreCatch = true; while (GenreCatch) { GenreCatch = false; Console.Write("Enter Genre (Drama, Adventure, Family, Action, Sci-Fi, Comedy, Animated, Thriller, or Other): "); string genre = Console.ReadLine(); try { if (genre == "Drama" || genre == "Adventure" || genre == "Family" || genre == "Action" || genre == "Sci-Fi" || genre == "Comedy" || genre == "Animated" || genre == "Thriller" || genre == "Other") { Genre = genre; } else { throw new Exception(); } } catch { Console.WriteLine("ERROR: Please enter valid input"); GenreCatch = true; } } bool ClassificationCatch = true; while (ClassificationCatch) { ClassificationCatch = false; Console.Write("Enter Classification (General (G), Parental Guidance (PG)), Mature (M15+), Mature Accompanied (MA15+): "); string clas = Console.ReadLine(); try { if (clas == "G" || clas == "PG" || clas == "M15+" || clas == "MA15+") { Classification = clas; } else { throw new Exception(); } } catch { Console.WriteLine("ERROR: Please enter valid input"); ClassificationCatch = true; } } bool ReleaseCatch = true; while (ReleaseCatch) { ReleaseCatch = false; Console.Write("Enter Release Year: "); string year = Console.ReadLine(); try { Int32.Parse(year); ReleaseDate = year; } catch { Console.WriteLine("ERROR: Please enter valid input"); ReleaseCatch = true; } } bool CopiesCatch = true; while (CopiesCatch) { CopiesCatch = false; Console.Write("Enter number of copies: "); string copies = Console.ReadLine(); try { Copies = Int32.Parse(copies); if (Copies <= 0) { throw new Exception(); } } catch { Console.WriteLine("ERROR: Please enter valid input"); CopiesCatch = true; } } Console.WriteLine(""); Console.WriteLine("Title: " + Title); Console.WriteLine("Starring: " + Starring); Console.WriteLine("Directed by: " + Director); Console.WriteLine("Length: " + Duration.ToString() + " hours"); Console.WriteLine("Genre: " + Genre); Console.WriteLine("Classification: " + Classification); Console.WriteLine("Release Date: " + ReleaseDate); Console.WriteLine("Copies: " + Copies); Console.WriteLine(""); bool RestartCatch = true; while (RestartCatch) { RestartCatch = false; Console.Write("Restart (0), Add (1): "); string restart = Console.ReadLine(); try { int value = Int32.Parse(restart); if (value == 0) { truth = true; } else if (value == 1) { Movies.Insert(new Movie(Title, Starring, Director, Duration, Genre, Classification, ReleaseDate), false, Copies); Console.ReadLine(); truth = false; } else { throw new Exception(); } } catch { Console.WriteLine("ERROR: Please enter valid input"); RestartCatch = true; } } } }
private static void AddNewDVD() { Console.Clear(); Movie newMovie; Console.Write("Please enter the movie title: "); String title = Console.ReadLine(); Console.Write("\r\nPlease enter the genre (Drama, Adventure, Family, Action, SciFi, Comedy, Animated, Thriller, Other): "); Genre genre; if (Enum.TryParse <Genre>(Console.ReadLine(), out genre)) { } else { genre = Genre.Other; } Console.Write("\r\nPlease enter the rating (G, PG, M15+, MA15+): "); Rating rating = Rating.G; bool choiceMade = false; while (!choiceMade) { switch (Console.ReadLine()) { case "G": rating = Rating.G; choiceMade = true; break; case "PG": rating = Rating.PG; choiceMade = true; break; case "M15": case "M15+": case "M": rating = Rating.M15; choiceMade = true; break; case "MA15": case "MA15+": case "MA": rating = Rating.MA15; choiceMade = true; break; default: Console.WriteLine("Please enter a valid selection (1-4): "); break; } } Console.Write("\r\nPlease enter the actors starring in this movie: "); String starring = Console.ReadLine(); Console.Write("\r\nPlease enter the director: "); String director = Console.ReadLine(); Console.Write("\r\nPlease enter the duration: "); String duration = Console.ReadLine(); Console.Write("\r\nPlease enter the release date (dd/mm/yyyy): "); DateTime releaseDate = DateTime.MinValue; while (!DateTime.TryParseExact(Console.ReadLine(), "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out releaseDate)) { Console.WriteLine("Please enter a valid date (dd/mm/yyyy): "); } Console.Write("\r\nPlease enter the quantity of DVD's: "); int quantity = 0; while (!int.TryParse(Console.ReadLine(), out quantity)) { Console.WriteLine("Please enter a valid number: "); } newMovie = new Movie(title, genre, rating, starring, director, duration, releaseDate, quantity); MovieCollection.AddMovie(newMovie); Console.Clear(); Console.WriteLine("{0} added to the system.\r\n" + "Press enter to return to staff menu... ", title); while (Console.ReadKey().Key != ConsoleKey.Enter) { } }