예제 #1
0
 public void AddSwimmer(Swimmer swimmer)
 {
     if (!Swimmers.Contains(swimmer))
     {
         if (swimmer.Club == null)
         {
             throw new Exception($"swimmer {swimmer.Name} not assigned club");
         }
         else if (Club == null)
         {
             throw new Exception($"Coach {Name} not assigned club");
         }
         else if (swimmer.Club != Club)
         {
             throw new Exception($"Coach {Name} and swimmer {swimmer.Name} are not in the same club");
         }
         else if (swimmer.Club == Club)
         {
             if (swimmer.Coach == null)
             {
                 swimmer.Coach = this;
             }
             else
             {
                 Swimmers.Add(swimmer);
             }
         }
     }
 }
        public void Load(string filename, string delimiter)
        {
            FileStream   inFile   = new FileStream(filename, FileMode.Open, FileAccess.Read);
            StreamReader reader   = new StreamReader(inFile);
            string       recordIn = reader.ReadLine();

            string[] fields;
            while (recordIn != null)
            {
                fields = recordIn.Split(new string[] { delimiter }, StringSplitOptions.None); //tables from Assignment 2 pdf called for a string delimiter and not a char delimiter
                Registrant newSwimmer;
                uint       swimmerNumber;
                int        clubNumber;
                long       phoneNumber;
                DateTime   birthdate;

                try
                {
                    swimmerNumber = Convert.ToUInt32(fields[0]);
                    birthdate     = Convert.ToDateTime(fields[2]);
                    phoneNumber   = Convert.ToInt64(fields[7]);
                    newSwimmer    = new Swimmer(fields[1], birthdate, new Address(fields[3], fields[4], fields[5], fields[6]), phoneNumber, (int)swimmerNumber);
                    Add(newSwimmer);
                    clubNumber = Convert.ToInt32(fields[8]); //placement of this code is intentional. some swimmers may not have a club, which will trigger an exception here.
                    Club swimmerClub = clubManager.GetByRegNum((uint)clubNumber);
                    swimmerClub.AddSwimmer(newSwimmer);
                }
                catch (FormatException ex)
                {
                    if (ex.ToString().Contains("ToUInt32"))
                    {
                        Console.WriteLine("Invalid swimmer record. Invalid registration number:\n\t{0}", recordIn);
                    }
                    else if (ex.ToString().Contains("ToInt64"))
                    {
                        Console.WriteLine("Invalid swimmer record. Phone number wrong format:\n\t{0}", recordIn);
                    }
                    else if (ex.ToString().Contains("ToDateTime"))
                    {
                        Console.WriteLine("Invalid swimmer record. Birth date is invalid:\n\t{0}", recordIn);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid swimmer record. {0}\n\t{1}", ex.Message, recordIn);
                }
                finally
                {
                    recordIn = reader.ReadLine();
                }
            }
            reader.Close();
            inFile.Close();

            //return null;
        }
예제 #3
0
        public void EnterSwimmersTime(Registrant registrant, string swimTime)
        {
            Swimmer swimmer = registrant as Swimmer;

            if (Registrants.Contains(registrant))
            {
                int  locator           = Registrants.IndexOf(registrant);
                Swim correspondingSwim = Swims[locator] as Swim;
                correspondingSwim.SwimTime = swimTime;
                swimmer.AddAsBestTime(swimMeet.PoolType, Distance, Stroke, TimeSpan.Parse("00:" + swimTime));
                return;
            }
            throw new Exception("Swimmer has not entered event");
        }
예제 #4
0
        public void EnterSwimmersTime(Registrant registrant, string swimTime)
        {
            Swimmer swimmer = registrant as Swimmer;

            for (int i = 0; i < noOfRegistrants; i++)
            {
                if (swimmer.Number == registrants[i].Number)
                {
                    swims[i].SwimTime = swimTime;
                    swimmer.AddAsBestTime(swimMeet.PoolType, Distance, Stroke, TimeSpan.Parse("00:" + swimTime));
                    return;
                }
            }
            throw new Exception("Swimmer has not entered event");
        }
예제 #5
0
 public void AddSwimmer(Swimmer swimmer)
 {
     if (Club == null)
     {
         throw new Exception("Coach is not assigned to a club");
     }
     else if (Club != swimmer.Club)
     {
         throw new Exception("Coach and swimmer are not in the same club");
     }
     else
     {
         Swimmers[NoOfSwimmers] = swimmer;
         NoOfSwimmers++;
         swimmer.Coach = this;
     }
 }
예제 #6
0
        public static List <Registrant> GetRegistrant()
        {
            List <Registrant> swimmers = new List <Registrant>();

            Registrant swimmer1 = new Swimmer("Bob Smith", new DateTime(1970, 01, 01),
                                              new Address("35 Elm St", "Toronto", "ON", "M2M 2M2"), 4161234567);
            Registrant swimmer2 = new Swimmer();

            swimmer2.Address     = new Address("1 King St", "Toronto", "ON", "M2M 3M3");
            swimmer2.Name        = "John Lee";
            swimmer2.PhoneNumber = 4162222222;
            swimmer2.DateOfBirth = new DateTime(1950, 12, 01);

            Registrant swimmer3 = new Swimmer("Ann Smith", new DateTime(1975, 01, 01),
                                              new Address("5 Queen St", "Toronto", "ON", "M2M 4M4"), 4163333333);

            swimmers.Add(swimmer1);
            swimmers.Add(swimmer2);
            swimmers.Add(swimmer3);

            return(swimmers);
        }
예제 #7
0
        public override string ToString()
        {
            string info    = string.Format("Name: {0}\nAddress:\n\t{1}\n\t{2}\n\t{3}\n\t{4}\nPhone: {5}\nReg number: {6}\nSwimmers:", name, address.StreetAddress, address.Municipality, address.Province, address.ZipCode, phoneNumber, number);
            string coaches = "";

            for (int i = 0; i < NoOfRegistrants; i++)
            {
                Swimmer swimmer = registrants[i] as Swimmer;
                if (swimmer != null)
                {
                    info += registrants[i].GetSwimmerName();
                }
                else
                {
                    coaches += registrants[i].GetSwimmerName();
                }
            }

            info += string.Format("\nCoaches: {0}", coaches);

            return(info);
        }
예제 #8
0
        public void AddSwimmer(Swimmer swimmer)
        {
            if (Club == null)
            {
                throw new Exception("Coach is not assigned to a club");
            }
            else if (Club != swimmer.Club)
            {
                throw new Exception("Coach and swimmer are not in the same club");
            }
            else
            {
                Swimmers.Add(swimmer);
                swimmer.Coach = this;
                //string message = "";
                //foreach (Swimmer aswimmer in swimmers)
                //{
                //    message += aswimmer.GetSwimmerName();
                //}

                //throw new Exception(message);
            }
        }