private async void btnTournament_Click(object sender, EventArgs e)// create a web tournament first to store all the team and members { Button tmp = (Button)sender; tmp.Enabled = false;// unless you create a tournament, or you are not allow to submit the team and members if (String.IsNullOrWhiteSpace(txtTournament.Text)) { MessageBox.Show("Please name a tournament before you add/update it.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Tournament tournament = new Tournament(txtTournament.Text); string result = await ApiHandler.addTournament(tournament); tournament = ApiHandler.jsonTo <Tournament>(result); tournamentID = tournament.id; } }
private async void TNBox1_Validated(object sender, EventArgs e) // once you enter the team that in the tournament, it will auto fill the memebers' name { int counter = 0; Team tmpTeam = new Team(); TextBox tmp = (TextBox)sender; string result = await ApiHandler.getTeams(Test.tournamentID); List <Team> teams = ApiHandler.jsonTo <List <Team> >(result); foreach (Team t in teams) { if (t.name.Equals(TNBox1.Text)) { tmpTeam = t;// get the team we entered in the team name box team1ID = t.id; break; } } result = await ApiHandler.getPlayers(tmpTeam.id); List <Player> players = ApiHandler.jsonTo <List <Player> >(result); foreach (Control c in tmp.Parent.Controls) //get all the members' name and auto fill it { if (c is GroupBox) { if (c.Name.Equals("Team1")) { foreach (Control t in c.Controls) { if (t is TextBox) { t.Text = players[counter].name; counter++; } } } } } }
// same with team name box 1 private async void TNBox2_Validated(object sender, EventArgs e) { int counter = 0; Team tmpTeam = new Team(); TextBox tmp = (TextBox)sender; string result = await ApiHandler.getTeams(Test.tournamentID); List <Team> teams = ApiHandler.jsonTo <List <Team> >(result); foreach (Team t in teams) { if (t.name.Equals(TNBox2.Text)) { tmpTeam = t; team2ID = t.id; break; } } result = await ApiHandler.getPlayers(tmpTeam.id); List <Player> players = ApiHandler.jsonTo <List <Player> >(result); foreach (Control c in tmp.Parent.Controls) { if (c is GroupBox) { if (c.Name.Equals("Team2")) { foreach (Control t in c.Controls) { if (t is TextBox) { t.Text = players[counter].name; counter++; } } } } } }
private async void btnTeam1_Click(object sender, EventArgs e)// send members and teams to web database { Button tmpBtn = (Button)sender; tmpBtn.Enabled = false; if (string.IsNullOrWhiteSpace(txtTournament.Text) || btnTournament.Enabled == true) { MessageBox.Show("Please name a tournament before you add/update it.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); tmpBtn.Enabled = true; } foreach (Control g in tmpBtn.Parent.Controls)// for loop to look all datas { if (g is GroupBox) { int columnCount = 0; DataGridViewRowCollection rows = table.board.Rows; teamCount = Convert.ToInt32(table.board.RowCount) + 1; object[] contains = new object[12]; contains[columnCount] = Convert.ToString(teamCount); columnCount++; foreach (Control c in g.Controls)// add all the details to the database and the datagridview in score board { if (c is TextBox) { if (String.IsNullOrWhiteSpace(c.Text)) { MessageBox.Show("Please name a team or fill in names of all members.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); tmpBtn.Enabled = true; break; } else { if (c.Tag.Equals("1"))// if is team name { Team team = new Team(c.Text); contains[columnCount] = team.name; //add team name to scoreboard columnCount++; for (int i = 0; i < 5; i++) // all records set to 0 { contains[columnCount] = 0; columnCount++; } string result = await ApiHandler.addTeam(tournamentID, team); team = ApiHandler.jsonTo <Team>(result); teamID = team.id; } else { Player player = new Player(c.Text);// add all players contains[columnCount] = player.name; await ApiHandler.addPlayer(teamID, player); } } } } rows.Add(contains);//add to the datagridview } } tmpBtn.Enabled = true; btnTournament.Enabled = true; table.Show();// show the score board with teams you have }
private async void endMatch_Click(object sender, EventArgs e) { //only work when all 3 rounds over if (roundNum == 4) { Match match = new Match("qual", "1"); await ApiHandler.addTeamToMatch(Test.tournamentID, team1ID, match); await ApiHandler.addTeamToMatch(Test.tournamentID, team2ID, match); // if team1 win this match if (team1RoundWin > team2RoundWin) { foreach (DataGridViewRow row in Test.table.board.Rows) { //find the match who win, add win and score if (Convert.ToString(row.Cells[1].Value).Equals(TNBox1.Text)) { row.Cells[2].Value = Convert.ToInt32(row.Cells[2].Value) + 1; row.Cells[5].Value = Convert.ToInt32(row.Cells[5].Value) + 2; Score score = new Score(Convert.ToString(row.Cells[5].Value)); await ApiHandler.updateScore(Test.tournamentID, team1ID, match.number, score); } //find the match who lose, add lose if (Convert.ToString(row.Cells[1].Value).Equals(TNBox2.Text)) { row.Cells[3].Value = Convert.ToInt32(row.Cells[3].Value) + 1; } } } // if team2 wins this match else if (team1RoundWin < team2RoundWin) { foreach (DataGridViewRow row in Test.table.board.Rows) { if (Convert.ToString(row.Cells[1].Value).Equals(TNBox2.Text)) { row.Cells[2].Value = Convert.ToInt32(row.Cells[2].Value) + 1; row.Cells[5].Value = Convert.ToInt32(row.Cells[5].Value) + 2; Score score = new Score(Convert.ToString(row.Cells[5].Value)); await ApiHandler.updateScore(Test.tournamentID, team2ID, match.number, score); } if (Convert.ToString(row.Cells[1].Value).Equals(TNBox1.Text)) { row.Cells[3].Value = Convert.ToInt32(row.Cells[3].Value) + 1; } } } else// ties { foreach (DataGridViewRow row in Test.table.board.Rows) { if (Convert.ToString(row.Cells[1].Value).Equals(TNBox1.Text)) { row.Cells[4].Value = Convert.ToInt32(row.Cells[4].Value) + 1; row.Cells[5].Value = Convert.ToInt32(row.Cells[5].Value) + 1; Score score = new Score(Convert.ToString(row.Cells[5].Value)); await ApiHandler.updateScore(Test.tournamentID, team2ID, match.number, score); } if (Convert.ToString(row.Cells[1].Value).Equals(TNBox2.Text)) { row.Cells[4].Value = Convert.ToInt32(row.Cells[4].Value) + 1; row.Cells[5].Value = Convert.ToInt32(row.Cells[5].Value) + 1; Score score = new Score(Convert.ToString(row.Cells[5].Value)); await ApiHandler.updateScore(Test.tournamentID, team2ID, match.number, score); } } } //add TP to two teams that attend this match foreach (DataGridViewRow row in Test.table.board.Rows) { if (Convert.ToString(row.Cells[1].Value).Equals(TNBox1.Text)) { row.Cells[6].Value = Convert.ToInt32(row.Cells[6].Value) + team1FinalScore; } if (Convert.ToString(row.Cells[1].Value).Equals(TNBox2.Text)) { row.Cells[6].Value = Convert.ToInt32(row.Cells[6].Value) + team2FinalScore; } } // sort the score table base on the score Test.table.board.Sort(Test.table.board.Columns[6], ListSortDirection.Descending); int rank = 1; // give it correct rank foreach (DataGridViewRow row in Test.table.board.Rows) { row.Cells[0].Value = rank; rank++; } } }