Beispiel #1
0
 /// <summary>
 /// Parameterized Constructor for the User class. Accepts Name, EmailAddress, and PhoneNumber as parameters
 /// </summary>
 /// <param name="n"></param>
 /// <param name="e"></param>
 /// <param name="p"></param>
 public User(Name n, EmailAddress e, PhoneNumber p)
 {
     if (e.IsValid)
     {
         if (n.IsValid)
         {
             if (p.IsValid)
             {
                 IsValid = true;
                 strName = n.ToString();
                 strEmailAddress = e.Address;
                 strPhoneNumber = p.Number;
             }
             else
                 IsValid = false;
         }
         else
             IsValid = false;
     }
     else
     {
         IsValid = false;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Determines whether the input information was valid, clears fields that contain invalid information,
        /// and highlights that field's label. Called by OKButton_Click and by NameBox_KeyPress, EmailBox_KeyPress,
        /// and PhoneNumber_KeyPress when the enter key is pressed and any of these controls have the focus.
        /// </summary>
        private void FormAccept()
        {
            int InvalidFieldCount = 0;
            UserName = new Name(NameBox.Text);
            UserEmail = new EmailAddress(EmailBox.Text);
            UserPhoneNumber = new PhoneNumber(PhoneNumberBox.Text);

            NewUser = new User(UserName, UserEmail, UserPhoneNumber);
            if (NewUser.IsValid)
            {
                this.Close();
            }
            else
            {
                if (UserName.IsValid == false)
                {
                    UserNameLabel.ForeColor = Color.Red;
                    NameBox.Text = String.Empty;
                    InvalidFieldCount++;
                }
                else
                {
                    UserNameLabel.ForeColor = Color.Black;
                }

                if (UserEmail.IsValid == false)
                {
                    EmailLabel.ForeColor = Color.Red;
                    EmailBox.Text = String.Empty;
                    InvalidFieldCount++;
                }
                else
                {
                    EmailLabel.ForeColor = Color.Black;
                }

                if (UserPhoneNumber.IsValid == false)
                {
                    PhoneNumberLabel.ForeColor = Color.Red;
                    PhoneNumberBox.Text = String.Empty;
                    InvalidFieldCount++;
                }
                else
                {
                    PhoneNumberLabel.ForeColor = Color.Black;
                }

                if (InvalidFieldCount > 1)
                {
                    InstructionBox.Text = "Highlighted fields were invalid. Please enter valid values";
                }
                else
                {
                    InstructionBox.Text = "Highlighted field was invalid. Please enter a valid value";
                }
            }
        }