private void InitMatch() { DateTime date = DateTime.Now; //排除1个月之前的比赛 var allMatch = EuropeMatchMgr.GetAllMatvch(date.AddDays(-30)); var allLogo = ConfigGambleiconMgr.GetAll(); _logoDic = allLogo.ToDictionary(r => r.Name.Trim(), r => r.Idx); _allMatch = new ConcurrentDictionary <DateTime, List <EuropeMatchEntity> >(); _oneMatch = new ConcurrentDictionary <int, EuropeMatchEntity>(); foreach (var item in allMatch) { item.HomeLogo = GetLogo(item.HomeName); item.AwayLogo = GetLogo(item.AwayName); item.MatchTimeTick = ShareUtil.GetTimeTick(item.MatchTime); if (!_allMatch.ContainsKey(item.MatchDate)) { _allMatch.TryAdd(item.MatchDate, new List <EuropeMatchEntity>()); } _allMatch[item.MatchDate].Add(item); _oneMatch.TryAdd(item.MatchId, item); } //是否有比赛 _matchInfoDic = new Dictionary <long, bool>(); for (int i = -7; i <= 7; i++) { var isMatch = EuropeMatchMgr.GetIsMatch(date.Date.AddDays(i)) > 0; _matchInfoDic.Add(ShareUtil.GetTimeTick(date.Date.AddDays(i)), isMatch); } }
protected void btnSend_Click(object sender, EventArgs e) { try { if (!CheckInput()) { return; } string homeName = txtHomeName.Text.Trim(); string awayName = txtAwayName.Text.Trim(); DateTime startTime = Convert.ToDateTime(txtStartTime.Text); EuropeMatchEntity entity = new EuropeMatchEntity(0, homeName, awayName, startTime.Date, startTime, 0, 0, 0, 1, DateTime.Now, DateTime.Now); if (!EuropeMatchMgr.Insert(entity)) { ShowMessage("发布失败"); } else { ShowMessage("发布成功"); BindData(); } } catch (Exception ex) { ShowMessage("发布失败:" + ex); } txtHomeName.Text = ""; txtStartTime.Text = ""; txtAwayName.Text = ""; }
/// <summary> /// 发布一场比赛 /// </summary> /// <param name="homeName"></param> /// <param name="awayName"></param> /// <param name="matchTime"></param> /// <returns></returns> public MessageCodeResponse ReleaseMatch(string homeName, string awayName, DateTime matchTime) { EuropeMatchEntity entity = new EuropeMatchEntity(0, homeName, awayName, matchTime.Date, matchTime, 0, 0, 0, 1, DateTime.Now, DateTime.Now); if (!EuropeMatchMgr.Insert(entity)) { return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbUpdateFail)); } return(ResponseHelper.CreateSuccess <MessageCodeResponse>()); }
//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); }
/// <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>()); }
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 = ""; }
public void SendPrize(int matchId, string zoneId) { DateTime date = DateTime.Now; var match = EuropeMatchMgr.GetById(matchId); var _season = EuropeSeasonMgr.GetSeason(date, zoneId); if (match == null) { return; } var season = EuropeSeasonMgr.GetSeason(date, zoneId); //获取未发奖的竞猜 var sendPrizeList = EuropeGamblerecordMgr.GetNotPrize(matchId, zoneId); foreach (var item in sendPrizeList) { if (item.IsSendPrize) { continue; } item.IsSendPrize = true; item.UpdateTime = date; MailBuilder mail = null; EuropeGambleEntity gambleInfo = null; bool isInsertInfo = false; if (item.GambleType == match.ResultType) //竞猜正确 { item.IsGambleCorrect = true; item.ReturnPoint = item.Point * 2; //发邮件 mail = new MailBuilder(item.ManagerId, EnumMailType.Europe, item.ReturnPoint, match.HomeName, match.AwayName); gambleInfo = EuropeGambleMgr.GetById(item.ManagerId, zoneId); if (gambleInfo == null) { isInsertInfo = true; gambleInfo = new EuropeGambleEntity(item.ManagerId, 1, "0,0,0,0", date, date, season.Idx); } else { if (_season != null && gambleInfo.SeasonId != _season.Idx) { //插入记录 EuropeRecordMgr.Insert(new EuropeRecordEntity(0, gambleInfo.ManagerId, gambleInfo.SeasonId, gambleInfo.CorrectNumber, gambleInfo.PrizeRecord, date), null, zoneId); //更新活动 gambleInfo.CorrectNumber = 0; gambleInfo.PrizeRecord = "0,0,0,0"; gambleInfo.SeasonId = _season.Idx; } gambleInfo.CorrectNumber++; gambleInfo.UpdateTime = date; } } else { item.IsGambleCorrect = false; } MessageCode code = MessageCode.FailUpdate; if (mail != null) { if (!mail.Save(zoneId)) { ShowMessage("发送邮件失败"); return; } } if (gambleInfo != null) { if (isInsertInfo) { if (!EuropeGambleMgr.Insert(gambleInfo, null, zoneId)) { code = MessageCode.NbUpdateFail; } } else { if (!EuropeGambleMgr.Update(gambleInfo, null, zoneId)) { code = MessageCode.NbUpdateFail; } } } if (!EuropeGamblerecordMgr.Update(item, null, zoneId)) { code = MessageCode.NbUpdateFail; } if (code != MessageCode.Success) { ShowMessage("保存失败"); } } }
private void BindData() { ClearData(); DateTime date = DateTime.Now; //排除1个月之前的比赛 var matchList = EuropeMatchMgr.GetAllMatvch(date.AddDays(-30)); if (matchList == null) { matchList = new List <EuropeMatchEntity>(); } matchList = matchList.OrderByDescending(r => r.MatchId).ToList(); foreach (var item in matchList) { if (item != null) { try { switch (item.ResultType) { case 0: item.ResultTypeString = "初始"; break; case 1: item.ResultTypeString = "主队获胜"; break; case 2: item.ResultTypeString = "平"; break; case 3: item.ResultTypeString = "客队获胜"; break; } switch (item.States) { case 0: item.StatusString = "初始"; break; case 1: item.StatusString = "可竞猜"; break; case 2: item.StatusString = "比赛中"; break; case 3: item.StatusString = "比赛完成"; break; case 4: item.StatusString = "发奖完成"; break; } } catch (Exception ex) { throw new Exception("match读取出错,id:" + item.MatchId); } } } datagrid1.DataSource = matchList; datagrid1.DataBind(); }