Ejemplo 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.");
                }
            }
        }
Ejemplo n.º 2
0
        private void SubmitInfor_Click(object sender, RoutedEventArgs e)
        {
            bool Success; //used this soluton from the video

            if (string.IsNullOrWhiteSpace(FirstNameBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid First Name");
            }
            if (string.IsNullOrWhiteSpace(LastNameBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid Last Name");
            }
            if (string.IsNullOrWhiteSpace(MajorBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid Major");
            }
            double GPA;

            if (double.TryParse(GPABox.Text, out GPA) == false)
            {
                Success = false;
                MessageBox.Show("Enter valid GPA");
            }
            int Zip;

            if (int.TryParse(ZipcodeBox.Text, out Zip) == false)
            {
                Success = false;
                MessageBox.Show("Enter valid Zip Code");
            }
            //

            if (string.IsNullOrWhiteSpace(streetNameBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid Street Name");
            }
            if (string.IsNullOrWhiteSpace(cityBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid City ");
            }
            if (string.IsNullOrWhiteSpace(stateBox.Text) == true)
            {
                Success = false;
                MessageBox.Show("Enter valid State");
            }
            int streetnumber;

            if (int.TryParse(streetNumberBox.Text, out streetnumber) == false)
            {
                Success = false;
                MessageBox.Show("Enter a valid Street Number");
            }
            if (Success = false)
            {
                return;
            }

            Student student = new Student()
            {
                FirstName = FirstNameBox.Text,
                LastName  = LastNameBox.Text,
                GPA       = GPA,
                Major     = MajorBox.Text
            };

            student.SetAddress(streetnumber, streetNameBox.Text, stateBox.Text, cityBox.Text, Zip);
            StudentListBox.Items.Add(student);
        }