private void Export() { saveFileDialog.FileName = DateTime.Now.ToString("yyyy-MM-dd"); if (saveFileDialog.ShowDialog() != DialogResult.OK) { return; } TA.ExIm.XmlExporter exporter = new TA.ExIm.XmlExporter(); exporter.SetHeaderInfo(DateTime.Now, Guid.NewGuid().ToString()); ParseTree(exporter, null, mainTreeView.Nodes); string filename = saveFileDialog.FileName; if (saveFileDialog.FilterIndex == 2) { filename = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetFileName(saveFileDialog.FileName), saveFileDialog.DefaultExt)); } TextWriter writer = new StreamWriter(filename); writer.Write(exporter.ToString()); writer.Close(); if (saveFileDialog.FilterIndex == 2) { Zipper.PackFile(filename, saveFileDialog.FileName); } }
private void ParseTree(TA.ExIm.XmlExporter exporter, TreeNode current_node, TreeNodeCollection nodes) { if (current_node != null) { if (current_node.Checked) { if (current_node.Tag is PlayerList) { PlayerList players = current_node.Tag as PlayerList; DatabaseManager.CurrentDb.ReadPlayerList(players); exporter.AddPlayers(players.Values.ToArray()); } if (current_node.Tag is TypeOfSport) { TypeOfSport game = current_node.Tag as TypeOfSport; RatingSystemBuilder rsb = new RatingSystemBuilder(); TA.RatingSystem.RatingSystem rs = RatingSystemBuilder.CreateRatingSystem(game.Id, game.Name); exporter.AddRatingList(game, rs.Players.Values.ToArray()); } if (current_node.Tag is Tournament) { Tournament tour = current_node.Tag as Tournament; List <Competition> comps = new List <Competition>(); foreach (TreeNode node in current_node.Nodes) { if (node.Checked && node.Tag is Competition) { comps.Add(node.Tag as Competition); } } if (comps.Count > 0) { exporter.AddTournament(tour.Info, comps.ToArray()); } } } } foreach (TreeNode node in nodes) { if (nodes.Count > 0) { ParseTree(exporter, node, node.Nodes); } } }