Пример #1
0
        private void runMatches(SingleElimination se)
        {
            StringBuilder resultHTML = new StringBuilder();
            AccessHelper  acc        = new AccessHelper();

            List <UDT.Games>          addGameLeftList   = new List <UDT.Games>();
            List <UDT.Games>          addGameRightList  = new List <UDT.Games>();
            List <UDT.GameCandidates> addGameCandidates = new List <UDT.GameCandidates>();
            int ref_event_id = int.Parse(_selectedEvent.UID);

            int x = se.roundCount;

            if (se.roundCount > 1)
            {
                x = se.roundCount - 1;
            }

            for (int i = 0; i < x; i++)
            {
                List <Match> mat1s = se.getMatchesOfDiv(1, i + 1);
                if (mat1s.Count > 0)
                {
                    foreach (Match m in mat1s)
                    {
                        if (m.is_virtual)
                        {
                            String msg = @"左空白\n";
                            resultHTML.Append(msg);
                        }
                        else
                        {
                            UDT.Games gL = new UDT.Games();
                            gL.RefEventId = ref_event_id;
                            gL.UUID       = Guid.NewGuid().ToString();
                            gL.GameNo     = m.no;
                            gL.RoundNo    = m.round_no;
                            gL.CreatedBy  = _userAccount;

                            int c1 = m.getCandidates()[0].lotsNo;
                            int c2 = m.getCandidates()[1].lotsNo;
                            gL.LotNo1 = c1;
                            gL.LotNo2 = c2;
                            addGameLeftList.Add(gL);
                            string msg = @"左 {0}({1} - {2}){3}\n";
                            resultHTML.Append(String.Format(msg, c1, m.round_no, m.no, c2));
                        }
                    }
                }
            }

            x = se.roundCount - 1;
            if (se.roundCount > 1)
            {
                x = se.roundCount - 2;
            }

            for (int i = x; i > -1; i--)
            {
                List <Match> mat2s = se.getMatchesOfDiv(2, i + 1);
                //console.log(` === div:2, round:${i+1}, matches count: ${(mat2s ? mat2s.length : 0)}`)
                if (mat2s.Count > 0)
                {
                    foreach (Match m in mat2s)
                    {
                        // console.log( m );
                        if (m.is_virtual)
                        {
                            string msg = @"右空白\n";
                            resultHTML.Append(msg);
                        }
                        else
                        {
                            UDT.Games gR = new UDT.Games();
                            gR.RefEventId = ref_event_id;
                            gR.UUID       = Guid.NewGuid().ToString();
                            gR.GameNo     = m.no;
                            gR.RoundNo    = m.round_no;
                            gR.CreatedBy  = _userAccount;
                            int c1 = m.getCandidates()[0].lotsNo;
                            int c2 = m.getCandidates()[1].lotsNo;
                            gR.LotNo1 = c1;
                            gR.LotNo2 = c2;

                            addGameRightList.Add(gR);

                            string msg = @"右 {0}({1} - {2}){3}\n";
                            resultHTML.Append(String.Format(msg, c1, m.round_no, m.no, c2));
                        }
                    }
                }
            }

            if (addGameLeftList.Count > 0)
            {
                addGameLeftList.SaveAll();
                // 處理第一輪
                List <UDT.Games> gL = acc.Select <UDT.Games>("ref_event_id = " + ref_event_id + " AND round_no=1");
                if (gL.Count > 0)
                {
                    foreach (UDT.Games data in gL)
                    {
                        UDT.GameCandidates gc = new UDT.GameCandidates();
                        gc.RefGameId   = int.Parse(data.UID);
                        gc.RefGameUuid = data.UUID;
                        gc.UUID        = Guid.NewGuid().ToString();
                        gc.DivNo       = 1;
                        gc.CreatedBy   = _userAccount;
                        addGameCandidates.Add(gc);
                    }
                }
            }

            if (addGameRightList.Count > 0)
            {
                addGameRightList.SaveAll();
                // 處理第一輪
                List <UDT.Games> gL = acc.Select <UDT.Games>("ref_event_id = " + ref_event_id + " AND round_no=1");
                if (gL.Count > 0)
                {
                    foreach (UDT.Games data in gL)
                    {
                        UDT.GameCandidates gc = new UDT.GameCandidates();
                        gc.RefGameId   = int.Parse(data.UID);
                        gc.RefGameUuid = data.UUID;
                        gc.UUID        = Guid.NewGuid().ToString();
                        gc.DivNo       = 2;
                        gc.CreatedBy   = _userAccount;
                        addGameCandidates.Add(gc);
                    }
                }
            }

            if (addGameCandidates.Count > 0)
            {
                addGameCandidates.SaveAll();
            }

            Console.WriteLine(resultHTML);
        }
