UpdateContact
The UpdateContact method saves any changes made on the Edit Contact Information GUI to the current contact instance — represented by curContact. The method is invoked when either the Update or Add buttons are clicked. The method does the following:
-
Assigns the values currently displayed by the GUI elements to the properties of curContact.
-
Invokes Save on curContact.
-
If the status information returned by Save indicates a problem, then UpdateContact displays a message.
-
If the status information returned by Save indicates success, then UpdateContact does the following:
-
Invokes RefreshContacts. This method updates the data displayed in the tree on the left hand side of the GUI.
-
Invokes DisplayContact passing it the object ID of the current contact.
-
Here is the method. Add the body of the method to the UpdateContact stub in PhoneFormObj.cs.
private void UpdateContact()
{
curContact.Name
= (txtConName.Text == "") ? null : txtConName.Text;
curContact.ContactType
= (comboBox1.SelectedItem == null) ?
null : comboBox1.SelectedItem.ToString();
status = curContact.Save();
if (!status.IsOK)
{
MessageBox.Show(status.Message);
}
else
{
RefreshContacts();
DisplayContact(curContact.Id());
}
}