Пример #1
0
        public void BindMatches()
        {
            IRepository repo = new Repository();

            var list  = repo.Query <CasinoMatch>(x => x.LeagueGuid == LeagueGuid);
            var teams = RelationGroupTeam.QueryByGroupGuid(ID);

            list = list.FindAll(x => teams.Exists(t => t.TeamGuid == x.Home) && teams.Exists(t => t.TeamGuid == x.Away));

            if (list.Count > 0)
            {
                foreach (var m in list)
                {
                    if (!m.GroupGuid.HasValue || m.GroupGuid != ID)
                    {
                        m.GroupGuid = ID;

                        repo.Update(m);
                    }
                }
            }
        }
Пример #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (var conn = new SqlConnection(DataAccess.ConnectString))
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    if (string.IsNullOrEmpty(ddlGroupLeague.SelectedValue) ||
                        !lbLeagueTeam.Items.Cast<ListItem>().Any(x => x.Selected))
                    { throw new Exception("请选择联赛分类与分组球队"); }

                    var g = new Group();

                    if (GroupGuid != Guid.Empty)
                    {
                        g = _repo.Single<Group>(GroupGuid);
                    }
                    else
                    {
                        g.ID = new Guid(tbGroupGuid.Text);
                    }

                    g.GroupName = tbGroupName.Text;
                    g.GroupOrder = Convert.ToInt16(tbGroupOrder.Text);
                    g.RankMethod = (RankMethodType)Enum.Parse(typeof(RankMethodType), rblRankMethod.SelectedValue);
                    g.IsTable = cbIsTable.Checked;

                    g.LeagueGuid = new Guid(ddlGroupLeague.SelectedValue);

                    #region ListBox Multiple Value for RelationGroupTeam

                    if (GroupGuid != Guid.Empty)
                    {
                        var rgts = RelationGroupTeam.QueryByGroupGuid(GroupGuid);

                        if (rgts.Count > 0)
                        {
                            foreach (var rgt in rgts)
                            {
                                rgt.Delete(trans);
                            }
                        }
                    }

                    foreach (ListItem item in lbLeagueTeam.Items)
                    {
                        Guid tGuid;
                        if (item.Selected && Guid.TryParse(item.Value, out tGuid))
                        {
                            var gt = new RelationGroupTeam
                            {
                                GroupGuid = g.ID,
                                TeamGuid = tGuid
                            };

                            gt.Insert(trans);
                        }
                    }

                    #endregion

                    if (GroupGuid != Guid.Empty)
                    {
                        _repo.Update(g, trans);
                        trans.Commit();

                        ClientScript.RegisterClientScriptBlock(typeof(string), "success", "alert('更新分组成功');", true);
                    }
                    else
                    {
                        _repo.Insert(g, trans);
                        trans.Commit();

                        ClientScript.RegisterClientScriptBlock(typeof(string), "success", "alert('添加分组成功');", true);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true);
                }
            }
        }
Пример #3
0
        public void Statistic()
        {
            IRepository repo = new Repository();

            // 取得当前分组的所有球队排名关系
            var listRgt = RelationGroupTeam.QueryByGroupGuid(ID);

            // 取得当前分组的所有博彩比赛
            List <CasinoMatch> listMatch;

            if (IsTable)
            {
                // 联赛积分榜
                //@"SELECT * FROM dbo.AcnCasino_Match WHERE (ResultHome IS NOT NULL) AND (ResultAway IS NOT NULL) AND
                //        (Home IN (SELECT TeamGuid FROM dbo.Arsenal_RelationGroupTeam AS GroupTeam1 WHERE GroupGuid = @groupGuid)) AND
                //        (Away IN (SELECT TeamGuid FROM dbo.Arsenal_RelationGroupTeam AS GroupTeam2 WHERE GroupGuid = @groupGuid)) AND
                //        (LeagueGuid = (SELECT LeagueGuid FROM dbo.Arsenal_Group WHERE GroupGuid = @groupGuid))
                //        ORDER BY PlayTime DESC";

                listMatch = repo.Query <CasinoMatch>(x => x.ResultHome.HasValue && x.ResultAway.HasValue && x.LeagueGuid == LeagueGuid)
                            .FindAll(x => listRgt.Exists(t => t.TeamGuid == x.Home) && listRgt.Exists(t => t.TeamGuid == x.Away))
                            .OrderBy(x => x.PlayTime).ToList();
            }
            else
            {
                // 分组排名表
                //@"SELECT * FROM dbo.AcnCasino_Match WHERE (GroupGuid =@groupGuid) AND (ResultHome IS NOT NULL) AND (ResultAway IS NOT NULL)
                //        AND (LeagueGuid = (SElECT LeagueGuid FROM dbo.Arsenal_Group WHERE GroupGuid = @groupGuid)) ORDER BY PlayTime DESC";

                listMatch = repo.Query <CasinoMatch>(x => x.ResultHome.HasValue && x.ResultAway.HasValue && x.GroupGuid == ID && x.LeagueGuid == LeagueGuid)
                            .OrderBy(x => x.PlayTime).ToList();
            }

            if (listRgt.Count > 0 && listMatch.Count > 0)
            {
                foreach (var rgt in listRgt)
                {
                    // 根据比赛更新球队的分组排名信息
                    rgt.Statistic(listMatch.FindAll(x => x.Home == rgt.TeamGuid || x.Away == rgt.TeamGuid));
                }
            }

            if (listRgt.Count > 0)
            {
                if (RankMethod == RankMethodType.VersusHist)
                {
                    // 设置双方交战比较规则
                    var comparer = new GroupRankComparer {
                        Matches = listMatch
                    };

                    // 根据总积分、双方交战记录、净胜球、进球数、失球数排序
                    listRgt = listRgt.OrderByDescending(x => x.TotalPoints)
                              .ThenByDescending(x => x.TeamGuid, comparer)
                              .ThenByDescending(x => x.HomeGoalDiff + x.AwayGoalDiff)
                              .ThenByDescending(x => x.HomeGoalFor + x.AwayGoalFor)
                              .ThenBy(x => x.HomeGoalAgainst + x.AwayGoalAgainst)
                              .ThenBy(x => Team.Cache.Load(x.TeamGuid).TeamEnglishName)
                              .ToList();
                }
                else
                {
                    // 根据总积分、净胜球、进球数、失球数排序
                    listRgt = listRgt.OrderByDescending(x => x.TotalPoints)
                              .ThenByDescending(x => x.HomeGoalDiff + x.AwayGoalDiff)
                              .ThenByDescending(x => x.HomeGoalFor + x.AwayGoalFor)
                              .ThenBy(x => x.HomeGoalAgainst + x.AwayGoalAgainst)
                              .ThenBy(x => Team.Cache.Load(x.TeamGuid).TeamEnglishName)
                              .ToList();
                }
                // 更新排名并持久化
                short positionNo = 0;

                foreach (var instance in listRgt)
                {
                    instance.PositionNo = ++positionNo;
                    instance.Update();
                }
            }
        }