private void cmdOK_Click(object sender, RoutedEventArgs e) { try { ContactGroupChangedEventArgs ce; if (m_Mode == AddEditMode.Add) { var cg = new PNContactGroup { Name = txtGroupName.Text.Trim(), ID = m_NewId }; ce = new ContactGroupChangedEventArgs(cg, m_Mode); } else { m_Group.Name = txtGroupName.Text.Trim(); ce = new ContactGroupChangedEventArgs(m_Group, m_Mode); } if (ContactGroupChanged != null) { ContactGroupChanged(this, ce); } if (!ce.Accepted) { txtGroupName.SelectAll(); txtGroupName.Focus(); return; } DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void dlgContactGroup_ContactGroupChanged(object sender, ContactGroupChangedEventArgs e) { try { var dg = sender as WndGroups; if (dg != null) { dg.ContactGroupChanged -= dlgContactGroup_ContactGroupChanged; } if (e.Mode == AddEditMode.Add) { if (_Groups.Any(g => g.Name == e.Group.Name)) { var message = PNLang.Instance.GetMessageText("group_exists", "Contacts group with this name already exists"); PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Information); e.Accepted = false; return; } _Groups.Add(e.Group); } else { var g = _Groups.FirstOrDefault(gr => gr.ID == e.Group.ID); if (g != null) { g.Name = e.Group.Name; } } fillGroups(false); } catch (Exception ex) { PNStatic.LogException(ex); } }