public bool SaveDiscipline(string name, List <string> players, List <string> results) { if (name == null) { Console.WriteLine("Wybierz dyscyplinę"); return(false); } foreach (var a in players) { if (a == string.Empty) { return(false); } } foreach (var a in results) { if (a == string.Empty) { return(false); } } Discipline newDiscipline = new Discipline(name); for (int i = 0; i < players.Count; i++) { Result newResult = new Result(players[i], results[i]); newDiscipline.AddResult(newResult); } competition.AddDiscipline(newDiscipline); return(true); }
public bool LoadCompetition(string path) { competition.ClearCompetition(); XmlDocument document = new XmlDocument(); try { document.Load(path); } catch (Exception) { return(false); } XPathNavigator navigator = document.CreateNavigator(); XPathNodeIterator disciplines = navigator.Select("/Competition/Discipline"); XPathNavigator competitionName = navigator.SelectSingleNode("/Competition/CompetitionName"); competition.CompetitionName = competitionName.Value; XPathNavigator competitionLocation = navigator.SelectSingleNode("/Competition/CompetitionLocation"); competition.CompetitionLocation = competitionLocation.Value; XPathNavigator competitionDate = navigator.SelectSingleNode("/Competition/CompetitionDate"); competition.CompetitionDate = competitionDate.Value; foreach (XPathNavigator d in disciplines) { XPathNavigator nav = d.SelectSingleNode("DisciplineName"); Discipline disc = new Discipline(nav.Value); XPathNodeIterator results = d.Select("Result"); foreach (XPathNavigator r in results) { XPathNavigator nav2 = r.SelectSingleNode("Player"); XPathNavigator nav3 = r.SelectSingleNode("PlayerResult"); Result res = new Result(nav2.Value, nav3.Value); disc.AddResult(res); } competition.AddDiscipline(disc); } Console.WriteLine("Odczytałem z pliku dane"); return(true); }