/// <summary> /// Метод проверки ввода почтового ящика /// </summary> /// <param name="sender"></param> /// <param name="ex"></param> private void EmailTextbox_TextChanged(object sender, EventArgs ex) { UpperFirstSimbol(sender); try { _contact.Email = EmailTextbox.Text; EmailTextbox.BackColor = Color.White; errorProvider.SetError(EmailTextbox, String.Empty); _checkEmailResult = true; } catch (ArgumentNullException e) { errorProvider.SetError(EmailTextbox, e.Message); EmailTextbox.Focus(); EmailTextbox.BackColor = Color.LightSalmon; _checkEmailResult = false; } catch (ArgumentException e) { errorProvider.SetError(EmailTextbox, e.Message); EmailTextbox.Focus(); EmailTextbox.BackColor = Color.LightSalmon; _checkEmailResult = false; } }
private void SendEmail_Click(object sender, RoutedEventArgs e) { if (HostTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please fill in the hosting provider.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); HostTextbox.Focus(); } else if (EmailTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please enter your email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailTextbox.Focus(); } else if (EmailTextbox.Text.Contains("@") == false) { System.Windows.MessageBox.Show("Please enter a valid email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailTextbox.Focus(); } else if (PasswordBox.Password == string.Empty) { System.Windows.MessageBox.Show("Please fill in your password.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); PasswordBox.Focus(); } else if (EmailToTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please Enter the email address where you want to send the mail.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailToTextbox.Focus(); } else if (EmailTextbox.Text.Contains("@") == false) { System.Windows.MessageBox.Show("Please enter a valid email address.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); EmailToTextbox.Focus(); } else if (SubjectTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please fill in the subject of your email.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); SubjectTextbox.Focus(); } else if (MessageTextbox.Text == string.Empty) { System.Windows.MessageBox.Show("Please leave a message.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); MessageTextbox.Focus(); } else { SendEmail.IsEnabled = false; if (HostTextbox.Text.StartsWith("pop3")) { HostTextbox.Text = HostTextbox.Text.Replace("pop3", "smtp"); } else if (HostTextbox.Text.StartsWith("imap")) { HostTextbox.Text = HostTextbox.Text.Replace("imap", "smtp"); } else if (!(HostTextbox.Text.Contains("smtp."))) { HostTextbox.Text = "smtp." + HostTextbox.Text; } ErrorFormat = String.Empty; ErrorSmtp = String.Empty; Host = HostTextbox.Text; EmailFrom = EmailTextbox.Text; EmailTo = EmailToTextbox.Text; Password = PasswordBox.Password; Subject = SubjectTextbox.Text; Message = MessageTextbox.Text; AttachmentPath = AttachmentTextbox.Text; StatusTextBlock.Foreground = Brushes.Black; StatusTextBlock.Text = "Sending..."; BackgroundWorker.RunWorkerAsync(); } }
private bool Validar() { bool paso = true; MyerrorProvider.Clear(); if (string.IsNullOrWhiteSpace(MatriculaTextBox.Text)) { MyerrorProvider.SetError(MatriculaTextBox, "El campo Direccion no puede estar vacio"); MatriculaTextBox.Focus(); paso = false; } if (NombreTextbox.Text == string.Empty) { MyerrorProvider.SetError(NombreTextbox, "El campo Nombre no puede estar vacio"); NombreTextbox.Focus(); paso = false; } if (ApellidoTextbox.Text == string.Empty) { MyerrorProvider.SetError(ApellidoTextbox, "El campo Nombre no puede estar vacio"); ApellidoTextbox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(CedulaTextbox.Text.Replace("-", ""))) { MyerrorProvider.SetError(CedulaTextbox, "El campo Cedula no puede estar vacio"); CedulaTextbox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(TelefonoTextbox.Text.Replace("-", ""))) { MyerrorProvider.SetError(TelefonoTextbox, "El campo Telefono no puede estar vacio"); TelefonoTextbox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(CelularTextbox.Text.Replace("-", ""))) { MyerrorProvider.SetError(CelularTextbox, "El campo Celular no puede estar vacio"); CelularTextbox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(EmailTextbox.Text)) { MyerrorProvider.SetError(EmailTextbox, "El campo Email no puede estar vacio"); EmailTextbox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(FechaNacimientoDateTimePicker.Text)) { MyerrorProvider.SetError(FechaNacimientoDateTimePicker, "El campo Fecha de nacimiento no puede estar vacio"); FechaNacimientoDateTimePicker.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(SexoComboBox.Text)) { MyerrorProvider.SetError(SexoComboBox, "El campo Sexo no puede estar vacio"); SexoComboBox.Focus(); paso = false; } if (string.IsNullOrWhiteSpace(BalanceTextBox.Text)) { MyerrorProvider.SetError(BalanceTextBox, "El campo Balance no puede estar vacio"); BalanceTextBox.Focus(); paso = false; } return(paso); }