Beispiel #1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            btnRun.Enabled = false;
            // 單淘汰賽
            if (_selectedEvent != null)
            {
                // 取得隊伍數
                int pCount = GetPCount();

                if (_GameList.Count > 0)
                {
                    if (FISCA.Presentation.Controls.MsgBox.Show("當按「是」將刪除舊資料", "刪除舊資料", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // 刪除舊資料
                        DeleteOldGameData();
                    }
                    else
                    {
                        btnRun.Enabled = true;
                        return;
                    }
                }

                Tournaments.SingleElimination se = new Tournaments.SingleElimination(pCount);
                se.startMatching();
                runMatches(se);
                btnRun.Enabled = true;
                _bgwLoadPlayer.RunWorkerAsync();
            }
        }
Beispiel #2
0
        private void _bgwRunReport_DoWork(object sender, DoWorkEventArgs e)
        {
            rptMapDict.Clear();

            System.IO.MemoryStream ms = new System.IO.MemoryStream(Properties.Resources.單淘汰賽程樣板);
            Workbook wb = new Workbook(ms);

            Dictionary <int, UDT.Teams> team = GetTeamLotNoByUID(_selectedEvent.UID);

            // 取得隊伍數
            int pCount = GetPCount();

            Tournaments.SingleElimination se = new Tournaments.SingleElimination(pCount);
            se.startMatching();
            runRptMatches(se);

            int r = rptMapDict.Count;

            int round = 0;

            foreach (int i in rptMapDict.Keys)
            {
                if (i > round)
                {
                    round = i;
                }
            }
            round += 1;
            // 判斷並選擇樣板
            if (_roundTempNameDict.ContainsKey(round))
            {
                string wbTempName = _roundTempNameDict[round];
                wb.Worksheets["Data"].Cells.CopyRows(wb.Worksheets[wbTempName].Cells, 0, 0, 100);
            }

            wb.Worksheets["Data"].IsSelected = true;

            int LeftCol  = 0;
            int LeftRow  = -2;
            int RightRow = -2;
            int RightCol = 3;
            int RightEnd = 0;


            if (round == 3)
            {
                RightEnd = 5;
            }
            else if (round == 4)
            {
                RightEnd = 7;
            }
            else if (round == 5)
            {
                RightEnd = 9;
            }
            else
            {
                RightEnd = 3;
            }

            // 解析位置
            foreach (int i in rptMapDict.Keys)
            {
                // 下向移動位置
                int movRow = int.Parse(Math.Pow(2, (i + 1)).ToString());
                int LRow   = int.Parse(Math.Pow(2, i - 1).ToString());
                // 初始值

                LeftRow  = RightRow = (LRow - 1);
                LeftCol  = i - 1;
                RightCol = (RightEnd - i + 1);

                foreach (DAO.rptCell cel in rptMapDict[i])
                {
                    // 左
                    if (cel.divNo == 1)
                    {
                        cel.Column = LeftCol;
                        cel.Row    = LeftRow;
                        LeftRow   += movRow;
                    }

                    // 右
                    if (cel.divNo == 2)
                    {
                        cel.Column = RightCol;
                        cel.Row    = RightRow;
                        RightRow  += movRow;
                    }
                }
            }


            // 填入 Excel 樣板
            foreach (int i in rptMapDict.Keys)
            {
                foreach (DAO.rptCell cel in rptMapDict[i])
                {
                    if (cel.Team1No == 0 && cel.Team2No == 0 && cel.Row == 0)
                    {
                        continue;
                    }
                    if (team.ContainsKey(cel.Team1No))
                    {
                        wb.Worksheets[0].Cells[cel.Row, cel.Column].PutValue(team[cel.Team1No].Name);
                    }
                    else
                    {
                        wb.Worksheets[0].Cells[cel.Row, cel.Column].PutValue(cel.Team1No);
                    }

                    wb.Worksheets[0].Cells[cel.Row + 1, cel.Column].PutValue(cel.Text);

                    if (team.ContainsKey(cel.Team2No))
                    {
                        wb.Worksheets[0].Cells[cel.Row + 2, cel.Column].PutValue(team[cel.Team2No].Name);
                    }
                    else
                    {
                        wb.Worksheets[0].Cells[cel.Row + 2, cel.Column].PutValue(cel.Team2No);
                    }
                }
            }


            // 清除樣板
            foreach (string name in _roundTempNameDict.Values)
            {
                wb.Worksheets.RemoveAt(name);
            }

            wb.Worksheets["Data"].AutoFitColumns(0, 10);

            try
            {
                _rptName = Application.StartupPath + "\\單淘汰賽.xlsx";
                wb.Save(_rptName);
            }
            catch (Exception ex)
            {
                e.Result = ex.Message;
            }
        }