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

            // 获取决赛两轮成绩
            var athletesScore = AthletesDAL.GetAthletesFinalScore(MatchId, groupName, sexName, 2);

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

            var fileName = $"{MatchInfo.Name}-{groupName}-{this.cbProjectNames.Text}-决赛成绩-{DateTime.Now.ToString("yyyyMMddHHmmss")}";

            ExcelHelperPrintFinalMatch.GenerateFinalScoreTwoRound(fileName, athletesScore, MatchInfo.Name, groupName, this.cbProjectNames.Text);
        }
Ejemplo n.º 2
0
        private static int PrintWomenScore(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.GetTeamMatchAthletesScore(matchId, groupName, "女", 2);
                var allPartInGroupFinalMatchScore = AthletesDAL.GetAthletesFinalScore(matchId, groupName, "女", 2);
                var athletes = allPartInGroupMatchScore.Select(x => new AthleteScore()
                {
                    Name          = x.Name,
                    TeamName      = x.TeamName,
                    TeamShortName = x.TeamShortName,
                    PreSumSocre   = x.SumSocre
                }).ToList();

                foreach (var allPart in allPartInGroupFinalMatchScore)
                {
                    var athlete = athletes.Where(x => x.Name == allPart.Name).FirstOrDefault();
                    if (athlete != null)
                    {
                        athlete.FinalSumSocre = allPart.SumSocre;
                    }
                }

                var sortedAthlete = new List <AthleteScore>();
                var finalAths     = athletes.Where(x => x.FinalSumSocre > 0).OrderBy(x => x.FinalSumSocre).ToList();
                sortedAthlete.AddRange(finalAths);
                var preAths = athletes.Where(x => x.FinalSumSocre == 0 && x.PreSumSocre > 0).OrderBy(x => x.PreSumSocre).ToList();
                sortedAthlete.AddRange(preAths);

                // 写入文件
                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++;

                var tbheadRow = ExcelHelper.GetRow(sheet, rowNum);
                ExcelHelper.SetCellStringValue(tbheadRow, 0, "代表队");
                ExcelHelper.SetCellStringValue(tbheadRow, 1, "运动员");
                ExcelHelper.SetCellStringValue(tbheadRow, 2, "预赛");
                ExcelHelper.SetCellStringValue(tbheadRow, 3, "决赛");
                ExcelHelper.SetCellStringValue(tbheadRow, 4, "名次");
                rowNum++;

                for (var i = 0; i < sortedAthlete.Count; i++)
                {
                    var cellRow = ExcelHelper.GetRow(sheet, rowNum);
                    ExcelHelper.SetCellStringValue(cellRow, 0, sortedAthlete[i].TeamShortName);
                    ExcelHelper.SetCellStringValue(cellRow, 1, sortedAthlete[i].Name);
                    ExcelHelper.SetCellStringValue(cellRow, 2, sortedAthlete[i].PreSumSocre.ToString());
                    ExcelHelper.SetCellStringValue(cellRow, 3, sortedAthlete[i].FinalSumSocre == 0 ? "" : sortedAthlete[i].FinalSumSocre.ToString());
                    ExcelHelper.SetCellStringValue(cellRow, 4, i < 8 ? $"{i + 1}" : "");
                    ++rowNum;
                }

                rowNum++;
            }



            return(rowNum);
        }