Esempio n. 1
0
    public static string GetEmailsCommaSepByEntityID(int entityID, bool forBilling, bool forNonBilling)
    {
        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            Contact[] contacts = ContactDB.GetByEntityIDs(-1, new int[] { entityID }, 27, -1);
            if (contacts == null || contacts.Length == 0)
            {
                return(null);
            }

            ArrayList emails = new ArrayList();
            foreach (Contact c in contacts)
            {
                if (((forBilling && c.IsBilling) || (forNonBilling && c.IsNonBilling)) && c.AddrLine1.Trim().Length > 0 && Utilities.IsValidEmailAddress(c.AddrLine1.Trim()))
                {
                    emails.Add(c.AddrLine1.Trim());
                }
            }

            if (emails.Count > 0)
            {
                return(string.Join(",", ((string[])emails.ToArray(typeof(string)))));
            }
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            ContactAus[] contacts = ContactAusDB.GetByEntityIDs(-1, new int[] { entityID }, 27, -1);
            if (contacts == null || contacts.Length == 0)
            {
                return(null);
            }

            ArrayList emails = new ArrayList();
            foreach (ContactAus c in contacts)
            {
                if (((forBilling && c.IsBilling) || (forNonBilling && c.IsNonBilling)) && c.AddrLine1.Trim().Length > 0 && Utilities.IsValidEmailAddress(c.AddrLine1.Trim()))
                {
                    emails.Add(c.AddrLine1.Trim());
                }
            }

            if (emails.Count > 0)
            {
                return(string.Join(",", ((string[])emails.ToArray(typeof(string)))));
            }
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }

        return(null);
    }
    public static Hashtable GetBullk(string contact_type_group_ids, string contact_type_ids, int[] entity_ids, int site_id)
    {
        if (entity_ids.Length == 0)
        {
            return(new Hashtable());
        }


        // remove duplicates
        ArrayList uniqueIDs = new ArrayList();

        for (int i = 0; i < entity_ids.Length; i++)
        {
            if (!uniqueIDs.Contains(entity_ids[i]))
            {
                uniqueIDs.Add(entity_ids[i]);
            }
        }
        entity_ids = (int[])uniqueIDs.ToArray(typeof(int));


        Hashtable phoneNumbers = new Hashtable();

        if (Utilities.GetAddressType().ToString() == "Contact")
        {
            Contact[] phoneNbrs = ContactDB.GetByEntityIDs(contact_type_group_ids, entity_ids, contact_type_ids, site_id);
            for (int i = 0; i < phoneNbrs.Length; i++)
            {
                if (phoneNumbers[phoneNbrs[i].EntityID] == null)
                {
                    phoneNumbers[phoneNbrs[i].EntityID] = new ArrayList();
                }
                ((ArrayList)phoneNumbers[phoneNbrs[i].EntityID]).Add(phoneNbrs[i]);
            }
        }
        else if (Utilities.GetAddressType().ToString() == "ContactAus")
        {
            ContactAus[] phoneNbrs = ContactAusDB.GetByEntityIDs(contact_type_group_ids, entity_ids, contact_type_ids, site_id);
            for (int i = 0; i < phoneNbrs.Length; i++)
            {
                if (phoneNumbers[phoneNbrs[i].EntityID] == null)
                {
                    phoneNumbers[phoneNbrs[i].EntityID] = new ArrayList();
                }
                ((ArrayList)phoneNumbers[phoneNbrs[i].EntityID]).Add(phoneNbrs[i]);
            }
        }
        else
        {
            throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
        }


        // convert arraylists to arrays (and sort if necessary)
        ArrayList keys = new ArrayList();

        foreach (DictionaryEntry de in phoneNumbers)
        {
            keys.Add(de.Key);
        }
        foreach (int key in keys)
        {
            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                phoneNumbers[key] = (Contact[])((ArrayList)phoneNumbers[key]).ToArray(typeof(Contact));
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                phoneNumbers[key] = (ContactAus[])((ArrayList)phoneNumbers[key]).ToArray(typeof(ContactAus));
            }
        }


        return(phoneNumbers);
    }