Ejemplo n.º 1
0
        private static int PrintWomenGroupScore(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);

                // 分别挑出4人成绩最少杆数一轮,二轮和对team进行排序
                var sortedTeamShortName = SortTeamShortNameByTeamScore(allPartInGroupMatchScore);

                // 遍历每个team, 对运动员按照总分数进行排序
                var sortedAllPartInGroupMatchScore = new List <AthleteSocreModel>();
                for (var i = 0; i < sortedTeamShortName.Count; i++)
                {
                    var sortedTeamAthletesScore = allPartInGroupMatchScore.Where(x => x.TeamShortName == sortedTeamShortName[i] && x.SumSocre > 0).OrderBy(x => x.SumSocre).ToList();
                    if (sortedTeamAthletesScore.Count >= 4) // 当团体赛人数少于4时,不计入团体赛成绩
                    {
                        sortedAllPartInGroupMatchScore.AddRange(sortedTeamAthletesScore);
                    }
                }

                // 写入文件
                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, "名次");
                rowNum++;

                // 写入每队人员成绩
                var allTeamShortNames = sortedAllPartInGroupMatchScore.Select(x => x.TeamShortName).Distinct().ToList();
                for (var i = 0; i < allTeamShortNames.Count && i < 8; i++)
                {
                    rowNum = SetTeamAthletes(sortedAllPartInGroupMatchScore.Where(x => x.TeamShortName == allTeamShortNames[i]).ToList(), rowNum, sheet, i + 1);
                }

                rowNum++;
            }

            return(rowNum);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 打印女子团体成绩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbWomenTeamScoreSummaryTable_Click(object sender, EventArgs e)
        {
            var selectedRow = dataGridViewX1.SelectedRows[0];

            if (selectedRow == null)
            {
                return;
            }
            var matchId   = selectedRow.Cells[0].Value.ToString();
            var matchName = selectedRow.Cells[1].Value.ToString();

            var matchInfo = MatchDAL.GetMatchInfoById(matchId);

            // 总合计
            if (matchInfo.ScoringMethod == "总合计")
            {
                // 获取所有分组
                var allGroupNames = AthletesDAL.GetAllGroupNames(matchId);

                // 遍历每组人员,获取所有运动员成绩
                foreach (var groupName in allGroupNames.OrderBy(x => x))
                {
                    var allPartInGroupMatchScore = AthletesDAL.GetTeamMatchAthletesScore(matchId, groupName, "女", 2);

                    // 分别挑出4人成绩最少杆数个人对team进行排序
                    var sortedTeamShortName = SortTeamShortNameByTeamPersonScore(allPartInGroupMatchScore);

                    // 遍历每个team, 对运动员按照总分数进行排序
                    var sortedAllPartInGroupMatchScore = new List <AthleteSocreModel>();
                    for (var i = 0; i < sortedTeamShortName.Count; i++)
                    {
                        var sortedTeamAthletesScore = allPartInGroupMatchScore
                                                      .Where(x => x.TeamShortName == sortedTeamShortName[i] && x.SumSocre > 0)
                                                      .OrderBy(x => x.SumSocre)
                                                      .ToList();
                        if (sortedTeamAthletesScore.Count >= 4) // 当团体赛人数少于4时,不计入团体赛成绩
                        {
                            sortedAllPartInGroupMatchScore.AddRange(sortedTeamAthletesScore);
                        }
                    }

                    // 导出文件
                    var fileName = $"{matchName}-{groupName}-女子团体成绩-{DateTime.Now.ToString("yyyyMMddHHmmss")}";
                    ExcelHelperPrintTeamScoreSummaryTable.GenerateTeamScoreSummaryPersonalTable(sortedAllPartInGroupMatchScore, matchName, groupName, "女", fileName);
                }
            }
            // 分开合计
            else
            {
                // 获取所有分组
                var allGroupNames = AthletesDAL.GetAllGroupNames(matchId);

                // 遍历每组人员,获取所有运动员成绩
                foreach (var groupName in allGroupNames.OrderBy(x => x))
                {
                    var allPartInGroupMatchScore = AthletesDAL.GetTeamMatchAthletesScore(matchId, groupName, "女", 2);

                    // 分别挑出4人成绩最少杆数一轮,二轮和对team进行排序
                    var sortedTeamShortName = SortTeamShortNameByTeamScore(allPartInGroupMatchScore);

                    // 遍历每个team, 对运动员按照总分数进行排序
                    var sortedAllPartInGroupMatchScore = new List <AthleteSocreModel>();
                    for (var i = 0; i < sortedTeamShortName.Count; i++)
                    {
                        var sortedTeamAthletesScore = allPartInGroupMatchScore.Where(x => x.TeamShortName == sortedTeamShortName[i] && x.SumSocre > 0).OrderBy(x => x.SumSocre).ToList();
                        if (sortedTeamAthletesScore.Count >= 4) // 当团体赛人数少于4时,不计入团体赛成绩
                        {
                            sortedAllPartInGroupMatchScore.AddRange(sortedTeamAthletesScore);
                        }
                    }

                    // 导出文件
                    var fileName = $"{matchName}-{groupName}-女子团体成绩-{DateTime.Now.ToString("yyyyMMddHHmmss")}";
                    ExcelHelperPrintTeamScoreSummaryTable.GenerateTeamScoreSummaryTable(sortedAllPartInGroupMatchScore, matchName, groupName, "女", fileName);
                }
            }
        }
Ejemplo n.º 3
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);
        }