Exemplo n.º 1
0
        private void btnValidate_Click(object sender, RoutedEventArgs e)
        {
            double gpa;
            int streetnumber;
            int zipcode;

            if (txtFirstName.Text != "" && txtLastName.Text != "" && txtMajor.Text != "" && txtGPA.Text != "" && txtStreetNumber.Text != ""
                && txtStreetName.Text != "" && txtCity.Text != "" && txtState.Text != "" && txtZipCode.Text != "")
            {
                if (Double.TryParse(txtGPA.Text, out gpa) == true && Int32.TryParse(txtStreetNumber.Text, out streetnumber) == true
                    && Int32.TryParse(txtZipCode.Text, out zipcode) == true)
                {
                    gpa = Convert.ToDouble(txtGPA.Text);
                    streetnumber = Convert.ToInt32(txtStreetNumber.Text);
                    zipcode = Convert.ToInt32(txtZipCode.Text);

                    Student student = new Student();
                    student.FirstName = txtFirstName.Text;
                    student.LastName = txtLastName.Text;
                    student.Major = txtMajor.Text;
                    student.GPA = gpa;
                    student.SetAddress(streetnumber, txtStreetName.Text, txtState.Text, txtCity.Text, zipcode);

                    

                    lstInfo.Items.Add(student);


                }
                else
                {
                    if (Double.TryParse(txtGPA.Text, out gpa) == false)
                    {
                        MessageBox.Show("The GPA you entered is not a valid double.");
                    }
                    if (Int32.TryParse(txtStreetNumber.Text, out streetnumber) == false)
                    {
                        MessageBox.Show("The Street Number you entered is not a valid integer.");
                    }
                    if (Int32.TryParse(txtZipCode.Text, out zipcode) == false)
                    {
                        MessageBox.Show("The Zip Code you entered is not a valid integer.");
                    }
                }
            }
            else
            {
                if (txtFirstName.Text == "")
                {
                    MessageBox.Show("You did not enter a First Name.");
                }
                if (txtLastName.Text == "")
                {
                    MessageBox.Show("You did not enter a Last Name.");
                }
                if (txtMajor.Text == "")
                {
                    MessageBox.Show("You did not enter a Major.");
                }
                if (txtGPA.Text == "")
                {
                    MessageBox.Show("You did not enter a GPA.");
                }
                if (txtStreetNumber.Text == "")
                {
                    MessageBox.Show("You did not enter a Street Number.");
                }
                if (txtStreetName.Text == "")
                {
                    MessageBox.Show("You did not enter a Street Name.");
                }
                if (txtCity.Text == "")
                {
                    MessageBox.Show("You did not enter a City.");
                }
                if (txtState.Text == "")
                {
                    MessageBox.Show("You did not enter a State.");
                }
                if (txtZipCode.Text == "")
                {
                    MessageBox.Show("You did not enter a Zip Code.");
                }
            }
        }