protected void btnSubmit_Click(object sender, EventArgs e) { Team team = new Team(); //make up participant list from textboxes team.FromTextboxes(pnlTxtBx.Controls.OfType<TextBox>().ToList()); // if no participant if (team.Participants.Count == 0) { lblResult.Text = "Enter atleast one TTID"; lblResult.ForeColor = Color.Red; return; } // check if participants are registered in TT //if (!team.Participants.All(i => Participant.CheckParticipantTTID(i.TTID))) //{ // lblResult.Text = "Invalid TTIDs"; // lblResult.ForeColor = Color.Red; // return; //} // register team in this event int teamID = Event.CreateNewTeam(ev, team); bool teamAdded; // error registering in event if (teamID == -1) { lblResult.Text = "Error! Please try again"; lblResult.ForeColor = Color.Red; return; } team.ID = teamID; if (!ev.IsSinglePlayer) //if multiplayer { teamAdded = Team.AddNewTeam(team); // save team data if (teamAdded) { // success lblResult.Text = "Team Created. Team ID is: " + teamID.ToString(); lblResult.ForeColor = Color.Green; } else { //failure lblResult.Text = "Team NOT Added"; lblResult.ForeColor = Color.Red; } } else// if singleplayer { //success lblResult.Text = "Participant Registered"; lblResult.ForeColor = Color.Green; } //clear textboxes pnlTxtBx.Controls.OfType<TextBox>().ToList().ForEach(i => i.Text = ""); }
protected void btnRegister_Click(object sender, EventArgs e) { Team team = new Team(); string result = null; int teamID; bool teamAdded; foreach (Panel pnlEvent in pnlEvents.Controls) { List<CheckBox> c = pnlEvent.Controls.OfType<CheckBox>().ToList(); if(c[0].Checked) { team.FromTextboxes(pnlEvent.Controls.OfType<TextBox>().ToList()); if (team.Participants.Count == 0) { result += "Enter atleast one TTID for <b>" + c[0].Text + "</b>.<br />"; continue; } Event ev = Event.GetEventDetails(int.Parse(pnlEvent.ID)); teamID = Event.CreateNewTeam(ev, team); if (teamID == -1) { result += "Error! Please try again for <b>" + c[0].Text + "</b>.<br />"; continue; } team.ID = teamID; if (!ev.IsSinglePlayer) { teamAdded = Team.AddNewTeam(team); if (teamAdded) { result += "Team ID for <b>" + c[0].Text + "</b> is: <b>" + teamID.ToString() + "</b>.<br />"; } else { result += "Team <b>NOT</b> Added for <b>" + c[0].Text + "</b>.<br />"; } } else { result += "Participant Registered in <b>" + c[0].Text + "</b>.<br />"; } pnlEvent.Controls.OfType<TextBox>().ToList().ForEach(i => i.Text = ""); pnlEvent.Controls.OfType<CheckBox>().ToList().ForEach(i => i.Checked = false); } } lblResult.Text = result; }
protected void btnUpdate_Click(object sender, EventArgs e) { Team t = new Team(); t.ID = int.Parse(txtbxTeamID.Text); t.FromTextboxes(pnlTxtBx.Controls.OfType<TextBox>().ToList()); // if no participant if (t.Participants.Count == 0) { lblResult.Text = "Enter atleast one TTID"; lblResult.ForeColor = Color.Red; txtbxTeamID.Focus(); return; } bool teamDeleted = Team.DeleteTeam(t.ID); if(teamDeleted) { // if all participants registered in TT //if (!t.Participants.All(i => Participant.CheckParticipantTTID(i.TTID))) //{ // lblResult.Text = "Invalid TTIDs"; // lblResult.ForeColor = Color.Red; // return; //} bool teamAdded = Team.AddNewTeam(t); if (teamAdded) { // success lblResult.Text = "Team Updated"; lblResult.ForeColor = Color.Green; } else { //failure lblResult.Text = "Team NOT Updated"; lblResult.ForeColor = Color.Red; } } else { lblResult.Text = "Error! Please try again"; } }