public void SetGame(UDT.Games ga) { _game = ga; if (_game == null) { _game = new UDT.Games(); } }
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); }