Beispiel #1
0
        private static void ExportData()
        {
            // Get a list of the values from the items to export.
            List <object[]> exportItems = new List <object[]>();

            foreach (Outlook.ContactItem item in Globals.ThisAddIn.OpportunitiesFolder.Items)
            {
                // Ignore items that are not Sales Opportunity contact items.
                if (item.MessageClass != Constants.MessageClassOpportunities)
                {
                    continue;
                }

                // Get values for specified properties from the item's PropertyAccessor.
                object[] values = item.PropertyAccessor.GetProperties(ContactItemHelper.PropertyReferences);

                try
                {
                    // Convert the encounter date value from a UTC time to a local time.
                    values[5] = item.PropertyAccessor.UTCToLocalTime((DateTime)values[5]);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Unable to convert encounter date from UTC to local time for contact {0}: {1}",
                                    item.FullName, ex.Message);
                }

                // Add the values to the list of contact item data.
                exportItems.Add(values);
            }

            // Export the items to a data file.
            ContactItemHelper.ExportData(dataExportFile, exportItems);
        }
        /// <summary>Gets contact information imported from a file.</summary>
        /// <param name="importDataFileName">The complete file path for the file
        /// from which to load the data.</param>
        /// <returns>A list of ContactItemHelper objects generated from the file data.
        /// </returns>
        public static List <ContactItemHelper> LoadDataFromFile(string importDataFileName)
        {
            List <ContactItemHelper> items = new List <ContactItemHelper>();

            string[]      lines    = File.ReadAllLines(importDataFileName);
            List <string> headings = getFields(lines[0]);

            for (int i = 1; i < lines.Length; i++)
            {
                string line = (lines[i] ?? string.Empty).Trim();
                if (line.Length == 0)
                {
                    continue;
                }

                List <string>     fields      = getFields(line);
                ContactItemHelper contactData = new ContactItemHelper(
                    getField(Constants.lastNameDisplayName, fields, headings),
                    getField(Constants.firstNameDisplayName, fields, headings),
                    getField(Constants.companyNameDisplayName, fields, headings),
                    getField(Constants.primaryEmailDisplayName, fields, headings),
                    getField(Constants.customerIDDisplayName, fields, headings),
                    getField(Constants.encounterDateDisplayName, fields, headings),
                    getField(Constants.purchaseEstimateDisplayName, fields, headings),
                    getField(Constants.salesRepDisplayName, fields, headings),
                    getField(Constants.salesValueDisplayName, fields, headings),
                    getField(Constants.tradeShowDisplayName, fields, headings));

                items.Add(contactData);
            }
            return(items);
        }
Beispiel #3
0
        private static void ImportData()
        {
            List <ContactItemHelper> itemData = ContactItemHelper.LoadDataFromFile(dataImportFile);

            foreach (ContactItemHelper contactData in itemData)
            {
                // Create a new sales opportunity contact.
                Outlook.ContactItem newContact =
                    Globals.ThisAddIn.OpportunitiesFolder.Items.Add(
                        Constants.MessageClassOpportunities) as Outlook.ContactItem;

                // Set properties for the contact item.
                object[] errors = newContact.PropertyAccessor.SetProperties(
                    ContactItemHelper.PropertyReferences, contactData.PropertyValues);

                // Check any errors returned by the SetProperties method.
                DumpErrorsFromSetProperties(contactData, errors);

                newContact.Save();
            }
        }
Beispiel #4
0
        private static void DumpErrorsFromSetProperties(
            ContactItemHelper contactData, object[] errors)
        {
            if (errors == null || errors.Length > 0)
            {
                Debug.WriteLine("Set data on {0} without any errors encountered.",
                                contactData);
                return;
            }

            for (int i = 0; i < errors.Length; i++)
            {
                if (errors[i] == null)
                {
                    continue;
                }

                Debug.WriteLine("Error setting data on {0}, field {1}: {2}",
                                contactData, ContactItemHelper.FieldHeadings[i],
                                new COMException("", (int)errors[i]));
            }
        }