summaryrefslogtreecommitdiff
path: root/Aktywator/RRBTournament.cs
blob: 20a3c21f542db2417898106603006790a0bb5879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace Aktywator
{
    class RRBTournament : Tournament
    {
        private XmlDocument _xml;
        private string p;

        public RRBTournament(string name)
        {
            this._name = name;
            this._type = Tournament.TYPE_RRB;
        }

        override internal void setup()
        {
            this._xml = new XmlDocument();
            this._xml.Load(this._name);
        }

        override internal string getName()
        {
            return this._xml.SelectSingleNode("//ustawienia/nazwa").InnerText;
        }

        override public string getSectionsNum()
        {
            List<string> sections = new List<string>();
            foreach (XmlNode table in this._xml.SelectNodes("//monitor/stoly/stol"))
            {
                string section = table.SelectSingleNode("sektor").InnerText;
                if (!sections.Contains(section))
                {
                    sections.Add(section);
                }
            }
            return sections.Count.ToString();
        }

        override public string getTablesNum()
        {
            return this._xml.SelectNodes("//monitor/stoly/stol").Count.ToString();
        }

        override internal string getTypeLabel()
        {
            return "RRBridge";
        }

        override internal Dictionary<int, List<string>> getNameList()
        {
            Dictionary<int, List<string>> names = new Dictionary<int, List<string>>();
            foreach (XmlNode pair in this._xml.SelectNodes("//lista/para"))
            {
                int pairNo = Int32.Parse(pair.SelectSingleNode("numer").InnerText);
                names.Add(pairNo, new List<string>());
                foreach (XmlNode player in pair.SelectNodes("gracz/nazwisko"))
                {
                    if ("pauza".Equals(player.InnerText.Trim()))
                    {
                        names[pairNo].Add("");
                    }
                    else
                    {
                        string[] name = player.InnerText.Trim().Split(' ');
                        if (name.Length > 0)
                        {
                            name[0] = (name[0].Length > 0) ? name[0][0].ToString() : "";
                        }
                        names[pairNo].Add(String.Join(" ", name));
                    }
                }
            }

            foreach (KeyValuePair<int, List<string>> pair in names)
            {
                while (pair.Value.Count < 2)
                {
                    pair.Value.Add("");
                }
            }
            return names;
        }
    }
}