示例#1
0
        //public static void UpdateTournamentMatchStatus(Cxt cxt, int tournamentID, int tournamentMatchStatusID, string matchIDs)
        //{

        //    string[] matches = matchIDs.Split(',');

        //    foreach (string item in matches)
        //    {
        //        UpdateTournamentMatchStatus(cxt, tournamentMatchStatusID, Convert.ToInt32(item));
        //    }
        //}

        #region Update Match Status

        public static void UpdateTournamentMatchStatus(Cxt cxt, TournamentMatchStatusE tournamentMatchStatusID, TournamentMatch m)
        {
            SqlTransaction t = null;
            Game           g = null;
            Challenge      c = null;

            DataTable         dtMatches = TournamentMatches.GetTournamentsMatchByTournamentID(m.TournamentID);
            TournamentMatches matches   = new TournamentMatches(cxt, dtMatches);
            DataTable         dtGame    = Games.GetAllGamesByTournamentID(cxt, m.TournamentID);

            DataTable dtTUser = TournamentUsers.GetTournamentUsersByTournamentID(StatusE.Active, m.TournamentID);

            try
            {
                if (!TournamentMatchRules.Instance.CanChangeStatus(m.TournamentMatchStatusE, tournamentMatchStatusID))
                {
                    return;
                }

                m.EloBlackBefore         = (m.EloBlackBefore == 0) ? 1500 : m.EloBlackBefore;
                m.EloWhiteBefore         = (m.EloWhiteBefore == 0) ? 1500 : m.EloWhiteBefore;
                m.TournamentMatchStatusE = tournamentMatchStatusID;

                if (GetGameResultID((TournamentMatchStatusE)tournamentMatchStatusID) != GameResultE.None)
                {
                    m.GameResultIDE = GetGameResultID((TournamentMatchStatusE)tournamentMatchStatusID);
                }

                if (m.TournamentMatchStatusE == TournamentMatchStatusE.InProgress || m.IsBye || m.IsForced)
                {
                    c = CreateChallenge(m);
                }

                t = SqlHelper.BeginTransaction(Config.ConnectionString);

                m.Save(t);

                if (c != null)
                {
                    if (c.IsNew)
                    {
                        c.Save(t);
                    }
                }

                if (m.IsBye || m.IsForced)
                {
                    if (c != null)
                    {
                        c.ChallengeStatusIDE = ChallengeStatusE.Decline;
                        c.StatusIDE          = StatusE.Inactive;
                        c.Save(t);
                    }

                    TournamentUserResult(cxt, dtTUser, m, matches, dtGame).Save(t);

                    g = GetGame(cxt, m);

                    if (!g.IsNew)
                    {
                        g.GameResultIDE = m.GameResultIDE;
                        g.GameFlags     = "";
                        g.Save(t);
                    }
                }

                SqlHelper.CommitTransaction(t);

                switch (m.TournamentMatchStatusE)
                {
                case TournamentMatchStatusE.Draw:
                case TournamentMatchStatusE.WhiteBye:
                case TournamentMatchStatusE.BlackBye:
                case TournamentMatchStatusE.ForcedWhiteWin:
                case TournamentMatchStatusE.ForcedWhiteLose:
                case TournamentMatchStatusE.ForcedDraw:
                    TournamentMatch.CreateChildMatchIfRequired(cxt, m, dtTUser);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                SqlHelper.RollbackTransaction(t);
                Log.Write(cxt, ex);
            }
        }