Exemplo n.º 1
0
 public void AddSwimmer(Registrant swimmer)
 {
     if (swimmer.Club != this && swimmer.Club != null)
     {
         throw (new Exception($"Swimmer {swimmer.Name} already assigned to {swimmer.Club.Name} club"));
     }
     else if (swimmer.Club == null)
     {
         swimmers.Add(swimmer);
         swimmer.Club = this;
     }
     else if (swimmer.Club == this && !swimmers.Contains(swimmer))
     {
         swimmers.Add(swimmer);
     }
 }
Exemplo n.º 2
0
 public void AddSwimmer(Registrant swimmer)
 {
     if (swimmers.Contains(swimmer))
     {
         throw (new Exception($"Swimmer {swimmer.Name}, {swimmer.RegNumber} is already entered"));
     }
     else
     {
         swimmer.SwimMeetInfo.Add(new List <int> {
             MySwimMeet, (int)Stroke, (int)Distance
         });
         if (swimmer.SwimMeetInfo.Count > swimmer.SwimTimeSpan.Count)
         {
             swimmer.SwimTimeSpan.Add(new TimeSpan());
         }
         swimmers.Add(swimmer);
     }
 }
        public void Save(string filename, string delimiter)
        {
            FileStream   outFile = new FileStream(filename, FileMode.Create, FileAccess.Write);
            StreamWriter writer  = new StreamWriter(outFile);

            for (int i = 0; i < Number; i++)
            {
                Registrant reg  = swimmers[i];
                string     line = reg.Number + delimiter + reg.Name + delimiter + reg.DateOfBirth + delimiter;
                line += reg.Address.StreetAddress + delimiter + reg.Address.Municipality + delimiter + reg.Address.Province + delimiter + reg.Address.ZipCode + delimiter;
                line += reg.PhoneNumber + delimiter;
                if (reg.Club != null)
                {
                    line += reg.Club.Number;
                }
                writer.WriteLine(line);
            }
            writer.Close();
            outFile.Close();
        }
Exemplo n.º 4
0
 public void Add(Registrant aSwimmer)
 {
     if (aSwimmer.Name == "")
     {
         throw new Exception("Invalid swimmer name:");
     }
     else if (GetByRegNum((uint)aSwimmer.Number) != null)
     {
         throw new Exception("Swimmer with the registration number already exists:");
     }
     else
     {
         if (aSwimmer.Club != null)
         {
             Club checker = clubManager.GetByRegNum((uint)aSwimmer.Club.Number);
             if (checker == null)
             {
                 clubManager.Add(aSwimmer.Club);
             }
         }
         swimmers.Add(aSwimmer);
     }
 }
Exemplo n.º 5
0
 public void AddSwimmer(Registrant aRegistrant)
 {
     aRegistrant.Club = this;
 }
        public void Load(string fileName, string delimeter)
        {
            char         deli = Convert.ToChar(delimeter);
            string       record;
            FileStream   fileIn = null;
            StreamReader reader = null;

            try
            {
                fileIn = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                reader = new StreamReader(fileIn);

                record = reader.ReadLine();
                while (record != null)
                {
                    string[] fields = record.Split(deli);
                    int      regNumber;
                    DateTime dateTime;
                    long     phoneNumber;
                    int      clubNumber;
                    try
                    {
                        try
                        {
                            regNumber = Convert.ToInt32(fields[0]);
                        }
                        catch (Exception)
                        {
                            throw new Exception($"Invalid swimmer record. Invalid registration number:\n         {record}");
                        }
                        try
                        {
                            dateTime = Convert.ToDateTime(fields[2]);
                        }
                        catch (Exception)
                        {
                            throw new Exception($"Invalid swimmer record. Birth date is invalid:\n         {record}");
                        }
                        try
                        {
                            phoneNumber = Convert.ToInt64(fields[7]);
                        }
                        catch (Exception)
                        {
                            throw new Exception($"Invalid swimmer record. Phone number wrong format:\n         {record}");
                        }
                        if (fields[1] == "")
                        {
                            throw new Exception($"Invalid swimmer record. Invalid swimmer name: \n         {record}");
                        }

                        Registrant result = new Registrant(regNumber, fields[1], dateTime, new Address(fields[3], fields[4], fields[5], fields[6]), phoneNumber);
                        // assign the corresponding club to swimmer
                        //if (fields[8] != "")
                        //{
                        //    clubNumber = Convert.ToInt32(fields[8]);
                        //    result.Club = clmg.GetByRegNum(clubNumber);
                        //}
                        if (GetByRegNum(regNumber) == null)
                        {
                            Swimmers.Add(result);
                        }
                        else
                        {
                            throw new Exception($"Invalid Swimmer record. Swimmer with the registration number already exists:\n         {record}");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        record = reader.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (fileIn != null)
                {
                    fileIn.Close();
                }
            }
        }