bool checkIDValidity(List <Individual> individuals, TroopVisit troopVisit, Individual.SexEnum sex, string ID) { bool valid = true; int dummy = 0; // Valid if of form troopid + sex + number, length 4 and not already in use valid &= ID.StartsWith(troopVisit.Troop.TroopID + sex.ToString()) || ID.StartsWith(troopVisit.Troop.TroopID + sex.ToString()); valid &= int.TryParse(ID.Substring(2, 2), out dummy); valid &= ID.Length == 4; //foreach (Individual i in individuals) //{ // if (i.ID == ID) // valid = false; //} return(valid); }
public static string GenerateNewTrappingId(List <Individual> individuals, TroopVisit troopVisit, Individual.SexEnum sex) { // ID should be of the form troopid sex number string newId = troopVisit.Troop.TroopID + sex.ToString(); //Determine the highest number for this troop + sex combination int number = 0; foreach (Individual i in individuals) { if (i.ID.StartsWith(newId)) { int idNumber = int.Parse(i.ID.Substring(2, 2)); if (number <= idNumber) { number = idNumber + 1; } } } return(newId + number.ToString("D2")); }