Esempio n. 1
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var rg    = new Regex(PNStrings.MAIL_PATTERN, RegexOptions.IgnoreCase);
         var match = rg.Match(txtMailAddress.Text.Trim());
         if (!match.Success)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_email", "Invalid e-mail address"),
                               PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtMailAddress.SelectAll();
             txtMailAddress.Focus();
             return;
         }
         _Contact.DisplayName = txtMailDisplayName.Text.Trim();
         _Contact.Address     = txtMailAddress.Text.Trim();
         if (MailContactChanged != null)
         {
             var en = new MailContactChangedEventArgs(_Contact, _Mode);
             MailContactChanged(this, en);
             if (!en.Accepted)
             {
                 return;
             }
         }
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Esempio n. 2
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var rg = new Regex(PNStrings.MAIL_PATTERN, RegexOptions.IgnoreCase);
         var match = rg.Match(txtMailAddress.Text.Trim());
         if (!match.Success)
         {
             PNMessageBox.Show(PNLang.Instance.GetMessageText("invalid_email", "Invalid e-mail address"),
                PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             txtMailAddress.SelectAll();
             txtMailAddress.Focus();
             return;
         }
         _Contact.DisplayName = txtMailDisplayName.Text.Trim();
         _Contact.Address = txtMailAddress.Text.Trim();
         if (MailContactChanged != null)
         {
             var en = new MailContactChangedEventArgs(_Contact, _Mode);
             MailContactChanged(this, en);
             if (!en.Accepted)
                 return;
         }
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Esempio n. 3
0
 private void dlgMailContact_MailContactChanged(object sender, MailContactChangedEventArgs e)
 {
     try
     {
         switch (e.Mode)
         {
             case AddEditMode.Add:
                 if (
                     _MailContacts.Any(
                         mc => mc.DisplayName == e.Contact.DisplayName && mc.Address == e.Contact.Address))
                 {
                     PNMessageBox.Show(
                     PNLang.Instance.GetMessageText("mail_contact_same_address",
                         "There is already mail contact with the same name and address"), PNStrings.PROG_NAME,
                     MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     e.Accepted = false;
                     return;
                 }
                 e.Contact.Id = _MailContacts.Any() ? _MailContacts.Max(mc => mc.Id) + 1 : 0;
                 _MailContacts.Add(e.Contact);
                 fillMailContacts(false);
                 break;
             case AddEditMode.Edit:
                 if (
                     _MailContacts.Any(
                         mc =>
                             mc.DisplayName == e.Contact.DisplayName && mc.Address == e.Contact.Address &&
                             mc.Id != e.Contact.Id))
                 {
                     PNMessageBox.Show(
                         PNLang.Instance.GetMessageText("mail_contact_same_address",
                             "There is already mail contact with the same name and address"), PNStrings.PROG_NAME,
                         MessageBoxButton.OK, MessageBoxImage.Exclamation);
                     e.Accepted = false;
                     return;
                 }
                 var contact = _MailContacts.FirstOrDefault(mc => mc.Id == e.Contact.Id);
                 if (contact == null) break;
                 contact.DisplayName = e.Contact.DisplayName;
                 contact.Address = e.Contact.Address;
                 fillMailContacts(false);
                 break;
         }
         var d = sender as WndMailContact;
         if (d == null) return;
         d.MailContactChanged -= dlgMailContact_MailContactChanged;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }