Ejemplo n.º 1
0
 public void AddSwimmer(Swimmer aSwimmer)
 {
     if (Club == aSwimmer.Club && !Swimmers.Contains(aSwimmer))
     {
         if (aSwimmer.Coach != this)
         {
             aSwimmer.Coach = this;
         }
         if (!Swimmers.Contains(aSwimmer))
         {
             Swimmers.Add(aSwimmer);
         }
     }
     else if (Club != aSwimmer.Club && Club != null)
     {
         throw new Exception("Coach and swimmer are not in the same club");
     }
     else if (Club == null)
     {
         throw new Exception("Coach is not assigned to a club");
     }
 }
Ejemplo n.º 2
0
        public void EnterSwimmersTime(Registrant aRegistrant, string timeSwam)
        {
            try
            {
                int index = 0;
                foreach (Registrant swimmer in Swimmers)
                {
                    if (aRegistrant == swimmer)
                    {
                        break;
                    }
                    index++;
                }
                TimeSpan time = TimeSpan.ParseExact(timeSwam, "mm':'ss'.'ff", null);
                Swims[index].TimeSwam = time;
            }
            catch (FormatException)
            {
                Console.WriteLine($"Error: {timeSwam} has invalid format");
            }
            catch (OverflowException)
            {
                Console.WriteLine($"Error: {timeSwam} has invalid range of inputs for TimeSpan");
            }
            catch (Exception)
            {
                throw new Exception("Swimmer has not entered event");
            }

            Swimmer aSwimmer = aRegistrant as Swimmer;

            if (aSwimmer != null)
            {
                bool     check     = false;
                TimeSpan timeCheck = TimeSpan.ParseExact(timeSwam, "mm':'ss'.'ff", null);
                if (aSwimmer.BestTimesOfEvents.Count == 0)
                {
                    aSwimmer.BestTimesOfEvents.Add(this);
                    aSwimmer.BestTimes.Add(timeCheck);
                }

                for (int i = 0; i < aSwimmer.BestTimesOfEvents.Count; i++)
                {
                    if ((aSwimmer.BestTimesOfEvents[i].Stroke == Stroke) && (aSwimmer.BestTimesOfEvents[i].Distance == Distance) &&
                        (aSwimmer.BestTimesOfEvents[i].SwimMeet.PoolType == SwimMeet.PoolType))
                    {
                        if (TimeSpan.Compare(aSwimmer.BestTimes[i], timeCheck) == 1)
                        {
                            aSwimmer.BestTimes[i] = timeCheck;
                        }
                        check = false;
                        break;
                    }
                    else if (!check)
                    {
                        check = true;
                    }
                }
                if (check)
                {
                    aSwimmer.BestTimesOfEvents.Add(this);
                    aSwimmer.BestTimes.Add(timeCheck);
                }
            }
        }