/// <summary> /// this methods clears the textboxes on the form and reset other properties /// </summary> private void ClearFrom() { NameTextBox.Clear(); AgeTextBox.Clear(); SubmitButton.Enabled = false; }
/// <summary> /// this method clears the text boxes on the form /// </summary> private void ClearForm() { NameTextBox.Clear(); AgeTextBox.Clear(); }
/// <summary> /// clearing form + initialization /// </summary> private void ClearForm() { SubmitButton.Enabled = false; NameTextBox.Clear(); AgeTextBox.Clear(); }
private void MakingCompetitors() //Makes our competitors. { if (AgeCheck() == true) //If the AgeCheck method returns true then we don't do anything and the code continues. { } else //If AgeCheck returns false we return an error message and try again. { MessageBox.Show("Please enter a number between 12 and 70 for your age."); AgeTextBox.Clear(); return; } if (NewNameTextBox.Text.Trim() == "") //If there is no name entered when you're making a competitor then it will be rejected. { MessageBox.Show("Please enter your name."); //The error message. } else if (NewCompetitorAddressTextBox.Text.Trim() == "") //If there is no address entered when you're making a competitor then it will be rejected. { MessageBox.Show("Please enter your address."); //The error message. } else if (AmateurRadioButton.IsChecked == false && ProfessionalRadioButton.IsChecked == false && CelebrityRadioButton.IsChecked == false) //If there is no class selected when you're making a competitor then it will be rejected. { MessageBox.Show("Please choose your class."); //The error message. } else if (AmateurRadioButton.IsChecked == true) //Makes an amateur competitor. { string ID = "Amateur"; //Gives the competitor their class ID. SkiRun.AddAmateurCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore); //Calls the amateur creator method in the SkiRun class. CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString(); //Gets the competitor number. MessageBox.Show("Competitor Created!"); //Message for when you have created your competitor. ClearText(); //Calls the ClearText method which clears all of the text. } else if (ProfessionalRadioButton.IsChecked == true) //Makes a professional competitor. { if (SponsorTextBox.Text == "") //If no sponsor is selected it will be rejected. { MessageBox.Show("Please enter a sponsor!"); //The error message. } else //If there is a sponsor then we continue onto the creation. { string ID = "Professional"; //Gives the competitor their class ID. SkiRun.AddProfessionalCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore, SponsorTextBox.Text.Trim()); //Calls the professional creator method in the SkiRun class. CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString(); //Gets the competitor number. MessageBox.Show("Competitor Created!"); //Message for when you have created your competitor. ClearText(); //Calls the ClearText method which clears all of the text. } } else if (CelebrityRadioButton.IsChecked == true) //Makes a celebrity competitor. { if (BloodTypeTextBox.Text.Trim() == "" || NextOfKinTypeTextBox.Text.Trim() == "") //If there is no blood type and/or next of kin then the cpmpetitor will be rejected. { MessageBox.Show("Please enter a blood type, next of kin or both!"); //The error message. } else { string ID = "Celebrity"; //Gives the competitor their class ID. SkiRun.AddCelebrityCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore, BloodTypeTextBox.Text.Trim(), NextOfKinTypeTextBox.Text.Trim()); //Calls the celebrity creator method in the SkiRun class. CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString(); //Gets the competitor number. MessageBox.Show("Competitor Created!"); //Message for when you have created your competitor. ClearText(); //Calls the ClearText method which clears all of the text. } } }
//Submit button private void button1_Click(object sender, EventArgs e) { //First Name validiation and parsing string firstName = firstNameTextBox.Text; if (firstName.Length < 1 || firstName.Length > 32) { MessageBox.Show("First Name must be between 1-32 characters long"); return; } if (!Regex.IsMatch(firstName, @"^[a-zA-Z]+$")) { MessageBox.Show("First Name can only contain alphabetic characters"); return; } //Last Name validiation and parsing string lastName = lastNameTextBox.Text; if (lastName.Length < 1 || lastName.Length > 32) { MessageBox.Show("Last Name must be between 1-32 characters long"); return; } if (!Regex.IsMatch(lastName, @"^[a-zA-Z]+$")) { MessageBox.Show("Last Name can only contain alphabetic characters"); return; } //BattleRosterNumber validation and parsing string battleRosterNumber = battleRosterNumberTextBox.Text; if (!Regex.IsMatch(battleRosterNumber, @"^[A-Z][A-Z][0-9][0-9][0-9][0-9]$")) { MessageBox.Show("Battle Roster Number must first 2 intials of last name in upercase and last 4 SSN numbers. (ie. AB1234)"); return; } //Height validation and parsing float height; if (float.TryParse(HeightTextBox.Text, out height)) { if (height < 1.0 || height > 12.0) { MessageBox.Show("Enter a valid height"); return; } } else { MessageBox.Show("Enter a valid height"); return; } //Weight validation and parsing float weight; if (float.TryParse(WeightTextBox.Text, out weight)) { if (weight < 1.0 || weight > 600.0) { MessageBox.Show("Enter a valid weight"); return; } } else { MessageBox.Show("Enter a valid weight"); return; } //Age validation and parsing int age; if (int.TryParse(AgeTextBox.Text, out age)) { if (age < 17 || age > 110) { MessageBox.Show("Enter a valid age"); return; } } else { MessageBox.Show("Enter a valid age"); return; } //Heat Casualty selection bool heatCat = true; if (HeatCatNoRadioButton.Checked) { heatCat = false; } if (HeatCatYesRadioButton.Checked) { heatCat = true; } //Male Female selection char sex = 'M'; if (SexMaleRadioButton.Checked) { sex = 'M'; } if (SexFemaleRadioButton.Checked) { sex = 'F'; } //Add data to the xmloader class Solider solider = new Solider(firstName, lastName, battleRosterNumber, heatCat, height, weight, sex); Program.xLoader.AddSoliderToRoster(solider); //Clear all data from textboxs and reset radio buttons firstNameTextBox.Clear(); lastNameTextBox.Clear(); battleRosterNumberTextBox.Clear(); HeightTextBox.Clear(); WeightTextBox.Clear(); AgeTextBox.Clear(); HeatCatYesRadioButton.Checked = true; SexMaleRadioButton.Checked = true; //Hide Form and return to previous form menuButtonPressed = true; FormProvider.AddSolider.Close(); FormProvider.RosterDisplay.Show(); }