Esempio n. 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);
            }
        }
Esempio n. 2
0
        private void lbGenerateRecordCard_Click(object sender, EventArgs e)
        {
            var groupName = this.cbGroupNames.SelectedItem.ToString();
            var matchId   = MatchId;
            var matchName = MatchName;
            var allSex    = MatchGroupTableDAL.GetAllProjectsByGroup(matchId, groupName); // 男,女,男男,女女,男女

            // 不同性别打印不同的记杆卡,同一性别打印在一个Excle中
            foreach (var sexName in allSex)
            {
                var table = MatchGroupTableDAL.GetEveryGroupTable(matchId, groupName, sexName);

                var gName    = SwitchSexName(sexName);
                var fileName = $"{matchName}-{groupName}-{gName}-记杆卡-{DateTime.Now.ToString("yyyyMMddHHmmss")}";
                ExcelHelperMatchGroup.GenerateRecoredCard(fileName, matchId, matchName, groupName, sexName, table);
            }
        }
Esempio n. 3
0
        public static void GenerateMatchGroup(string fileName, string matchId, string matchName, string groupName)
        {
            IWorkbook workbook = null;
            ISheet    sheet;
            string    path;

            workbook = InitialExcelSheet(fileName, workbook, out sheet, out path);
            // 设置每列宽度
            sheet.SetColumnWidth(0, 3500);
            sheet.SetColumnWidth(1, 3500);
            sheet.SetColumnWidth(2, 3500);
            sheet.SetColumnWidth(3, 3500);
            sheet.SetColumnWidth(4, 3500);
            sheet.SetColumnWidth(5, 3500);

            var row = 0;

            // 设置文档表头
            row = SetTableHeader(workbook, sheet, row, $"竞赛分组表", 450);

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

            foreach (var sexName in allSex.Distinct())
            {
                var sName = SwitchSexName(sexName);
                // 设置表名
                row = SetTableHeader(workbook, sheet, row, $"{matchName}{sName}分组表");

                var table = MatchGroupTableDAL.GetEveryGroupTable(matchId, groupName, sexName);
                if (table.Count == 0)
                {
                    continue;
                }
                var column = table.Max(x => x.Column) + 1;

                // 设置表头
                row = SetColumnHeader(workbook, sheet, row, column);

                // 设置每行人数
                var maxRow = table.Max(x => x.Row);
                for (var i = 0; i < maxRow + 1; i++)
                {
                    var athletesRow   = CreateRow(sheet, row);
                    var rowHeaderCell = SetCellValue(athletesRow, 0, $"第 {i + 1} 组");
                    rowHeaderCell.CellStyle = SetCellStyle(workbook, sheet, row, needBorder: true);

                    var athletes = table.Where(x => x.Row == i).OrderBy(x => x.Column).ToList();
                    for (var j = 0; j < athletes.Count; j++)
                    {
                        var cell = SetCellValue(athletesRow, j + 1, $"{athletes[j].Name} \n {athletes[j].TeamShortName}");
                        cell.CellStyle = SetCellStyle(workbook, sheet, row, needBorder: true);
                        if (athletes[j].IsIndividualGroupMatch && (sexName == "男" || sexName == "女"))
                        {
                            SetCellValue(athletesRow, j + 1, $"{athletes[j].Name} \n {athletes[j].TeamShortName} ■");
                        }
                    }

                    ++row;
                }
            }


            using (FileStream fileStream1 = File.OpenWrite(path))
            {
                workbook.Write(fileStream1);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("报表已生成");
            sb.AppendLine($"路径:{Path.GetDirectoryName(path)}");
            sb.AppendLine($"报表文件:{fileName}.xlsx");

            MessageBox.Show(sb.ToString(), "提示");

            // 打开生成的报表
            System.Diagnostics.Process.Start(path);
        }