/// <summary> /// this finds the capacity of the cans in question /// if they are entered with ',' seperating them, then if will take every can # entered. /// if no can numbers were entered, it returns an empty list /// Note that this function is very slow. /// </summary> /// <returns></returns> public List <SearchResult> RetrieveCanList(out int numOfCans) { SearchResults searchResults = new SearchResults(); List <SearchResult> results = new List <SearchResult>(); //Case: no can numbers were entered. if (canNum.Equals("*")) { SearchTerm searchTerm = new SearchTerm(canNum, code, animalName, breed, owner, town, state); results = searchResults.retrieveData(searchTerm); numOfCans = results.GroupBy(x => x.CanNum).Count(); return(results); } //Check that query is valid if (IsValidQuery(canNum)) { //split the query by ',' string[] canNumbers = canNum.Split(','); string[] canRange = new string[(canNumbers.Length * 2)]; int j = 0; //split each section by ':' for (int i = 0; i < canNumbers.Length; i++) { string[] temp = canNumbers[i].Split(':'); if (temp.Length > 1) { canRange[j] = temp[0]; canRange[j + 1] = temp[1]; j += 2; //if there is a colon, delete that query from canNumbers canNumbers[i] = ""; } } //get all cans from canNumbers foreach (string number in canNumbers) { if (number != "") { SearchTerm searchTerm = new SearchTerm(number.Trim().ToString(), code, animalName, breed, owner, town, state); results.AddRange(searchResults.retrieveData(searchTerm)); } } for (int i = 0; i < canRange.Length; i += 2) { if (canRange[i] != null) { int begin = Int32.Parse(canRange[i]); int end = Int32.Parse(canRange[i + 1]); if (begin > end) { int temp = begin; begin = end; end = temp; } while (begin <= end) { SearchTerm searchTerm = new SearchTerm(begin.ToString(), code, animalName, breed, owner, town, state); results.AddRange(searchResults.retrieveData(searchTerm)); begin++; } } } numOfCans = results.GroupBy(x => x.CanNum).Count(); return(results); } else { //TODO: tell user the input was invalid numOfCans = 0; return(results); } }