private void btnSubmit_Click(object sender, EventArgs e) { // TODO: Add code to add a new game object to the array and list int rosterInt = Convert.ToInt16(txtBxRosterSize.Text); int budgetInt; int assitantInt; bool proBool = txtBxProfessional.Text == "True"; bool cheerleadersBool = txtBxCheerleaders.Text == "True"; // validate form data if (int.TryParse(txtBxRosterSize.Text, out rosterInt)) { if (int.TryParse(txtBxAssistant.Text, out assitantInt)) { // use form data to create a new instance Team newTeam = new SubTeam(txtBxTeamName.Text, rosterInt, txtBxCoach.Text, txtBxSportName.Text, proBool, assitantInt, cheerleadersBool); // add the new instance to the list box lstBxTeams.Items.Add(newTeam); } else if (int.TryParse(txtBxUniform.Text, out budgetInt)) { // use form data to create a new instance Team newTeam = new SubTeam2(txtBxTeamName.Text, rosterInt, txtBxCoach.Text, txtBxSportName.Text, proBool, txtBxSponsor.Text, budgetInt); // add the new instance to the list box lstBxTeams.Items.Add(newTeam); } } // set current row to zero currentRow = 0; }
/// <summary> /// put data from sub team 2 games into form text boxes /// </summary> /// <param name="item"></param> private void LoadSub2Data(SubTeam2 item) { grpSubTeam1.Visible = false; grpSubTeam2.Visible = true; txtBxSponsor.Text = item.NameMainSponsor; txtBxUniform.Text = item.DollarsUniformBudget.ToString(); }
public static Team[] BuildData() { teamList = new Team[20]; for (int i = 0; i < 10; i++) { teamList[i] = new SubTeam($"teamName{i}", 24, $"coachName{i}", $"sportName{i}", true, 99, true); } for (int i = 10; i < 20; i++) { teamList[i] = new SubTeam2($"teamName{i}", 42, $"coachName{i}", $"sportName{i}", true, $"nameMainSponsor", 77); } return(teamList); }
private void lstBxSports_SelectedIndexChanged(object sender, EventArgs e) { currentRow = lstBxTeams.SelectedIndex; Team item = (Team)lstBxTeams.SelectedItem; if (item is SubTeam) { SubTeam teamItem = (SubTeam)item; LoadTeamData(teamItem); LoadSub1Data(teamItem); } else { SubTeam2 teamItem = (SubTeam2)item; LoadTeamData(teamItem); LoadSub2Data(teamItem); } // end else } // end of method
//load the form by preparingtest data private void Form1_Load(object sender, EventArgs e) { btnSubmit.Visible = false; teamList = SportsTester.BuildData(); foreach (var item in teamList) { if (item is SubTeam) { SubTeam teamItem = (SubTeam)item; lstBxTeams.Items.Add(item); } else { SubTeam2 teamItem = (SubTeam2)item; lstBxTeams.Items.Add(item); } } EnDisFields(false); }
private void btnUpdate_Click(object sender, EventArgs e) { // TODO: Add code to update the current row // update the game instance in the listbox int rosterInt = Convert.ToInt16(txtBxRosterSize.Text); int budgetInt; int assitantInt; bool proBool = txtBxProfessional.Text == "True"; bool cheerleadersBool = txtBxCheerleaders.Text == "True"; // validate form data // validate form data if (int.TryParse(txtBxRosterSize.Text, out rosterInt)) { if (int.TryParse(txtBxAssistant.Text, out assitantInt)) { // use form data to create a new instance Team newTeam = new SubTeam(txtBxTeamName.Text, rosterInt, txtBxCoach.Text, txtBxSportName.Text, proBool, assitantInt, cheerleadersBool); // delete old record and add the new instance to the list box currentRow = lstBxTeams.SelectedIndex; lstBxTeams.Items.RemoveAt(currentRow); // above line deletes entry but then gives error from LoadTeamData() since it now sees nulls instead of expected values lstBxTeams.Items.Add(newTeam); } else if (int.TryParse(txtBxUniform.Text, out budgetInt)) { // use form data to create a new instance Team newTeam = new SubTeam2(txtBxTeamName.Text, rosterInt, txtBxCoach.Text, txtBxSportName.Text, proBool, txtBxSponsor.Text, budgetInt); // delete old record and add the new instance to the list box currentRow = lstBxTeams.SelectedIndex; lstBxTeams.Items.RemoveAt(currentRow); // above line deletes entry but then gives error from LoadTeamData() since it now sees nulls instead of expected values lstBxTeams.Items.Add(newTeam); } } }