private void PrintTotalLeadsInMarketingCampaign()
{
Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
Outlook.Application olApp = (Outlook.Application)_app;
Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
Outlook.Folders folders = olNameSpace.Session.Folders;
Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"];
Outlook.Folder contacts = (Outlook.Folder)bcmRootFolder.Folders["Business Contacts"];
Outlook.Folder mktgCampFolder = (Outlook.Folder)bcmRootFolder.Folders["Marketing Campaigns"];
Outlook.UserProperty userProp;
Outlook.TaskItem taskItem = (Outlook.TaskItem)mktgCampFolder.Items.Add("IPM.Task.BCM.Campaign");
taskItem.Subject = "New Marketing Campaign";
if (taskItem.UserProperties["Campaign Code"] == null)
{
userProp = taskItem.UserProperties.Add("Campaign Code", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = "SP2";
}
if (taskItem.UserProperties["Campaign Type"] == null)
{
userProp = taskItem.UserProperties.Add("Campaign Type", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = "Direct Mail Print";
}
if (taskItem.UserProperties["Budgeted Cost"] == null)
{
userProp = taskItem.UserProperties.Add("Budgeted Cost", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olCurrency, false, false);
userProp.Value = 243456;
}
if (taskItem.UserProperties["Delivery Method"] == null)
{
userProp = taskItem.UserProperties.Add("Delivery Method", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = "Word Mail Merge";
}
taskItem.StartDate = System.DateTime.Parse("4/20/2006");
taskItem.DueDate = System.DateTime.Parse("5/20/2006");
taskItem.Save();
Outlook.ContactItem newContact1 = (Outlook.ContactItem)contacts.Items.Add("IPM.Contact.BCM.Contact");
newContact1.FullName = "John Smith";
newContact1.FileAs = "John Smith";
if (newContact1.UserProperties["Lead"] == null)
{
userProp = newContact1.UserProperties.Add("Lead", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olYesNo, false, false);
userProp.Value = true;
}
if (newContact1.UserProperties["Referred Entry Id"] == null)
{
userProp = newContact1.UserProperties.Add("Referred Entry Id", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = taskItem.EntryID;
}
newContact1.Save();
Outlook.ContactItem newContact2 = (Outlook.ContactItem)contacts.Items.Add("IPM.Contact.BCM.Contact");
newContact2.FullName = "Liz Keyser";
newContact2.FileAs = "Liz Keyser";
if (newContact2.UserProperties["Lead"] == null)
{
userProp = newContact2.UserProperties.Add("Lead", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olYesNo, false, false);
userProp.Value = true;
}
if (newContact2.UserProperties["Referred Entry Id"] == null)
{
userProp = newContact2.UserProperties.Add("Referred Entry Id", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = taskItem.EntryID;
}
newContact2.Save();
Outlook.ContactItem newContact3 = (Outlook.ContactItem)contacts.Items.Add("IPM.Contact.BCM.Contact");
newContact3.FullName = "Simon Pearson";
newContact3.FileAs = "Simon Pearson";
if (newContact3.UserProperties["Referred Entry Id"] == null)
{
userProp = newContact2.UserProperties.Add("Referred Entry Id", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = taskItem.EntryID;
}
newContact3.Save();
int totalLeads = 0;
Outlook.ContactItem existContact;
bool leadValue;
IEnumerator en = contacts.Items.GetEnumerator();
en.MoveNext();
for (int index = 0; index < contacts.Items.Count; index++)
{
if (index > 0)
{
en.MoveNext();
}
existContact = (Outlook.ContactItem)en.Current;
if (existContact.UserProperties["Lead"] == null)
{
existContact.UserProperties.Add("Lead", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olYesNo, false, false);
leadValue = (bool)existContact.UserProperties["Lead"].Value;
}
else
{
leadValue = (bool)existContact.UserProperties["Lead"].Value;
}
if (leadValue == true && existContact.ItemProperties["Referred Entry Id"].Value.Equals(taskItem.EntryID))
{
totalLeads++;
}
}
Console.WriteLine("TotalLeads is: {0}", totalLeads);
Console.ReadLine();
}
|