コード例 #1
0
        private void replacePlayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var tournament = Config.Settings.GetTournament(TournamentName);
            using (var playerSelect = new FrmAddPlayer(tournament.Players))
            {
                if (playerSelect.ShowDialog() == DialogResult.OK)
                {
                    var reopenRoundForm = false;
                    if (RoundForm != null)
                    {
                        RoundForm.Close();
                        reopenRoundForm = true;
                    }
                    var originalID = lstResults.SelectedItems[0].Name;
                    var number = tournament.Players[originalID];
                    var id = playerSelect.SelectedID;
                    var faction = playerSelect.SelectedFaction;
                    tournament.Players.Remove(originalID);
                    tournament.PlayerFaction.Remove(originalID);
                    tournament.AddPlayer(id, faction, number);

                    if (tournament.RemovedPlayers.Contains(originalID))
                        tournament.RemovedPlayers[tournament.RemovedPlayers.IndexOf(originalID)] = id;
                    foreach(var round in tournament.Rounds)
                    {
                        var match = round.Matches.Where(m => m.Players.Contains(originalID)).FirstOrDefault();
                        if (match != null)
                        {
                            match.Players[match.Players.IndexOf(originalID)] = id;
                            if (match.Results.ContainsKey(originalID))
                            {
                                var result = match.Results[originalID];
                                match.Results.Remove(originalID);
                                result.PlayerID = id;
                                match.Results.Add(id, result);                                
                            }
                        }
                    }
                    Config.Settings.SaveEvents();
                    FillPlayers();
                    UpdateScores();
                    if (reopenRoundForm) btnRound_Click(sender, e);
                }
            }
        }
コード例 #2
0
        private void btnAddPlayer_Click(object sender, EventArgs e)
        {
            var tournament = Config.Settings.GetTournament(TournamentName);
            using (var playerSelect = new FrmAddPlayer(tournament.Players))
            {
                if (playerSelect.ShowDialog() == DialogResult.OK)
                {
                    var reopenRoundForm = false;
                    if (RoundForm != null)
                    {
                        RoundForm.Close();
                        reopenRoundForm = true;
                    }
                    var id = playerSelect.SelectedID;
                    var faction = playerSelect.SelectedFaction;
                    tournament.AddPlayer(id, faction);

                    int currentRound = Config.Settings.GetTournament(TournamentName).Rounds.Count;
                    if (currentRound > 0)
                    {
                        if (tournament.Players.Count%2 == 1)
                        {
                            var byeMatch = new TournamentMatch(TournamentName);
                            byeMatch.Players.Add(id);
                            byeMatch.Crews.Add(id, new PlayerCrew());
                            var byeResult = new MatchResult(id) {Bye = true};
                            byeMatch.Results.Add(id, byeResult);

                            if (!Config.Settings.GetTournament(TournamentName).Rounds[currentRound - 1].Completed)
                                Config.Settings.GetTournament(TournamentName).Rounds[currentRound - 1].Matches.Add(
                                    byeMatch);
                        }
                        else
                        {
                            foreach (
                                var match in Config.Settings.GetTournament(TournamentName).Rounds[currentRound - 1].
                                    Matches.Where(match => match.ByeRound))
                            {
                                if (!Config.Settings.GetTournament(TournamentName).Rounds[currentRound - 1].Completed)
                                {
                                    match.Results.Clear();
                                    match.Players.Add(id);
                                    match.Crews.Add(id, new PlayerCrew());
                                    break;
                                }
                            }
                        }
                    }
                    Config.Settings.SaveEvents();
                    FillPlayers();
                    UpdateScores();

                    if (reopenRoundForm) btnRound_Click(sender, e);
                }
            }
        }