public void delete(iTool aTool, int quantity) { iToolCollection currentToolCollection = MainMenu.currentToolType; List <iTool> toolList = currentToolCollection.ToolCollectionList; iTool[] toolArray = currentToolCollection.toArray(); int i = 0; foreach (var tool in toolArray) { if (tool.Name == aTool.Name) { break; } i++; } toolList[i].Quantity = -quantity; }
public void add(iTool aTool, int quantity) //add new pieces of an existing tool to the system { iToolCollection currentToolCollection = MainMenu.currentToolType; List <iTool> toolList = currentToolCollection.ToolCollectionList; iTool[] toolArray = currentToolCollection.toArray(); int i = 0; foreach (var tool in toolArray) { if (tool.Name == aTool.Name) { break; } i++; } toolList[i].Quantity = quantity; }
private static int[] PickTool(bool remove = false, bool noQuantity = false, int numValues = -1) { int number; int toolChoice = 0; int[] existingTool = new int[2]; if (numValues == -1) { numValues = currentToolType.toArray().Length; } string[] prompts = new string[] { $"\nPlease select a tool (1-{numValues}) or 0 to exit: ", $"\nPlease choose a quantity of that tool to edit the Libary or 0 to exit: " }; for (int indexer = 0; indexer < 2; indexer++) { if (indexer == 1 && noQuantity) { existingTool[indexer] = 0; return(existingTool); } Console.Write($"{prompts[indexer]}"); string input = Console.ReadLine(); bool success = Int32.TryParse(input, out number); if (indexer == 1 && number > 0 && success) { if (remove) { if (currentToolType.toArray()[existingTool[toolChoice] - 1].AvailableQuantity < number) { Console.Write($"Your input was incorrect, it should be less than or equal to the " + $"current Avalible Quantity of that Tool\nPress any key to try again... "); Console.ReadKey(); indexer--; } else { existingTool[indexer] = number; } } else { existingTool[indexer] = number; } } else if (success && number <= numValues && number > 0) { existingTool[indexer] = number; } else if (number == 0) { Console.WriteLine($"You have chosen to exit\nPress any key to continue... "); Console.ReadKey(); return(null); } else { Console.Write($"Your input was incorrect, it should be one of the options " + $"(1-{numValues}) or a positve quanintity number\nPress any key to try again... "); Console.ReadKey(); indexer--; } } return(existingTool); }