Exemplo n.º 1
0
 private void dlgContact_ContactChanged(object sender, ContactChangedEventArgs e)
 {
     try
     {
         var dc = sender as WndContacts;
         if (dc != null)
         {
             dc.ContactChanged -= dlgContact_ContactChanged;
         }
         if (e.Mode == AddEditMode.Add)
         {
             if (_Contacts.Any(c => c.Name == e.Contact.Name))
             {
                 var message = PNLang.Instance.GetMessageText("contact_exists",
                     "Contact with this name already exists");
                 PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
                 e.Accepted = false;
                 return;
             }
             _Contacts.Add(e.Contact);
         }
         else
         {
             var c = _Contacts.FirstOrDefault(con => con.ID == e.Contact.ID);
             if (c == null) return;
             c.Name = e.Contact.Name;
             c.ComputerName = e.Contact.ComputerName;
             c.IpAddress = e.Contact.IpAddress;
             c.UseComputerName = e.Contact.UseComputerName;
             c.GroupID = e.Contact.GroupID;
         }
         fillContacts(false);
         fillGroups(false);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Exemplo n.º 2
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_Mode == AddEditMode.Add)
         {
             _Contact = new PNContact {
                 ID = _Id
             };
         }
         _Contact.Name = txtContactName.Text.Trim();
         if (optUseCompName.IsChecked != null)
         {
             _Contact.UseComputerName = optUseCompName.IsChecked.Value;
         }
         _Contact.ComputerName = txtCompName.Text.Trim();
         if (optUseAddress.IsChecked != null && optUseAddress.IsChecked.Value)
         {
             _Contact.IpAddress = ipaAddress.Text;
         }
         if (_Contact.UseComputerName && string.IsNullOrEmpty(_Contact.IpAddress))
         {
             try
             {
                 Mouse.OverrideCursor = Cursors.Wait;
                 if (!PNStatic.SetContactIpAddress(_Contact))
                 {
                     //var msg = PNLang.Instance.GetMessageText("host_unknown", "No such host is known");
                     //msg = msg.Replace(PNStrings.PLACEHOLDER1, txtCompName.Text.Trim());
                     //PNMessageBox.Show(msg, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
                     //return;
                 }
             }
             finally
             {
                 Mouse.OverrideCursor = null;
             }
         }
         if (cboGroups.SelectedIndex > 0)
         {
             var group = (string)cboGroups.SelectedItem;
             var g     = _Groups.FirstOrDefault(gr => gr.Name == group);
             if (g != null)
             {
                 _Contact.GroupID = g.ID;
             }
         }
         else
         {
             _Contact.GroupID = -1;
         }
         if (ContactChanged != null)
         {
             var ce = new ContactChangedEventArgs(_Contact, _Mode);
             ContactChanged(this, ce);
             if (!ce.Accepted)
             {
                 txtContactName.SelectAll();
                 txtContactName.Focus();
                 return;
             }
         }
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }