Synchronizing with Windows Mobile Contacts

Windows Mobile Contacts is a pretty useful tool provided with Windows Mobile that allows you to store a list of all your contacts. These contacts can also be readily synced with Microsoft Outlook (via ActiveSync) on the desktop to provide you with an always updated list of contacts.

If your users use the sales force application to create a lead, opportunity, or customer, why should it be any different? These are also your contacts and should, therefore, make their way into the Windows Mobile Contacts area. Using the OutlookSession class in the Microsoft.WindowsMobile.PocketOutlook namespace, you can access all the Contacts stored on your mobile device.

Let's see how we can write the following function code to sync the latest information in the sales force application to the Windows Mobile Contacts area:

using Microsoft.WindowsMobile.PocketOutlook;
public void SyncToWindowsMobileContacts(string
mobilePhoneNumber, string firstName, string lastName,
string address, string emailAddress)
{
OutlookSession _outlookapp = new OutlookSession();
PropertyDescriptor _contact;
int _contactIndex;
Contact _contactItem;

You can search through your Windows Mobile Contacts using the Find() function as follows. This function is flexible enough to allow you to search by any property in the PocketOutlook.Contact class.

_contact = TypeDescriptor.GetProperties(typeof(Contact))
["MobileTelephoneNumber"];
_contactIndex = _outlookapp.Contacts.Items.Find(_contact,
mobilePhoneNumber);

If a result returned from the search is -1, this means that a contact matching the mobile phone number passed in cannot be found, you should proceed to create the contact in this case. If the result was a value other than -1, you can retrieve the contact and update its details with the latest data from the sales force application.

if (_contactIndex == - 1)
{
_contactItem = new Contact();
_contactItem.FirstName = firstName;
_contactItem.LastName = lastName;
_contactItem.MobileTelephoneNumber = mobilePhoneNumber;
_contactItem.AccountName = firstName + " " + lastName +
"@CRMLive";
_contactItem.Email1Address = emailAddress;
_outlookapp.Contacts.Items.Add(_contactItem);
}
else
{
_contactItem =
_outlookapp.Contacts.Items[_contactIndex];
_contactItem.FirstName = firstName;
_contactItem.LastName = lastName;
_contactItem.Update();
}
}

Now that you have created this function, a suitable place to call it is when the user clicks on the Save button of the AccountViewer form. This is because you need to update the Windows Mobile Contacts area with the latest first name and last name of the lead account. Let's take a look at the btnSave_Click() function in the AccountViewer form. The changes in this function are highlighted as follows:

private void btnSave_Click(System.Object sender,
System.EventArgs e)
{
AccountBindingSource.EndEdit();
if (Account.Validate == false)
{
Interaction.MsgBox(Account.GetValidationResult(),
MsgBoxStyle.Exclamation, "Save error");
}
else
{
Telephony _telephony = new Telephony();
_telephony.SyncToWindowsMobileContacts
(txtMobPhone.Text, txtFirstName.Text,
txtLastName.Text, txtStreet.Text, txtEmail.Text);
this.DialogResult = Windows.Forms.DialogResult.OK;
this.Close();
}
}

You can test this functionality by running the application and subsequently creating or updating an existing lead, opportunity, or customer. You will notice that the account's information is automatically propagated to the Windows Mobile Contacts area (as shown in the next screenshot).

Synchronizing with Windows Mobile Contacts
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.222.12