// 生成决赛竞赛
        private void lbGenerateFinalMatchGroupTable_Click(object sender, EventArgs e)
        {
            // 决赛的时候,取出成绩的前几名显示,前几名在创建比赛的时候设定
            var showNum   = MatchInfo.FinalNum;
            var sexName   = SwitchProjectNamesToSex(this.cbProjectNames.Text);
            var groupName = this.cbGroupNames.Text;

            var preRound      = MatchInfo.PreRounds;
            var athletesScore = AthletesDAL.GetAthletesScore(MatchId, groupName, sexName, preRound);

            athletesScore = athletesScore.Where(x => x.ScoresWithRound.Count > 0 && x.ScoresWithRound.ContainsKey(x.ScoresWithRound.Count))
                            .OrderBy(x => x.SumSocre)
                            .ThenBy(x => x.ScoresWithRound[x.ScoresWithRound.Count].Sum())
                            .Take(showNum)
                            .ToList();

            GenerateFinalMatchGroup form = new GenerateFinalMatchGroup();

            form.MatchId   = MatchInfo.Id;
            form.MatchName = MatchInfo.Name;
            form.GroupName = groupName;
            form.SexName   = sexName;
            form.Project   = this.cbProjectNames.Text;
            form.Athletes  = athletesScore;
            form.ShowDialog();
        }
        // 打印个人成绩预赛汇总
        private void lbPrintAthletePreScore_Click(object sender, EventArgs e)
        {
            // 决赛的时候,取出成绩的前几名显示,前几名在创建比赛的时候设定
            var showNum   = MatchInfo.FinalNum;
            var sexName   = SwitchProjectNamesToSex(this.cbProjectNames.Text);
            var groupName = this.cbGroupNames.Text;

            // 获取几轮杆数的排序
            var preRound      = MatchInfo.PreRounds;
            var athletesScore = AthletesDAL.GetAthletesScore(MatchId, groupName, sexName, preRound);

            athletesScore = athletesScore.Where(x => x.ScoresWithRound.Count > 0 && x.SumSocre > 0).OrderBy(x => x.SumSocre).ThenBy(x => x.ScoresWithRound[x.ScoresWithRound.Count].Sum()).ToList();
            if (preRound == 1)
            {
            }
            else if (preRound == 2)
            {
                var fileName = $"{MatchInfo.Name}-{groupName}-{this.cbProjectNames.Text}-预赛成绩-{DateTime.Now.ToString("yyyyMMddHHmmss")}";

                ExcelHelperPrintPreMatch.GeneratePreScoreTwoRound(fileName, athletesScore, showNum, MatchInfo.Name, groupName, this.cbProjectNames.Text);
            }
        }