Пример #2
0
        private void runRptMatches(SingleElimination se)
        {
            StringBuilder resultHTML = new StringBuilder();

            int x = se.roundCount;

            if (se.roundCount > 1)
            {
                x = se.roundCount - 1;
            }

            for (int i = 0; i < x; i++)
            {
                List <Match> mat1s = se.getMatchesOfDiv(1, i + 1);
                if (mat1s.Count > 0)
                {
                    foreach (Match m in mat1s)
                    {
                        if (m.is_virtual)
                        {
                            String msg = @"左空白\n";
                            resultHTML.Append(msg);
                            //if (!rptMapDict.ContainsKey(0))
                            //    rptMapDict.Add(0, new List<DAO.rptCell>());
                            //DAO.rptCell cell = new DAO.rptCell();
                            //cell.divNo = 1;
                            //cell.Text = "空白";
                            //rptMapDict[0].Add(cell);
                        }
                        else
                        {
                            int    c1  = m.getCandidates()[0].lotsNo;
                            int    c2  = m.getCandidates()[1].lotsNo;
                            string msg = @"左 {0}({1} - {2}){3}\n";

                            if (!rptMapDict.ContainsKey(m.round_no))
                            {
                                rptMapDict.Add(m.round_no, new List <DAO.rptCell>());
                            }

                            DAO.rptCell cell = new DAO.rptCell();
                            cell.GameNo  = m.no;
                            cell.RoundNo = m.round_no;
                            cell.Team1No = c1;
                            cell.Team2No = c2;
                            cell.divNo   = 1;
                            cell.Text    = "(" + m.round_no + "回-" + m.no + "場)";
                            rptMapDict[m.round_no].Add(cell);

                            resultHTML.Append(String.Format(msg, c1, m.round_no, m.no, c2));
                        }
                    }
                }
            }

            x = se.roundCount - 1;
            if (se.roundCount > 1)
            {
                x = se.roundCount - 2;
            }

            for (int i = x; i > -1; i--)
            {
                List <Match> mat2s = se.getMatchesOfDiv(2, i + 1);
                if (mat2s.Count > 0)
                {
                    foreach (Match m in mat2s)
                    {
                        // console.log( m );
                        if (m.is_virtual)
                        {
                            string msg = @"右空白\n";
                            resultHTML.Append(msg);
                            //if (!rptMapDict.ContainsKey(0))
                            //    rptMapDict.Add(0, new List<DAO.rptCell>());
                            //DAO.rptCell cell = new DAO.rptCell();
                            //cell.divNo = 2;
                            //cell.Text = "空白";
                            //rptMapDict[0].Add(cell);
                        }
                        else
                        {
                            int    c1  = m.getCandidates()[0].lotsNo;
                            int    c2  = m.getCandidates()[1].lotsNo;
                            string msg = @"右 {0}({1} - {2}){3}\n";

                            if (!rptMapDict.ContainsKey(m.round_no))
                            {
                                rptMapDict.Add(m.round_no, new List <DAO.rptCell>());
                            }

                            DAO.rptCell cell = new DAO.rptCell();
                            cell.GameNo  = m.no;
                            cell.RoundNo = m.round_no;
                            cell.Team1No = c1;
                            cell.Team2No = c2;
                            cell.divNo   = 2;
                            cell.Text    = "(" + m.round_no + "回-" + m.no + "場)";
                            rptMapDict[m.round_no].Add(cell);

                            resultHTML.Append(String.Format(msg, c1, m.round_no, m.no, c2));
                        }
                    }
                }
            }

            Console.WriteLine(resultHTML);
        }