summaryrefslogtreecommitdiff
path: root/Aktywator/ChooseTournament.cs
blob: 2a7316f700211b737d99d8e6e405dcdf086707e4 (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Aktywator
{
    public struct TournamentListItem
    {
        public int Type;
        public string Name;
        public string Label;
    }

    public partial class ChooseTournament : Form
    {
        private TournamentListItem[] turns;
        public MySQLTournament chosenTournament;

        public ChooseTournament()
        {
            InitializeComponent();
        }

        private void ChooseTournament_Load(object sender, EventArgs e)
        {
            List<TournamentListItem> list = MySQLTournament.getTournaments();
            turns = new TournamentListItem[list.Count];
            int c = 0;
            foreach (TournamentListItem t in list)
            {
                turns[c++] = t;
                listBox.Items.Add(t.Label);
            }
        }

        private void bChoose_Click(object sender, EventArgs e)
        {
            if (listBox.SelectedIndex >= 0)
            {
                switch (turns[listBox.SelectedIndex].Type)
                {
                    case Tournament.TYPE_PARY:
                        chosenTournament = new ParyTournament(turns[listBox.SelectedIndex].Name);
                        break;
                    case Tournament.TYPE_TEAMY:
                        chosenTournament = new TeamyTournament(turns[listBox.SelectedIndex].Name);
                        break;
                }
                Close();
            }
        }

        private void listBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            bChoose_Click(sender, e);
        }
    }
}