//Adds movie to inventory public static void Add(String line) { String[] d = line.Split('#'); bool stock; if (d[4] == "yes") { stock = true; } else { stock = false; } Movie movieToAdd = new Movie(int.Parse(d[0]), d[1], d[2], int.Parse(d[3]), stock); MovieFile mf = new MovieFile(); Movie[] oldInv = mf.ReadFile(); mf.IncrementCount(); int count = mf.GetCount(); Movie[] updatedInventory = new Movie[count]; //Assigns updatedInventory movies to oldInv movies (thru count - 1). //Assigns last value of updatedInventory to movieToAdd and writes moviefile with updatedInventory. for (int i = 0; i < count - 1; i++) { updatedInventory[i] = oldInv[i]; } updatedInventory[count - 1] = movieToAdd; Console.WriteLine($"\nAdded movie: {movieToAdd.ReadString()}"); mf.WriteFile(updatedInventory); }
//Removes movie from inventory public static void Delete(String line) { MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); int id = int.Parse(line.Split('#')[0]); int index = Program.GetMovieIndex(inv, id); inv[index].SetStock(); Movie removie = inv[index]; inv = Program.RemoveMovieFromArray(inv, inv[index]); mf.DecrementCount(); mf.WriteFile(inv); RemovedFile rf = new RemovedFile(); Movie[] oldRemoved = rf.ReadFile(); rf.IncrementCount(); int count = rf.GetCount(); Movie[] updatedRemoved = new Movie[count]; for (int i = 0; i < count - 1; i++) { updatedRemoved[i] = oldRemoved[i]; } updatedRemoved[count - 1] = removie; Console.WriteLine($"\nRemoved movie: {removie.ReadString()}"); rf.WriteFile(updatedRemoved); }
//Changes line in inventory public static void Change(String line) { MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); String[] delin = line.Split('#'); int id = int.Parse(delin[0]); int index = Program.GetMovieIndex(inv, id); if (delin[1].Length > 0) { inv[index].SetTitle(delin[1]); } if (delin[2].Length > 0) { inv[index].SetGenre(delin[2]); } if (delin[3].Length > 0) { inv[index].SetReleaseYear(int.Parse(delin[3])); } if (delin[4].Length > 0) { inv[index].SetStock(delin[4]); } Console.WriteLine($"\nUpdated movie: {inv[index].ReadString()}"); mf.WriteFile(inv); }
//Reads through movie inventory and removed inventory and returns movie that matches id parameter public static Movie GetMovie(int id) { MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); for (int i = 0; i < inv.Length; i++) { if (inv[i].GetMovieID() == id) { return(inv[i]); } } RemovedFile rf = new RemovedFile(); Movie[] rem = rf.ReadFile(); for (int i = 0; i < rem.Length; i++) { if (rem[i].GetMovieID() == id) { return(rem[i]); } } Console.WriteLine("\tError: Movie with ID = " + id + " Not Found"); Movie blankMovie = new Movie(); return(blankMovie); }
//Reads through movie inventory and removed inventory and returns the next movie id public static int GetNextID() { int max = 0; MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); for (int i = 0; i < inv.Length; i++) { if (inv[i].GetMovieID() > max) { max = inv[i].GetMovieID(); } } RemovedFile rf = new RemovedFile(); Movie[] rem = rf.ReadFile(); for (int i = 0; i < rem.Length; i++) { if (rem[i].GetMovieID() > max) { max = rem[i].GetMovieID(); } } return(max + 1); }
//Prompts suer for id and returns movie. Updates inventory and adds return date to transactions public static void ReturnMovie() { Console.Clear(); Console.WriteLine("\nRETURN MOVIE\n"); TransactionFile tf = new TransactionFile(); Transaction[] transList = tf.ReadFile(); string email = ViewRentedMovies(); int index = -1; int id = -1; while (index == -1) { Console.WriteLine("\nEnter movie ID of movie to return: "); string input = Console.ReadLine(); if (input.All(char.IsNumber)) { id = int.Parse(input); index = GetTransactionIndex(transList, id); if (index == -1) { Console.WriteLine("\tError: Movie not found."); } } else { Console.WriteLine("\tError: Enter only numeric values."); } } String[] dateDelin = DateTime.Now.ToString().Split(' '); String returnDate = dateDelin[0]; transList[index].SetReturnDate(returnDate); tf.WriteFile(transList); MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); index = Program.GetMovieIndex(inv, id); inv[index].SetStock(); Console.WriteLine($"\nReturned movie: {inv[index].ReadString()}"); mf.WriteFile(inv); }
//Prints movies in stock public static void StockedMovies() { Console.Clear(); Console.WriteLine("\nIN STOCK MOVIES\n"); MovieFile mf = new MovieFile(); Movie[] inv = mf.ReadFile(); for (int i = 0; i < mf.GetCount(); i++) { if (inv[i].GetStock()) { Console.WriteLine(inv[i].ReadString()); } } }
//Prints available movies public static void ViewAvailableMovies() { Console.WriteLine("\nAVAILABLE MOVIES\n"); Console.WriteLine("\tMovie ID\t|\tTitle\t\t\t|\tGenre\t\t|\tRelease Year"); Console.WriteLine("\t--------------------------------------------------------------------------------------------"); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); for (int i = 0; i < movieInventory.Length; i++) { if (movieInventory[i].GetStock()) { if (movieInventory[i].GetTitle().Length < 9) { Console.WriteLine($"\t{movieInventory[i].GetMovieID()}\t\t|\t{movieInventory[i].GetTitle()}\t\t\t|\t{movieInventory[i].GetGenre()}\t\t|\t{movieInventory[i].GetReleaseYear()}"); } else { Console.WriteLine($"\t{movieInventory[i].GetMovieID()}\t\t|\t{movieInventory[i].GetTitle()}\t\t|\t{movieInventory[i].GetGenre()}\t\t|\t{movieInventory[i].GetReleaseYear()}"); } } } }
//Prompts user for email and prints each movie rented by that email public static string ViewRentedMovies() { Console.WriteLine("\nEnter email address: "); String email = Console.ReadLine(); Console.WriteLine("\nRENTED MOVIES\n"); Console.WriteLine("\n\tTransaction ID\t|\tMovie ID\t|\tDate Rented|\tTitle\t"); Console.WriteLine("\t-------------------------------------------------------------------------------------"); TransactionFile tf = new TransactionFile(); Transaction[] transList = tf.ReadFile(); MovieFile mf = new MovieFile(); Movie[] movieInv = mf.ReadFile(); for (int i = 0; i < transList.Length; i++) { if (transList[i].GetEmail() == email) { if (transList[i].GetReturnDate() == "Not Returned") { string rented = transList[i].GetRentDate(); int transID = transList[i].GetTransID(); int movieID = transList[i].GetMovieID(); int index = Program.GetMovieIndex(movieInv, movieID); string title = movieInv[index].GetTitle(); string space = "\t\t|\t"; Console.WriteLine($"\t{transID}{space}{movieID}{space}{rented}{space}{title}"); } } } return(email); }
//Prompts user for info of movie to remove public static void RemoveMovie() { Console.Clear(); Console.WriteLine("\nREMOVE MOVIE\n"); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); mf.DecrementCount(); int index = -1; while (index == -1) { index = PromptForMovie(movieInventory, "remove"); if (!movieInventory[index].GetStock()) { Console.WriteLine("\tError: Selected movie is unavailable. Please select a different movie."); index = -1; } } String str = movieInventory[index].ToString(); Delete(str); }
//Prompts user for id and rents movie. Updates inventory and adds to transactions public static void RentMovie() { Console.Clear(); Console.WriteLine("\nRENT MOVIE\n"); String input; int id; int index = -1; TransactionFile tf = new TransactionFile(); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); ViewAvailableMovies(); Console.WriteLine("\nEnter email address: "); String email = Console.ReadLine(); while (index == -1) { Console.WriteLine("\nEnter movie ID to rent:\t(Enter 0 to input movie title instead)"); input = Console.ReadLine(); if (input.All(char.IsNumber)) { id = int.Parse(input); if (id == 0) { Console.WriteLine("\nEnter movie title to rent: "); input = Console.ReadLine(); index = Program.GetMovieIndex(movieInventory, input); } else { index = Program.GetMovieIndex(movieInventory, id); } if (index == -1) { Console.WriteLine("\tError: Movie not found."); } } else { Console.WriteLine("\tError: Enter only numeric values."); } if (index != -1) { if (movieInventory[index].GetStock() == false) { Console.WriteLine("\tError: Selected movie is unavailable. Please select a different movie."); index = -1; } } } movieInventory[index].SetStock(); mf.WriteFile(movieInventory); String[] dateDelin = DateTime.Now.ToString().Split(' '); String rentDate = dateDelin[0]; Transaction[] transactions = tf.ReadFile(); tf.IncrementCount(); Transaction newTransaction = new Transaction(tf.GetID(), email, movieInventory[index].GetMovieID(), rentDate); int count = tf.GetCount(); Transaction[] updatedTransactions = new Transaction[count]; for (int i = 0; i < count - 1; i++) { updatedTransactions[i] = transactions[i]; } updatedTransactions[updatedTransactions.Length - 1] = newTransaction; Console.WriteLine($"\nRented movie: {movieInventory[index].ReadString()}"); tf.WriteFile(updatedTransactions); }
//Prompts user for info of movie to add public static void AddMovie() { Console.Clear(); Console.WriteLine("\nADD MOVIE\n"); //Read moviefile and instantiate inventory. MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); mf.SetNextID(); int id = mf.GetID(); String title, genre, input; int genreChc = 0; int year = -1; bool stock = true; //Set title Console.WriteLine("\nEnter movie title: "); title = Console.ReadLine(); //Set genre while (genreChc < 1 || genreChc > 6) { Console.WriteLine("\nEnter genre choice: "); Console.WriteLine("\t(1) Action"); Console.WriteLine("\t(2) Family"); Console.WriteLine("\t(3) Horror"); Console.WriteLine("\t(4) Sci-Fi"); Console.WriteLine("\t(5) Comedy"); Console.WriteLine("\t(6) Other"); input = Console.ReadLine(); if (input.All(char.IsNumber)) { genreChc = int.Parse(input); if (genreChc < 1 || genreChc > 6) { Console.WriteLine("\tError: Enter value between 1 and 6"); } } else { Console.WriteLine("\tError: Enter only numeric values"); } } genre = GENRES[genreChc - 1]; //Set year while (year == -1) { Console.WriteLine("\nEnter movie release year: "); input = Console.ReadLine(); if (input.All(char.IsNumber)) { year = int.Parse(input); } else { Console.WriteLine("\tError: Enter only numeric values"); } } //Creates instance of Movie with id, title, genre, year, and stock assigned. //Updates moviefile count +1 and creates new Movie array updatedInventory that is of size count. Movie newMovie = new Movie(id, title, genre, year, stock); String str = newMovie.ToString(); Add(str); }
//Prompts user for info to change on movie and edits it public static void EditMovie() { Console.Clear(); Console.WriteLine("\nEDIT MOVIE\n"); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); int index = PromptForMovie(movieInventory, "edit"); Movie movieToEdit = movieInventory[index]; String input = ""; Console.WriteLine("\t(1) Title:\t\t" + movieToEdit.GetTitle()); Console.WriteLine("\t(2) Genre:\t\t" + movieToEdit.GetGenre()); Console.WriteLine("\t(3) Release Year:\t" + movieToEdit.GetReleaseYear()); Console.WriteLine("\t(4) Stock:\t\t" + movieToEdit.GetStock()); int choice = 0; while (choice < 1 || choice > 4) { choice = Program.ValidInput(4); } switch (choice) { case 1: Console.WriteLine("\nEnter new movie title: "); input = Console.ReadLine(); movieToEdit.SetTitle(input); break; case 2: int genreChc = 0; while (genreChc < 1 || genreChc > 6) { Console.WriteLine("\nEnter genre choice: \n\t(1) Action\n\t(2) Family\n\t(3) Horror\n\t(4) Sci-Fi\n\t(5) Comedy\n\t(6) Other"); input = Console.ReadLine(); genreChc = Program.ValidInput(6); } string genre = GENRES[genreChc - 1]; movieToEdit.SetGenre(genre); break; case 3: int year = -1; while (year == -1) { Console.WriteLine("\nEnter new release year: "); input = Console.ReadLine(); if (input.All(char.IsNumber)) { year = int.Parse(input); } else { Console.WriteLine("\tError: Enter only numeric values"); } } movieToEdit.SetReleaseYear(year); break; case 4: movieToEdit.SetStock(); break; } Console.WriteLine($"\nUpdated movie: {movieToEdit.ReadString()}"); movieInventory[index] = movieToEdit; mf.WriteFile(movieInventory); }