Exemple #3
0
        private static int PrintMenWomenScore(IWorkbook workbook, ISheet sheet, int startRowNum, string matchId, string matchName)
        {
            var rowNum = startRowNum;
            // 获取所有分组
            var allGroupNames = AthletesDAL.GetAllGroupNames(matchId);

            // 遍历每组人员,获取所有运动员成绩
            foreach (var groupName in allGroupNames.OrderBy(x => x))
            {
                var allPartInGroupMatchScore = AthletesDAL.GetAthletesScore(matchId, groupName, "男女", 2);
                if (allPartInGroupMatchScore.Count == 0)
                {
                    continue;
                }
                var athletes = allPartInGroupMatchScore.Select(x => new AthleteScore()
                {
                    Name          = x.Name,
                    TeamName      = x.TeamName,
                    TeamShortName = x.TeamShortName,
                    PreSumSocre   = x.SumSocre
                }).ToList();
                athletes = athletes.Where(x => x.PreSumSocre > 0).OrderBy(x => x.PreSumSocre).ToList();

                // 写入文件
                sheet.AddMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 4));
                var headRow  = ExcelHelper.GetRow(sheet, rowNum);
                var headCell = ExcelHelper.SetCellStringValue(headRow, 0, $"杆数赛混双({groupName})");
                headCell.CellStyle = ExcelHelper.SetCellStyle(workbook, sheet, rowNum, true, 300);
                rowNum++;

                rowNum = SetAtheleScore(workbook, sheet, rowNum, athletes);

                rowNum++;
            }

            return(rowNum);
        }
        private void LoadAthletes(DataTable table, string matchId, string groupName, string sexName, int round, bool isFinal)
        {
            // 决赛
            if (isFinal)
            {
                // 决赛的时候,取出成绩的前几名显示,前几名在创建比赛的时候设定
                var showNum = MatchInfo.FinalNum;

                // 获取几轮杆数的排序
                var preRound       = MatchInfo.PreRounds;
                var athletesScore1 = AthletesDAL.GetAthletesScore(matchId, groupName, sexName, preRound);
                athletesScore1 = athletesScore1.Where(x => x.ScoresWithRound.Count > 0).OrderBy(x => x.SumSocre).Take(showNum).ToList();

                if (RecordByGroup)
                {
                    // 判断是否已经生成分组表,如果没有则提示先生成分组表
                    var finalMatchGroupGenerate = MatchGroupTableDAL.FinalMatchGroupGenerated(matchId, groupName, sexName);
                    if (!finalMatchGroupGenerate)
                    {
                        MessageBox.Show($"{groupName}-{sexName}-决赛分组表还未生成,请先生成决赛分组表后再通过分组表录入分数");
                        return;
                    }

                    var roundField    = ConvertRoundToDBField(round, isFinal);
                    var athletesScore = AthletesDAL.GetAthletesScore(matchId, groupName, sexName, roundField);

                    // 更新每条数据在group table的位置
                    MatchGroupTableDAL.UpdateFinalGroupTableInfo(matchId, groupName, sexName, athletesScore);
                    athletesScore = athletesScore.OrderBy(x => x.Row).ThenBy(x => x.Column).ToList();

                    for (var i = 0; i < athletesScore.Count; i++)
                    {
                        var row = table.NewRow();
                        row[0] = $"第{athletesScore[i].Row + 1}组";
                        row[1] = athletesScore[i].TeamShortName;
                        row[2] = athletesScore[i].Name;
                        var sum = 0.0;
                        if (athletesScore1.Select(x => x.TeamShortName).Contains(athletesScore[i].TeamShortName) &&
                            athletesScore1.Select(x => x.Name).Contains(athletesScore[i].Name))
                        {
                            if (athletesScore[i].Score.Count > 1)
                            {
                                var j = 3;
                                foreach (var s in athletesScore[i].Score)
                                {
                                    row[j] = s.Value;
                                    var value = 0.0;
                                    Double.TryParse(s.Value, out value);
                                    sum += value;

                                    j++;
                                }
                                row[3 + athletesScore[i].Score.Count] = sum;
                            }
                            table.Rows.Add(row);
                        }
                    }
                }
                else
                {
                    var roundField    = ConvertRoundToDBField(round, isFinal);
                    var athletesScore = AthletesDAL.GetAthletesScore(matchId, groupName, sexName, roundField);
                    athletesScore = athletesScore.OrderBy(x => x.TeamName).ThenBy(x => x.Name).ToList();
                    for (var i = 0; i < athletesScore.Count; i++)
                    {
                        var row = table.NewRow();
                        row[0] = athletesScore[i].TeamShortName;
                        row[1] = athletesScore[i].Name;
                        var sum = 0.0;
                        if (athletesScore1.Select(x => x.TeamShortName).Contains(athletesScore[i].TeamShortName) &&
                            athletesScore1.Select(x => x.Name).Contains(athletesScore[i].Name))
                        {
                            if (athletesScore[i].Score.Count > 1)
                            {
                                var j = 2;
                                foreach (var s in athletesScore[i].Score)
                                {
                                    row[j] = s.Value;
                                    var value = 0.0;
                                    Double.TryParse(s.Value, out value);
                                    sum += value;

                                    j++;
                                }

                                row[2 + athletesScore[i].Score.Count] = sum;
                            }
                            table.Rows.Add(row);
                        }
                    }
                }
            }
            else // 预赛
            {
                var roundField = ConvertRoundToDBField(round, isFinal);

                var athletesScore = AthletesDAL.GetAthletesScore(matchId, groupName, sexName, roundField);
                if (RecordByGroup)
                {
                    // 更新每条数据在group table的位置
                    MatchGroupTableDAL.UpdateGroupTableInfo(matchId, groupName, sexName, athletesScore);
                    athletesScore = athletesScore.OrderBy(x => x.Row).ThenBy(x => x.Column).ToList();
                }
                else
                {
                    athletesScore = athletesScore.OrderBy(x => x.TeamShortName).ThenBy(x => x.Name).ToList();
                }

                for (var i = 0; i < athletesScore.Count; i++)
                {
                    var row = table.NewRow();
                    if (RecordByGroup)
                    {
                        row[0] = $"第{athletesScore[i].Row + 1}组";
                        row[1] = athletesScore[i].TeamShortName;
                        row[2] = athletesScore[i].Name;
                        var sum = 0.0;
                        if (athletesScore[i].Score.Count > 1)
                        {
                            var j = 3;
                            foreach (var s in athletesScore[i].Score)
                            {
                                row[j] = s.Value;
                                var value = 0.0;
                                Double.TryParse(s.Value, out value);
                                sum += value;

                                j++;
                            }

                            row[3 + athletesScore[i].Score.Count] = sum;
                        }
                    }
                    else
                    {
                        row[0] = athletesScore[i].TeamShortName;
                        row[1] = athletesScore[i].Name;
                        var sum = 0.0;
                        if (athletesScore[i].Score.Count > 1)
                        {
                            var j = 2;
                            foreach (var s in athletesScore[i].Score)
                            {
                                row[j] = s.Value;
                                var value = 0.0;
                                Double.TryParse(s.Value, out value);
                                sum += value;

                                j++;
                            }

                            row[2 + athletesScore[i].Score.Count] = sum;
                        }
                    }
                    table.Rows.Add(row);
                }
            }
        }