private void Txb_LastName_Validating(object sender, CancelEventArgs e)
 {
     try
     {
         string lastName = Txb_LastName.Text;
         if (lastName == string.Empty)
         {
             this.EP_ErrorMessage.SetError(Txb_LastName, GlobalStrings.FailureInputTxbNames_Empty);
             e.Cancel = true;
         }
         else if (!Char.IsUpper(lastName[0]))
         {
             EP_ErrorMessage.SetError(Txb_LastName, GlobalStrings.FailureInputTxbNames_InvalidFirstLetter);
             e.Cancel = true;
         }
         else
         {
             this.EP_ErrorMessage.Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void Txb_Amount_Validating(object sender, CancelEventArgs e)
        {
            char invalidChar;

            try
            {
                if (this.Text == "Payments")
                {
                    invalidChar = ',';
                }
                else
                {
                    invalidChar = '.';
                }
                if (!Double.TryParse(Txb_Amount.Text, out double money) || Txb_Amount.Text.Contains(invalidChar))
                {
                    this.EP_ErrorMessage.SetError(Txb_Amount, GlobalStrings.FailureTxbAmount);
                    e.Cancel = true;
                }
                else
                {
                    EP_ErrorMessage.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
 private void Txb_MoneyAccount_Validating(object sender, CancelEventArgs e)
 {
     try
     {
         if (!Double.TryParse(Txb_MoneyAccount.Text, out double money))
         {
             this.EP_ErrorMessage.SetError(Txb_MoneyAccount, GlobalStrings.FailureTxbAmount);
             e.Cancel = true;
         }
         else
         {
             EP_ErrorMessage.Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void Txb_EmailAddress_Validating(object sender, CancelEventArgs e)
        {
            string emailAddress   = Txb_EmailAddress.Text;
            bool   isEmailcorrect = false;
            int    counter        = 0;
            int    counterPoint   = 0;

            try
            {
                // E-mail address must have at least one . after the @ and must contain exactly one @
                for (int i = 0; i < emailAddress.Length; i++)
                {
                    if (emailAddress[i] == '@')
                    {
                        counter++; // counter for the @
                        for (int j = i; j < emailAddress.Length; j++)
                        {
                            if (emailAddress[j] == '.')
                            {
                                counterPoint++; // counter for the points
                            }
                        }
                        if (counter == 1 && counterPoint != 0)
                        {
                            isEmailcorrect = true;
                        }
                    }
                }// end for-loop
                int counterCharactersAfterPoint = 0;
                for (int i = emailAddress.Length - 1; i >= 0; i--)
                {
                    if (emailAddress[i] == '.' && counterCharactersAfterPoint >= 2 && counterCharactersAfterPoint <= 4)
                    {
                        isEmailcorrect = true;
                        break;
                    }
                    else if (Char.IsLetter(emailAddress[i]))
                    {
                        counterCharactersAfterPoint++;
                    }
                    else
                    {
                        isEmailcorrect = false;
                        break;
                    }
                }
                if (!isEmailcorrect)
                {
                    EP_ErrorMessage.SetError(Txb_EmailAddress, GlobalStrings.FailureInputTxbEmail);
                    e.Cancel = true;
                }
                else
                {
                    EP_ErrorMessage.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }