示例#1
0
        //private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        //{
        //    _timer.Stop();
        //    DateTime date = DateTime.Now;
        //    try
        //    {
        //        var allMatch = new List<EuropeMatchEntity>();
        //        if (_allMatch.ContainsKey(date.Date.AddDays(-1)))
        //            allMatch.AddRange(_allMatch[date.Date.AddDays(-1)]);
        //        if (_allMatch.ContainsKey(date.Date)) //获取当天的比赛
        //            allMatch.AddRange(_allMatch[date.Date]);
        //        foreach (var entity in allMatch)
        //        {
        //            if (entity.States ==(int)EnumEuropeStatus.Gamble && entity.MatchTime<= date)
        //            {
        //                entity.States = (int) EnumEuropeStatus.MatchIng;
        //                EuropeMatchMgr.Update(entity);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        SystemlogMgr.Error("欧洲杯更新比赛状态", ex);
        //    }
        //    _timer.Start();
        //}

        /// <summary>
        /// 刷新比赛  发奖
        /// </summary>
        public MessageCode RefreshMatch()
        {
            DateTime date = DateTime.Now;

            InitMatch();
            try
            {
                var allMatch = new List <EuropeMatchEntity>();
                if (_allMatch.ContainsKey(date.Date.AddDays(-1)))
                {
                    allMatch.AddRange(_allMatch[date.Date.AddDays(-1)]);
                }
                if (_allMatch.ContainsKey(date.Date)) //获取当天的比赛
                {
                    allMatch.AddRange(_allMatch[date.Date]);
                }
                foreach (var entity in allMatch)
                {
                    if (entity.States == (int)EnumEuropeStatus.Gamble && entity.MatchTime <= date)
                    {
                        entity.States = (int)EnumEuropeStatus.MatchIng;
                        EuropeMatchMgr.Update(entity);
                    }
                    if (entity.States == (int)EnumEuropeStatus.MatchEnd)
                    {
                        if (entity.ResultType == 0)
                        {
                            if (entity.HomeGoals > entity.AwayGoals)
                            {
                                entity.ResultType = 1;
                            }
                            else if (entity.HomeGoals == entity.AwayGoals)
                            {
                                entity.ResultType = 2;
                            }
                            else
                            {
                                entity.ResultType = 3;
                            }
                        }
                        SendGamblePrize(entity);
                        entity.States = (int)EnumEuropeStatus.PrizeEnd;
                        //EuropeMatchMgr.Update(entity);
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("欧洲杯刷新比赛  发奖", ex);
                return(MessageCode.NbParameterError);
            }
            return(MessageCode.Success);
        }
示例#2
0
        /// <summary>
        /// 结束一场比赛
        /// </summary>
        /// <param name="matchId"></param>
        /// <param name="homeGoals"></param>
        /// <param name="awayGoals"></param>
        /// <returns></returns>
        public MessageCodeResponse EndMatch(int matchId, int homeGoals, int awayGoals)
        {
            DateTime date  = DateTime.Now;
            var      match = EuropeConfig.Instance.GetOneMatch(matchId);

            if (match == null)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
            }
            if (match.MatchTime.AddHours(2) > date)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.Match2HoursEnd));
            }
            if (match.States != (int)EnumEuropeStatus.MatchIng)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
            }
            match.HomeGoals = homeGoals;
            match.AwayGoals = awayGoals;
            if (homeGoals > awayGoals)
            {
                match.ResultType = 1;
            }
            else if (homeGoals == awayGoals)
            {
                match.ResultType = 2;
            }
            else
            {
                match.ResultType = 3;
            }
            match.States = (int)EnumEuropeStatus.MatchEnd;
            if (!EuropeMatchMgr.Update(match))
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbUpdateFail));
            }
            EuropeConfig.Instance.SendGamblePrize(match);
            match.States = (int)EnumEuropeStatus.PrizeEnd;
            EuropeMatchMgr.Update(match);
            return(ResponseHelper.CreateSuccess <MessageCodeResponse>());
        }
示例#3
0
        protected void btnEnd_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime date      = DateTime.Now;
                int      matchId   = ConvertHelper.ConvertToInt(txtMatchId.Text.Trim());
                int      homeGoals = ConvertHelper.ConvertToInt(txtHomeGoals.Text.Trim());
                int      awayGoals = ConvertHelper.ConvertToInt(txtAwayGoals.Text.Trim());
                if (matchId == 0)
                {
                    ShowMessage("比赛ID不能为0");
                    return;
                }

                var match = EuropeMatchMgr.GetById(matchId);
                if (match == null)
                {
                    ShowMessage("没有找到比赛");
                    return;
                }
                //if (match.MatchTime.AddHours(2) > date)
                //{
                //    ShowMessage("开始时间不足两小时");
                //    return;
                //}
                if (match.States != (int)EnumEuropeStatus.MatchIng)
                {
                    ShowMessage("比赛还未开始");
                    return;
                }
                match.HomeGoals = homeGoals;
                match.AwayGoals = awayGoals;
                if (homeGoals > awayGoals)
                {
                    match.ResultType = 1;
                }
                else if (homeGoals < awayGoals)
                {
                    match.ResultType = 3;
                }
                else
                {
                    match.ResultType = 2;
                }
                match.States = (int)EnumEuropeStatus.MatchEnd;
                if (!EuropeMatchMgr.Update(match))
                {
                    ShowMessage("更新失败");
                    return;
                }
                BindData();
                ShowMessage("成功");
            }
            catch (Exception ex)
            {
                ShowMessage("失败:" + ex.ToString());
            }
            txtMatchId.Text   = "";
            txtHomeGoals.Text = "";
            txtAwayGoals.Text = "";
        }