private void PrintTotalOpportunitiesInMarketingCampaign()
{
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 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.Folder accounts = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];
Outlook.ContactItem newAccount = (Outlook.ContactItem)accounts.Items.Add("IPM.Contact.BCM.Account");
newAccount.FullName = "Wide World Importers";
newAccount.FileAs = "WWImporters";
newAccount.Save();
string accountEntryID = newAccount.EntryID;
Outlook.Folder opportunities = (Outlook.Folder)bcmRootFolder.Folders["Opportunities"];
Outlook.TaskItem newOpportunity1 = (Outlook.TaskItem)opportunities.Items.Add("IPM.Task.BCM.Opportunity");
newOpportunity1.Subject = "Sales Opp with Wide World Importers";
if (newOpportunity1.UserProperties["Parent Entity EntryID"] == null)
{
userProp = newOpportunity1.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = accountEntryID;
}
if (newOpportunity1.UserProperties["Referred Entry Id"] == null)
{
userProp = newOpportunity1.UserProperties.Add("Referred Entry Id", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = taskItem.EntryID;
}
newOpportunity1.Save();
Outlook.TaskItem newOpportunity2 = (Outlook.TaskItem)opportunities.Items.Add("IPM.Task.BCM.Opportunity");
newOpportunity2.Subject = "New Sales Opportunity with Sara";
if (newOpportunity2.UserProperties["Parent Entity EntryID"] == null)
{
userProp = newOpportunity2.UserProperties.Add("Parent Entity EntryID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = accountEntryID;
}
if (newOpportunity2.UserProperties["Referred Entry Id"] == null)
{
userProp = newOpportunity2.UserProperties.Add("Referred Entry Id", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, false, false);
userProp.Value = taskItem.EntryID;
}
newOpportunity2.Save();
int totalOpportunities = 0;
Outlook.TaskItem existOpportunity;
IEnumerator en = opportunities.Items.GetEnumerator();
en.MoveNext();
for (int index = 0; index < opportunities.Items.Count; index++)
{
if (index > 0)
{
en.MoveNext();
}
existOpportunity = (Outlook.TaskItem)en.Current;
if (existOpportunity.ItemProperties["Referred Entry Id"].Value.Equals(taskItem.EntryID))
{
totalOpportunities++;
}
}
Console.WriteLine("TotalOpportunities is: {0}", totalOpportunities);
Console.ReadLine();
}
|