private void btnAddToGames_Click(object sender, EventArgs e) { if (!ValidateChildren()) { return; } if (lbTeams.SelectedItems.Count == 2) { Game game = new Game(); game.Code = mtbCode.Text; game.HomeTeam = lbTeams.SelectedItems[0] as Team; game.GuestTeam = (Team)lbTeams.SelectedItems[1]; game.Coefitients[0] = (float)nudCoef1.Value; game.Coefitients[1] = (float)nudCoefX.Value; game.Coefitients[2] = (float)nudCoef2.Value; if (!containsTeam(game)) { lbGames.Items.Add(game); nudCoef1.ResetText(); nudCoefX.ResetText(); nudCoef2.ResetText(); lbTeams.ClearSelected(); mtbCode.Clear(); } else { MessageBox.Show("Овој натпревар е веќе внесен!"); } } else { MessageBox.Show("Избери точно 2 тима!"); } }
bool containsTeam(Game game) { for (int i = 0; i < lbGames.Items.Count; i++) { Game g = lbGames.Items[i] as Game; if (g.Code.Equals(game.Code)) { return true; } } return false; }