public void readTXT_Click(object sender, RoutedEventArgs e) { teamList.Items.Clear(); teams.Clear(); if (File.Exists("../../Players.txt")) { if (File.Exists("../../Players.xml")) { try { using (StreamReader sr = new StreamReader("../../Players.txt", Encoding.Default)) { while (!sr.EndOfStream) { List <Player> players = new List <Player>(); string teamName = Pages.FirstUpper(sr.ReadLine()); foreach (Team team in teams) { if (team.Name == teamName) { MessageBox.Show(" Недопустимо наличие в файле двух команд с одинаковым названием. "); teams.Clear(); players.Clear(); return; } } string coachName = Pages.FirstUpper(sr.ReadLine()); foreach (Team team in teams) { if (team.NameOfCoach == coachName) { MessageBox.Show(" Один тренер не может тренировать две команды. Проверьте информацию в файле. "); teams.Clear(); players.Clear(); return; } } string[] teamStats = sr.ReadLine().Split('-'); int wins = int.Parse(teamStats[0]); int loses = int.Parse(teamStats[1]); sr.ReadLine(); while (true) { string playerName = Pages.FirstUpper(sr.ReadLine()); foreach (Team team in teams) { foreach (Player player in team.Players) { if (player.Name == playerName) { MessageBox.Show(" Недопустимо наличие в файле двух игроков с одинаковым именем. "); teams.Clear(); players.Clear(); return; } } } if (playerName == "") { break; } string[] orgInfo = sr.ReadLine().Split(','); int num = int.Parse(orgInfo[0]); string position = orgInfo[1]; int growth = int.Parse(orgInfo[2]); int weight = int.Parse(orgInfo[3]); int yearOfDraft = int.Parse(sr.ReadLine()); string[] stats = sr.ReadLine().Split(' '); double pts = double.Parse(stats[0]); double rbs = double.Parse(stats[1]); double ast = double.Parse(stats[2]); double stl = double.Parse(stats[3]); double blk = double.Parse(stats[4]); double to = double.Parse(stats[5]); double fg = double.Parse(stats[6]); double ft = double.Parse(stats[7]); double tp = double.Parse(stats[8]); Player p = new Player(playerName, num, position, growth, weight, yearOfDraft, pts, rbs, ast, stl, blk, fg, ft, tp, to); players.Add(p); if (sr.EndOfStream) { break; } } Team t = new Team(teamName, coachName, wins, loses, players); teams.Add(t); } } foreach (Team team in teams) { teamList.Items.Add(team.Name); } using (FileStream fs = new FileStream("../../Players.xml", FileMode.Create)) { formatter.Serialize(fs, teams); } } catch (Exception ex) { MessageBox.Show(ex.Message + " Проверьте корректность данных, введенных в файл. "); } } else { MessageBox.Show(" Указан несуществующий путь xml файла. "); } } else { MessageBox.Show(" Указан несуществующий путь текстового файла. "); } }