public string PriorityInitial(Item.Priority priority) { string initial = ""; switch (priority) { case Item.Priority.High: initial = "H"; break; case Item.Priority.Medium: initial = "M"; break; case Item.Priority.Low: initial = "L"; break; } return(initial); }
internal static void AddNewItem(MenuDisplay menu, ListDisplay list) { string NewItemName = ""; Item.Category NewItemCategory = new Item.Category(); Item.Priority NewItemPriority = new Item.Priority(); list.DisplayCurrentList(ItemsList.UserShoppingList); bool valid = false; bool duplicate = true; do { duplicate = false; menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); menu.ActionPrompt.Add("Enter Item Name:"); menu.ActionInstructions(menu.ActionPrompt); Console.SetCursorPosition(MenuDisplay.InstDisplay + 2, menu.ActionPromptInitLine + 1); NewItemName = Console.ReadLine(); /*Duplicate Detector*/ for (int i = 0; i < ItemsList.UserShoppingList.Count; ++i) { if (ItemsList.UserShoppingList[i].Name.ToUpper() == NewItemName.ToUpper()) { menu.StatusUpdate(); menu.StatusUpdate($"{NewItemName} is already on the list. ", MenuDisplay.ActionStatus.ActionFailure); duplicate = true; break; } if (duplicate == true) { break; } } if (duplicate == true) { continue; } if (NewItemName.Length > ListDisplay.CatCol - ListDisplay.itemNumCol /*Name Col*/ - 2) { menu.StatusUpdate(); menu.StatusUpdate($"Your item name is too long. " + $"Max {ListDisplay.CatCol - ListDisplay.itemNumCol /*Name Col*/ - 2} only", MenuDisplay.ActionStatus.ActionFailure); continue; } valid = true; }while (valid == false || duplicate == true); menu.StatusUpdate(); menu.StatusUpdate(MenuDisplay.DefaultStatus); valid = false; while (valid == false) { menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); menu.ActionPrompt.Add($"Name: {NewItemName}"); menu.ActionPrompt.Add($" "); for (int i = 0; i < Item.catList.Count(); ++i) { menu.ActionPrompt.Add($"{i + 1}: {Item.catList[i]}"); } menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add("Your Choice: "); menu.ActionInstructions(menu.ActionPrompt); char charInput = Console.ReadKey().KeyChar; if (!int.TryParse(charInput.ToString(), out int catInput)) { menu.StatusUpdate(); menu.StatusUpdate($"Please enter a whole Number.", MenuDisplay.ActionStatus.ActionFailure); continue; } if (catInput > 7 || catInput <= 0) { menu.StatusUpdate(); menu.StatusUpdate($"Number {charInput} is out of range.", MenuDisplay.ActionStatus.ActionFailure); continue; } NewItemCategory = Item.catList[catInput - 1]; valid = true; } menu.StatusUpdate(); menu.StatusUpdate(MenuDisplay.DefaultStatus); valid = false; while (valid == false) { menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); menu.ActionPrompt.Add($"Name: {NewItemName}"); menu.ActionPrompt.Add($"Category: {NewItemCategory.ToString()}"); menu.ActionPrompt.Add($" "); for (int i = 0; i < Item.prioList.Count(); ++i) { menu.ActionPrompt.Add($"{menu.PriorityInitial(Item.prioList[i])}: {Item.prioList[i]}"); } menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add("Your Choice: "); menu.ActionInstructions(menu.ActionPrompt); string stringInput = Console.ReadKey().KeyChar.ToString().ToUpper(); if (stringInput != "H" && stringInput != "M" && stringInput != "L") { menu.StatusUpdate(); menu.StatusUpdate($"Please Select 'H', 'M', or 'L'", MenuDisplay.ActionStatus.ActionFailure); continue; } switch (stringInput) { case "H": NewItemPriority = Item.Priority.High; break; case "M": NewItemPriority = Item.Priority.Medium; break; case "L": NewItemPriority = Item.Priority.Low; break; } valid = true; } menu.StatusUpdate(); Item item = new Item(NewItemName, NewItemCategory, NewItemPriority); ItemsList.UserShoppingList.Add(item); list.DisplayCurrentList(ItemsList.UserShoppingList); menu.StatusUpdate($"Item {NewItemName} has been added to list.", MenuDisplay.ActionStatus.ActionSuccess); Save(); menu.ActionInstructionsClear(); }
internal static void EditItem(MenuDisplay menu, ListDisplay list) { string NewItemName = ""; Item.Category NewItemCategory = new Item.Category(); Item.Priority NewItemPriority = new Item.Priority(); list.DisplayCurrentList(ItemsList.UserShoppingList); IndexFilter(menu, "Which Item # do you want to edit?", out int itemNumIndex, out bool exit); if (exit == true) { return; } menu.StatusUpdate(); Item selectedItem = ItemsList.UserShoppingList[itemNumIndex]; ItemSpecs(selectedItem, menu, list); /*Do not reset yet*/ /*Name*/ bool valid = false; bool duplicate = true; do { duplicate = false; menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); ItemSpecs(selectedItem, menu, list); menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add($"New Name: "); menu.ActionInstructions(menu.ActionPrompt); string input = Console.ReadLine(); for (int i = 0; i < ItemsList.UserShoppingList.Count; ++i) { if (ItemsList.UserShoppingList[i].Name == NewItemName) { menu.StatusUpdate(); menu.StatusUpdate($"{NewItemName} is already on the list. ", MenuDisplay.ActionStatus.ActionFailure); duplicate = true; break; } if (duplicate == true) { break; } } if (duplicate == true) { continue; } if (NewItemName.Length > ListDisplay.CatCol - ListDisplay.itemNumCol /*Name Col*/ - 2) { menu.StatusUpdate(); menu.StatusUpdate($"Your item name is too long. " + $"Max {ListDisplay.CatCol - ListDisplay.itemNumCol /*Name Col*/ - 2} only", MenuDisplay.ActionStatus.ActionFailure); continue; } NewItemName = input; valid = true; }while (valid == false || duplicate == true); int inputSpaces = NewItemName.Count(char.IsWhiteSpace); if (NewItemName.Length == inputSpaces || NewItemName == string.Empty) { NewItemName = selectedItem.Name; } selectedItem.Name = NewItemName; menu.StatusUpdate(); menu.StatusUpdate(MenuDisplay.DefaultStatus); /*Category*/ valid = false; while (valid == false) { menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); ItemSpecs(selectedItem, menu, list); menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add($"New Name: {selectedItem.Name}"); menu.ActionPrompt.Add($" "); for (int i = 0; i < Item.catList.Count(); ++i) { menu.ActionPrompt.Add($"{i + 1}: {Item.catList[i]}"); } menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add("New Category: "); menu.ActionInstructions(menu.ActionPrompt); char charInput = Console.ReadKey().KeyChar; if (charInput == ' ' || charInput == '\r') { NewItemCategory = selectedItem.category; valid = true; break; } if (!int.TryParse(charInput.ToString(), out int catInput)) { menu.StatusUpdate(); menu.StatusUpdate($"Please enter a whole Number.", MenuDisplay.ActionStatus.ActionFailure); continue; } if (catInput > 7 || catInput <= 0) { menu.StatusUpdate(); menu.StatusUpdate($"Number {charInput} is out of range.", MenuDisplay.ActionStatus.ActionFailure); continue; } NewItemCategory = Item.catList[catInput - 1]; valid = true; } selectedItem.category = NewItemCategory; menu.StatusUpdate(); menu.StatusUpdate(MenuDisplay.DefaultStatus); //Priority valid = false; while (valid == false) { menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); ItemSpecs(selectedItem, menu, list); menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add($"New Name: {selectedItem.Name}"); menu.ActionPrompt.Add($"New Category: {selectedItem.category}"); menu.ActionPrompt.Add($" "); for (int i = 0; i < Item.prioList.Count(); ++i) { menu.ActionPrompt.Add($"{menu.PriorityInitial(Item.prioList[i])}: {Item.prioList[i]}"); } menu.ActionPrompt.Add($" "); menu.ActionPrompt.Add("Your Choice: "); menu.ActionInstructions(menu.ActionPrompt); string stringInput = Console.ReadKey().KeyChar.ToString().ToUpper(); if (stringInput == " " || stringInput == "\r") { NewItemPriority = selectedItem.priority; valid = true; break; } if (stringInput != "H" && stringInput != "M" && stringInput != "L") { menu.StatusUpdate(); menu.StatusUpdate($"Please Select 'H', 'M', or 'L'", MenuDisplay.ActionStatus.ActionFailure); continue; } switch (stringInput) { case "H": NewItemPriority = Item.Priority.High; break; case "M": NewItemPriority = Item.Priority.Medium; break; case "L": NewItemPriority = Item.Priority.Low; break; } valid = true; } selectedItem.priority = NewItemPriority; //ifPurchased if (ItemsList.UserShoppingList[itemNumIndex].IsPurchased == true) { int indexAtPurchList = ItemsList.UserPurchasedList.IndexOf(ItemsList.UserShoppingList[itemNumIndex]); ItemsList.UserPurchasedList[indexAtPurchList].Name = NewItemName; ItemsList.UserPurchasedList[indexAtPurchList].category = NewItemCategory; ItemsList.UserPurchasedList[indexAtPurchList].priority = NewItemPriority; } //Finalize menu.ActionInstructionsClear(); menu.ActionPrompt.Clear(); menu.StatusUpdate(); list.DisplayCurrentList(ItemsList.UserShoppingList); menu.StatusUpdate($"Item {selectedItem.Name} has been successfully edited.", MenuDisplay.ActionStatus.ActionSuccess); Save(); }