Пример #1
0
        private void cbGroupNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            var groupName = this.cbGroupNames.SelectedItem?.ToString();

            if (string.IsNullOrWhiteSpace(groupName))
            {
                return;
            }
            var matchId        = MatchId;
            var columnSelected = MatchGroupTableDAL.GetColumnCountSelected(matchId, groupName);

            if (columnSelected.Length == 0)
            {
                // 初始化男子,女子个人团体每组人数
                this.cbMenAndWomenEveryGroupNum.SelectedItem = "4";

                // 初始化双打每组人数
                this.cbDoubleEveryGroupNum.SelectedItem = "3";

                this.menDataView.DataSource        = null;
                this.WomenDataView.DataSource      = null;
                this.menmenDataView.DataSource     = null;
                this.womenWomenDataView.DataSource = null;
                this.menWomenDataView.DataSource   = null;
                UnLockControl();
                return;
            }
            LockControl();
            var menWomenColumn = columnSelected[0];
            var doubleColumn   = columnSelected[1];

            this.cbMenAndWomenEveryGroupNum.SelectedItem = menWomenColumn;
            this.cbDoubleEveryGroupNum.SelectedItem      = doubleColumn;

            var allSex = MatchGroupTableDAL.GetAllProjectsByGroup(matchId, groupName); // 男,女,男男,女女,男女

            foreach (var sexName in allSex)
            {
                var columnCount = 0;
                if (sexName == "男" || sexName == "女")
                {
                    columnCount = Convert.ToInt32(menWomenColumn);
                }
                else if (sexName == "男男" || sexName == "女女" || sexName == "男女")
                {
                    columnCount = Convert.ToInt32(doubleColumn);
                }

                // 获取选择组别、项目下的所有运动员信息
                var allAthletes = MatchGroupTableDAL.GetAllAthletesByGroupProject(matchId, groupName, sexName);
                // 设置分组,同单位的不同列,不同行,只参加个人赛的需要标注
                var rowCount = (int)Math.Ceiling(allAthletes.Count / (decimal)columnCount); // 需要的组数

                var table = MatchGroupTableDAL.GetEveryGroupTable(matchId, groupName, sexName);

                DisplayInScreen(rowCount, columnCount, sexName, table);
            }
        }
Пример #2
0
        private void lbGenerateMatchGroup_Click(object sender, EventArgs e)
        {
            var doubleColumn      = this.cbDoubleEveryGroupNum.SelectedItem?.ToString();
            var menWomenColumn    = this.cbMenAndWomenEveryGroupNum.SelectedItem?.ToString();
            var groupNameSelected = this.cbGroupNames.SelectedItem?.ToString();

            if (string.IsNullOrWhiteSpace(doubleColumn) || string.IsNullOrWhiteSpace(groupNameSelected) || string.IsNullOrWhiteSpace(menWomenColumn))
            {
                MessageBox.Show("请先定义组别, 男子女子个人团体每组人数,双打每组人数, 再生成竞赛分组表");
                return;
            }
            var groupName = groupNameSelected;

            var allSex = MatchGroupTableDAL.GetAllProjectsByGroup(MatchId, groupNameSelected); // 男,女,男男,女女,男女

            // 根据不同的sexName生成不同的竞赛分组表
            foreach (var sexName in allSex)
            {
                var columnCount = 0;
                if (sexName == "男" || sexName == "女")
                {
                    columnCount = Convert.ToInt32(menWomenColumn);
                }
                else if (sexName == "男男" || sexName == "女女" || sexName == "男女")
                {
                    columnCount = Convert.ToInt32(doubleColumn);
                }

                // 获取选择组别、项目下的所有参加杆数赛的运动员信息
                var allAthletes = MatchGroupTableDAL.GetAllAthletesByGroupProject(MatchId, groupName, sexName);
                if (allAthletes.Count == 0)
                {
                    continue;
                }
                // 设置分组,同单位的不同列,不同行,只参加个人赛的需要标注
                var rowCount = (int)Math.Ceiling(allAthletes.Count / (decimal)columnCount); // 需要的组数

                var newAthletes = new List <MatchGroupTableAthleteModel>();
                allAthletes.ForEach(i => newAthletes.Add(i));

                // 排序结果:
                // 1. 同组人员尽可能分为上下两区
                // 2. 同组人员不同行不同列
                // 3. 如果人还多,则同列,按照同每列人数从2开始逐渐递增,直至没有多余的列或者最大列数
                // 4. 如果人还多便可以同行,同行人数最大每行容纳每组人数两人,否则报错

                // 对当前的运动员信息按照每队的人数从大到小进行排序, 如果人数最大的组的数目 > 2 * 组数,提示报错,每组不该超过两人该队人员
                // 遍历每一只队伍,进行三轮排序直到该队伍人数排完为止
                // 第一轮,不同行,不同列,行 + 列,最小/最大位置切换填充人员
                // 第二轮,不同行,同列,行 + 列,最小/最大位置切换填充人员(每列人数从2~总行数)
                // 第三轮, 不同列同行数不超过2人,行 + 列,最小/最大位置切换填充人员,遇到行 + 列数目相同的单元格,选择列中同队人员最小的一个

                // 按队伍人数从多到少的排序
                var allSortedTeamNames = GetAllSortedTeamNames(newAthletes, rowCount, sexName);

                // 初始化一个竞赛分组表
                var table = GenerateMatchTable(rowCount, columnCount);

                // 对每一只队伍进行排序
                for (var i = 0; i < allSortedTeamNames.Count; i++)
                {
                    var willSortedAthletes = newAthletes.Where(x => x.TeamName == allSortedTeamNames[i]).ToList();
                    SortEveryTeamAthletes(table, willSortedAthletes);
                }

                // 展示到界面上
                DisplayInScreen(rowCount, columnCount, sexName, table);

                #region 将生成的分组竞赛表存入到DB中
                MatchGroupTableDAL.InsertMatchGroupTableBatch(MatchId, table, sexName, groupName, Convert.ToInt32(menWomenColumn), Convert.ToInt32(doubleColumn));
                #endregion
            }

            LockControl();
        }