public FrmTournamentPlayers(TournamentPlayersEventArgs e)
        {
            InitializeComponent();
            myArgs = e;

            Text = e.Name + " -- Enroll Players";
            lstAvailable.BeginUpdate();
            lstEnrolled.BeginUpdate();
            lstAvailable.Columns[0].ImageIndex = 0;
            lstEnrolled.Columns[0].ImageIndex = 0;

            if (Enrolled != null)
                foreach (var id in e.Enrolled)
                {
                    var player = Config.Settings.GetPlayer(id.Key);
                    var item = new ListViewItem { Name = player.ID, Text = player.Name };
                    item.SubItems.Add(player.Hometown);
                    item.SubItems.Add(id.Value.ToString());
                    item.SubItems.Add(e.ChosenFactions[player.ID].ToString());
                    lstEnrolled.Items.Add(item);
                }

            foreach (PlayerRecord player in Config.Settings.Players)
            {
                if (lstEnrolled.Items.ContainsKey(player.ID)) continue;
                var item = new ListViewItem { Name = player.ID, Text = player.Name };
                item.SubItems.Add(player.Hometown);
                lstAvailable.Items.Add(item);

            }

            lblTotal.Text = "Total Players Enrolled: " + lstEnrolled.Items.Count.ToString();
            lstAvailable.Sort();
            lstEnrolled.Sort();
            lstAvailable.EndUpdate();
            lstEnrolled.EndUpdate();
        }
        private void PlayersAdded(object sender, TournamentPlayersEventArgs e)
        {
            lstEvents.BeginInvoke(new MethodInvoker(delegate
                {
                    if (!e.Cancel)
                    {
                        Tournament tournament = Config.Settings.GetTournament(e.Name);
                        int index = Config.Settings.Tournaments.IndexOf(tournament);

                        Config.Settings.Tournaments[index].Players = e.Enrolled;
                        Config.Settings.Tournaments[index].PlayerFaction = e.ChosenFactions;
                        Config.Settings.SaveEvents();

                        if (lstEvents.Items.ContainsKey(tournament.Name))
                            lstEvents.Items[tournament.Name].SubItems[4].Text = e.Enrolled.Count.ToString();

                        if (e.Enrolled.Count > 0 && Config.Settings.OpenAfterPlayersAdded)
                        {
                            foreach (ListViewItem item in lstEvents.Items)
                            {
                                if (item.Text == e.Name)
                                {
                                    item.Selected = true;
                                    break;
                                }
                            }
                            openEventToolStripMenuItem_Click(this, new EventArgs());
                        }
                    }
                    ActivePlayersWindows.Remove((FrmTournamentPlayers)sender);
                    return;
                }));
        }
        private void inputPlayersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Tournament tournament = Config.Settings.GetTournament(lstEvents.SelectedItems[0].Text);
            var args = new TournamentPlayersEventArgs(tournament.Name, tournament.Players, tournament.PlayerFaction,
                                                      PlayersAdded);
            foreach (FrmTournamentPlayers active in ActivePlayersWindows)
            {
                if (active.TournamentName == tournament.Name)
                {
                    active.WindowState = FormWindowState.Normal;
                    active.Focus();
                    return;
                }
            }

            var dialog = new FrmTournamentPlayers(args);
            dialog.MdiParent = MdiParent;
            dialog.Show();
            ActivePlayersWindows.Add(dialog);
        }
        private void btnNewEvent_Click(object sender, EventArgs e)
        {
            var selectedType = EventType.Unknown;
            using (var typeDialog = new frmEventType())
            {
                if (typeDialog.ShowDialog() == DialogResult.Cancel) return;
                selectedType = typeDialog.Value;
            }

            if (selectedType == EventType.Tournament)
            {
                Tournament tournament = null;
                while (true)
                {
                    using (var dialog = new frmTournamentOptions(tournament))
                    {
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            tournament = dialog.Tournament;

                            League checkLeague = Config.Settings.GetLeague(dialog.Name);
                            Tournament checkTournament = Config.Settings.GetTournament(dialog.Name);
                            if (checkTournament != null || checkLeague != null)
                                if (MessageBox.Show("An event with the name \"" + tournament.Name + "\" already " +
                                                    "exists. Event names must be unique.", "Validation Error",
                                                    MessageBoxButtons.RetryCancel,
                                                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) ==
                                    DialogResult.Cancel)
                                    return;
                                else
                                    continue;

                            Config.Settings.Tournaments.Add(tournament);
                            Config.Settings.SaveEvents();

                            lstEvents.BeginUpdate();

                            var item = new ListViewItem();
                            item.Name = tournament.Name;
                            item.Text = tournament.Name;
                            item.SubItems.Add("Tournament");
                            item.SubItems.Add(tournament.Location);
                            item.SubItems.Add(tournament.Date.ToShortDateString());
                            item.SubItems.Add(tournament.Players.Count.ToString());
                            item.SubItems.Add("Not Started");
                            lstEvents.Items.Add(item);

                            lstEvents.Sort();
                            lstEvents.EndUpdate();

                            // Show the Add Players screen if wanted.
                            if (!btnShowAddPlayers.Checked) return;
                            var args = new TournamentPlayersEventArgs(tournament.Name, tournament.Players, tournament.PlayerFaction,
                                                                      PlayersAdded);

                            var addPlayersDialog = new FrmTournamentPlayers(args);
                            addPlayersDialog.MdiParent = MdiParent;
                            addPlayersDialog.Show();
                            ActivePlayersWindows.Add(addPlayersDialog);

                            return;
                        }
                        else
                            return;
                    }
                }
            }
            else if (selectedType == EventType.League)
            {
                League league = null;
                while (true)
                {
                    using (var dialog = new frmLeagueOptions(league))
                    {
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            league = dialog.League;
                            League checkLeague = Config.Settings.GetLeague(dialog.Name);
                            Tournament checkTournament = Config.Settings.GetTournament(dialog.Name);
                            if (checkTournament != null || checkLeague != null)
                                if (MessageBox.Show("An event with the name \"" + league.Name + "\" already " +
                                                    "exists. Event names must be unique.", "Validation Error",
                                                    MessageBoxButtons.RetryCancel,
                                                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) ==
                                    DialogResult.Cancel)
                                    return;
                                else
                                    continue;

                            Config.Settings.Leagues.Add(league);
                            Config.Settings.SaveEvents();

                            lstEvents.BeginUpdate();

                            var item = new ListViewItem();
                            item.Name = league.Name;
                            item.Text = league.Name;
                            item.SubItems.Add("League");
                            item.SubItems.Add(league.Location);
                            item.SubItems.Add(league.StartDate.ToShortDateString());
                            item.SubItems.Add(league.Players.Count.ToString());
                            item.SubItems.Add("Not Started");
                            lstEvents.Items.Add(item);

                            lstEvents.Sort();
                            lstEvents.EndUpdate();

                            return;
                        }
                        else
                            return;
                    }
                }
            }
        }