Beispiel #1
0
 private void LoadFromFile()
 {
     using (TextReader read = File.OpenText(fileName))
     {
         string line;
         while ((line = read.ReadLine()) != null)
         {
             string[] values = line.Split(';');
             if (values.Length == 4)
             {
                 int  id;
                 int  teamID;
                 bool ok = int.TryParse(values[0], out id);
                 if (ok)
                 {
                     ok = int.TryParse(values[3], out teamID);
                     if (ok)
                     {
                         Team team = teamFileRepository.FindOne(teamID);
                         if (!(team is default(Team)))
                         {
                             Player player = new Player(id, values[1], values[2], team);
                             base.Save(player);
                         }
                     }
                 }
             }
         }
     }
 }
        private void LoadFromFile()
        {
            using (TextReader read = File.OpenText(fileName))
            {
                string line;
                while ((line = read.ReadLine()) != null)
                {
                    string[] values = line.Split(';');
                    if (values.Length == 4)
                    {
                        int  id;
                        bool ok = int.TryParse(values[0], out id);
                        if (ok)
                        {
                            int idFirstTeam;
                            ok = int.TryParse(values[1], out idFirstTeam);
                            if (ok)
                            {
                                Team team = teamFileRepository.FindOne(idFirstTeam);
                                if (!(team is default(Team)))
                                {
                                    int idSecondTeam;
                                    ok = int.TryParse(values[2], out idSecondTeam);

                                    if (ok)
                                    {
                                        Team teamTwo = teamFileRepository.FindOne(idSecondTeam);
                                        if (!(teamTwo is default(Team)))
                                        {
                                            DateTime data;
                                            ok = DateTime.TryParse(values[3], out data);
                                            Game game = new Game(id, team, teamTwo, data);
                                            base.Save(game);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }