/// <summary> /// Adding Items to the user list by importing the list from file. Adding to the list and then saving the list. /// After enter the item the user is returned to the main menu /// </summary> public void AddToListMenu() { MenuDisplaySettings(); ClassLists cL = new ClassLists(); Files files = new Files(); List <Tuple <string, bool> > MyList = files.LoadItem(); Console.WriteLine("\n\tAdd Task Menu"); // Change text Console.Write("Add Something: "); string userInput = Console.ReadLine(); cL.AddThingsToMyList(userInput, MyList); }
/// <summary> /// View menu pulls from the load method > which opens the file location and assigns the list values to "MyList" /// </summary> public void ViewListMenu() { Files files = new Files(); ClassLists classLists = new ClassLists(); List <Tuple <string, bool> > MyList = files.LoadItem(); /// The base that the item numbers in the console display calculate from. int i = 1; /// used to calulate list position int currentPage = 0; int totalPages = (int)Math.Ceiling(MyList.Count() / 25.0); /// To Do bool loopComplete = false; do { /// Menu display clears the console and resets the color to white. MenuDisplaySettings(); /// view list is the text displayed for the user in the console window. ViewList(); int lowerLimit = currentPage * 25; /// the count must consider if there are less than 25 items on the list. The else statement covers the /// range should there be more than 25 items. The code will not run without the first if statement. int count; if (MyList.Count < 25) { count = MyList.Count; } else { /// needs to start with 1 count = (currentPage + 1 == totalPages) ? (MyList.Count - currentPage * 25) : 25; } /// Creates the list of the items currently on the list. Also evaluates if the task is complete. foreach (Tuple <string, bool> item in MyList.GetRange(lowerLimit, count)) { if (item.Item2 == true) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine($"{i++}) {item.Item1}"); } else { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{i++}) {item.Item1}"); } } /// re-sets the counter to one so that the list only displays items 1 - 25 for each page. i = 1; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"\nCurrent Page #{currentPage + 1} of {totalPages}"); Console.WriteLine("---------------------"); // condition next && previous pages Console.WriteLine($"'n') Next Page"); Console.WriteLine($"'p') Previous Page"); Console.Write("\nEnter Your Selection: "); string userInput = Console.ReadLine().ToLower(); try { MenuDisplaySettings(); int intUserInput = Convert.ToInt32(userInput); /// calculates list index position int indexNumber = ((currentPage * 25) + intUserInput) - 1; Console.WriteLine($"\nTask:\t{MyList[indexNumber].Item1}"); Console.WriteLine("\n\n1) Complete"); Console.WriteLine("\n2) Do It Later"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" This Option will mark the item as\n" + " complete and create a Incomplete\n" + " at the end of the list. "); Console.Write("\nPlease make your selection: "); string completeOrDoItLater = Console.ReadLine(); string newTask = MyList[indexNumber].Item1; if (completeOrDoItLater == "1") { classLists.MarkedAsComplete(MyList, indexNumber); Console.WriteLine("\nYour task has been marked complete"); Console.ReadLine(); } else if (completeOrDoItLater == "2") { classLists.MarkedAsComplete(MyList, indexNumber); classLists.AddThingsToMyList(newTask, MyList); Console.WriteLine("\nYour list has been updated"); Console.ReadLine(); } else { continue; } Console.ReadLine(); } catch (Exception) { /// handles next page input if (userInput == "n") { if (currentPage == totalPages) { currentPage = 0; continue; } else { currentPage++; continue; } } /// handles previous page input else if (userInput == "p") { if (currentPage == 0) { currentPage = (totalPages - 1); continue; } else { currentPage--; continue; } } else { loopComplete = true; } //Console.ReadLine(); } /// Previous } while (!loopComplete); Console.ReadLine(); }