/*Add Method*/ public void Add(Registrant newSwimmer) { Swimmers.Add(newSwimmer); Number++; bool isAssigned = false; foreach (Club club in ClubManager.Clubs) { if (newSwimmer.Club == club) { isAssigned = true; } } if (!isAssigned && newSwimmer.Club != null) { ClubManager.Add(newSwimmer.Club); } }
public void AddSwimmer(Registrant swimmer) { bool isEntered = true; foreach (Registrant newSwimmer in Swimmers) { if (newSwimmer == swimmer) { isEntered = false; } } if (isEntered == true) { Swimmers.Add(swimmer); swimmer.AddToEvent = this; } else { throw new Exception($"Swimmer {swimmer.Name}, Id No: {swimmer.UniqueId} is already entered"); } }
public void AddSwimmer(Registrant newSwimmer) { //Making the ndex start from one if (NumberOfSwimmers == 0 || Swimmers[NumberOfSwimmers - 1] != newSwimmer) { if (newSwimmer.Club == null || newSwimmer.Club == this) { Swimmers.Add(newSwimmer); NumberOfSwimmers++; // Only Assigning the unassigned Swimmers if (newSwimmer.Club == null) { newSwimmer.Club = this; } } else { throw new Exception(string.Format($"Swimmer already assigned to { newSwimmer.Club.Name} club")); } } }
/*Load Method to load the Swimmers*/ public void Load(string fileName, string delimeter) { FileStream inFile = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(inFile); string recordIn; string[] fields; recordIn = reader.ReadLine(); while (recordIn != null) { try { fields = recordIn.Split(delimeter[0]); Registrant newSwimmer = new Registrant(); // Check the fields CheckUniqueId(fields[0]); CheckName(fields[1]); CheckDOB(fields[2]); CheckPhoneNo(fields[7]); newSwimmer.UniqueId = Int32.Parse(fields[0]); newSwimmer.Name = fields[1]; newSwimmer.DateOfBirth = DateTime.Parse(fields[2]); newSwimmer.Address = new Address(fields[3], fields[4], fields[5], fields[6]); newSwimmer.PhoneNumber = long.Parse(fields[7]); if (fields[8] != "") { int clubNumber = Int32.Parse(fields[8]); if (clubNumber != 0) { for (int i = 0; i < ClubManager.Number; i++) { if (ClubManager.Clubs[i].UniqueId == clubNumber) { ClubManager.Clubs[i].AddSwimmer(newSwimmer); break; } } } } Add(newSwimmer); } catch (Exception exception) { Console.WriteLine($"{exception.Message} \n\t{recordIn}"); } recordIn = reader.ReadLine(); } if (reader != null) { reader.Close(); } if (inFile != null) { inFile.Close(); } }