コード例 #1
0
        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;
                    }
                }
            }
        }
コード例 #2
0
        private void editOptionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstEvents.SelectedItems[0].SubItems[1].Text == "Tournament")
            {
                Tournament tournament = Config.Settings.GetTournament(lstEvents.SelectedItems[0].Text);
                using (var dialog = new frmTournamentOptions(tournament, false))
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        int index = Config.Settings.Tournaments.IndexOf(tournament);
                        Config.Settings.Tournaments[index] = dialog.Tournament;
                        Config.Settings.SaveEvents();

                        lstEvents.BeginUpdate();

                        lstEvents.SelectedItems[0].Text = tournament.Name;
                        lstEvents.SelectedItems[0].SubItems[2].Text = tournament.Location;
                        lstEvents.SelectedItems[0].SubItems[3].Text = tournament.Date.ToShortDateString();
                        lstEvents.SelectedItems[0].SubItems[4].Text = tournament.Players.Count.ToString();
                        if (tournament.Rounds.Count == 0)
                            lstEvents.SelectedItems[0].SubItems[5].Text = "Not Started";
                        else if (tournament.Rounds.Count == tournament.TotalRounds &&
                                 tournament.Rounds[tournament.TotalRounds - 1].Completed)
                            lstEvents.SelectedItems[0].SubItems[5].Text = "Finished";
                        else
                        {
                            int roundNum = tournament.Rounds.Count;
                            if (tournament.Rounds[roundNum - 1].Completed)
                                lstEvents.SelectedItems[0].SubItems[5].Text = "Round " + roundNum.ToString() +
                                                                              " of " +
                                                                              tournament.TotalRounds.ToString() +
                                                                              " Done";
                            else
                                lstEvents.SelectedItems[0].SubItems[5].Text = "Round " + roundNum.ToString() +
                                                                              " of " +
                                                                              tournament.TotalRounds.ToString() +
                                                                              " Active";
                        }

                        lstEvents.Sort();
                        lstEvents.EndUpdate();
                    }
                }
            }
            else
            {
                var pastReference = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                League league = Config.Settings.GetLeague(lstEvents.SelectedItems[0].Text);
                using (var dialog = new frmLeagueOptions(league, false))
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        int index = Config.Settings.Leagues.IndexOf(league);
                        Config.Settings.Leagues[index] = dialog.League;
                        Config.Settings.SaveEvents();

                        lstEvents.BeginUpdate();
                        lstEvents.SelectedItems[0].Text = league.Name;
                        lstEvents.SelectedItems[0].SubItems[2].Text = league.Location;
                        lstEvents.SelectedItems[0].SubItems[3].Text = league.StartDate.ToShortDateString();
                        lstEvents.SelectedItems[0].SubItems[4].Text = league.Players.Count.ToString();
                        if (league.MatchesPlayed.Count == 0)
                            lstEvents.SelectedItems[0].SubItems[5].Text = "Not Started";
                        else if (league.EndDate < pastReference)
                            lstEvents.SelectedItems[0].SubItems[5].Text = "Finished";
                        else
                        {
                            lstEvents.SelectedItems[0].SubItems[5].Text = league.MatchesPlayed.Count.ToString() +
                                                                          " Result" +
                                                                          (league.MatchesPlayed.Count == 1 ? "" : "s") +
                                                                          " Entered";
                        }

                        lstEvents.Sort();
                        lstEvents.EndUpdate();
                    }
                }
            }
        }
コード例 #3
0
        private void btnNewTournament_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;

                            Tournament checkTournament = Config.Settings.GetTournament(tournament.Name);
                            if (checkTournament != null)
                                if (MessageBox.Show("A tournament with the name \"" + tournament.Name + "\" already " +
                                                    "exists. Tournament 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();

                            foreach (Form form in MdiChildren)
                                if (form is frmEventsList)
                                {
                                    ((frmEventsList) form).FilterList();
                                    break;
                                }

                            return;
                        }
                        else
                            return;
                    }
                }
            }
            else
            {
            }
            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();
                        return;
                    }
                    else
                        return;
                }
            }
        }