protected void Page_Load(object sender, EventArgs e) { chkEmail.Enabled = !String.IsNullOrEmpty(ContactHelper.GetEmailDomain(this.CurrentContact.ContactEmail)); chkAddress.Enabled = !String.IsNullOrEmpty(this.CurrentContact.ContactAddress1) || !String.IsNullOrEmpty(this.CurrentContact.ContactAddress2) || !String.IsNullOrEmpty(this.CurrentContact.ContactCity) || !String.IsNullOrEmpty(this.CurrentContact.ContactZIP); chkBirthDay.Enabled = (this.CurrentContact.ContactBirthday != DateTimeHelper.ZERO_TIME); chkPhone.Enabled = !String.IsNullOrEmpty(this.CurrentContact.ContactBusinessPhone) || !String.IsNullOrEmpty(this.CurrentContact.ContactHomePhone) || !String.IsNullOrEmpty(this.CurrentContact.ContactMobilePhone); chkMembership.Visible = chkIPaddress.Visible = ci.ContactSiteID != 0; // Current contact is global object if (ci.ContactSiteID == 0) { plcSite.Visible = true; // Display site selector in site manager if (ContactHelper.IsSiteManager) { siteOrGlobalSelector.Visible = false; } // Display 'site or global' selector in CMS desk for global objects else if (ContactHelper.AuthorizedReadContact(CMSContext.CurrentSiteID, false) && ContactHelper.AuthorizedModifyContact(CMSContext.CurrentSiteID, false)) { siteSelector.Visible = false; } else { plcSite.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { chkEmail.Enabled = !String.IsNullOrEmpty(ContactHelper.GetEmailDomain(CurrentContact.ContactEmail)); chkAddress.Enabled = !String.IsNullOrEmpty(CurrentContact.ContactAddress1) || !String.IsNullOrEmpty(CurrentContact.ContactAddress2) || !String.IsNullOrEmpty(CurrentContact.ContactCity) || !String.IsNullOrEmpty(CurrentContact.ContactZIP); chkBirthDay.Enabled = (CurrentContact.ContactBirthday != DateTimeHelper.ZERO_TIME); chkPhone.Enabled = !String.IsNullOrEmpty(CurrentContact.ContactBusinessPhone) || !String.IsNullOrEmpty(CurrentContact.ContactHomePhone) || !String.IsNullOrEmpty(CurrentContact.ContactMobilePhone); chkMembership.Visible = chkIPaddress.Visible = ci.ContactSiteID != 0; if (chkMembership.Visible) { var relationships = ContactMembershipInfoProvider.GetRelationships() .WhereEquals("ActiveContactID", CurrentContact.ContactID); chkMembership.Enabled = relationships.Any(); var ips = IPInfoProvider.GetIps() .WhereEquals("IPActiveContactID", CurrentContact.ContactID); chkIPaddress.Enabled = ips.Any(); } // Current contact is global object if (ci.ContactSiteID == 0) { plcSite.Visible = true; // Display site selector in site manager if (ContactHelper.IsSiteManager) { siteOrGlobalSelector.Visible = false; } // Display 'site or global' selector in CMS desk for global objects else if (ContactHelper.AuthorizedReadContact(SiteContext.CurrentSiteID, false) && ContactHelper.AuthorizedModifyContact(SiteContext.CurrentSiteID, false)) { siteSelector.Visible = false; } else { plcSite.Visible = false; } } }
/// <summary> /// Returns SQL WHERE condition depending on selected checkboxes. /// </summary> /// <returns>Returns SQL WHERE condition</returns> public string GetWhereCondition() { var where = new WhereCondition(); // Contacts checked if (chkContacts.Checked) { where.Where(GetContactWhereCondition()); } // Address checked if (chkAddress.Checked) { where.Where(GetAddressWhereCondition()); } // Email address checked if (chkEmail.Checked) { string domain = ContactHelper.GetEmailDomain(CurrentAccount.AccountEmail); if (!String.IsNullOrEmpty(domain)) { var emailWhere = new WhereCondition().WhereEndsWith("AccountEmail", "@" + domain); where.Where(emailWhere); } } // URL checked if (chkURL.Checked && !String.IsNullOrEmpty(CurrentAccount.AccountWebSite)) { var urlWhere = new WhereCondition().WhereContains("AccountWebSite", URLHelper.CorrectDomainName(CurrentAccount.AccountWebSite)); where.Where(urlWhere); } // Phone & fax checked if (chkPhone.Checked && (!String.IsNullOrEmpty(CurrentAccount.AccountPhone) || !String.IsNullOrEmpty(CurrentAccount.AccountFax))) { where.Where(GetPhoneWhereCondition()); } if ((!chkContacts.Checked && !chkAddress.Checked && !chkEmail.Checked && !chkURL.Checked && !chkPhone.Checked) || (String.IsNullOrEmpty(where.WhereCondition))) { return("(1 = 0)"); } // Filter out current account where.WhereNotEquals("AccountID", CurrentAccount.AccountID); // Filter out merged records where.Where(w => w.Where(x => x.WhereNull("AccountMergedWithAccountID") .WhereNull("AccountGlobalAccountID") .WhereGreaterThan("AccountSiteID", 0)) .Or(y => y.WhereNull("AccountGlobalAccountID") .WhereNull("AccountSiteID"))); // For global object use siteselector's value if (plcSite.Visible) { mSelectedSiteID = UniSelector.US_ALL_RECORDS; if (siteSelector.Visible) { mSelectedSiteID = siteSelector.SiteID; } else if (siteOrGlobalSelector.Visible) { mSelectedSiteID = siteOrGlobalSelector.SiteID; } // Only global objects if (mSelectedSiteID == UniSelector.US_GLOBAL_RECORD) { where.WhereNull("AccountSiteID"); } // Global and site objects else if (mSelectedSiteID == UniSelector.US_GLOBAL_AND_SITE_RECORD) { where.Where(w => w.WhereNull("AccountSiteID").Or().WhereEquals("AccountSiteID", SiteContext.CurrentSiteID)); } // Site objects else if (mSelectedSiteID != UniSelector.US_ALL_RECORDS) { where.WhereEquals("AccountSiteID", mSelectedSiteID); } } // Filter out accounts from different sites else { // Site accounts only if (CurrentAccount.AccountSiteID > 0) { where.WhereEquals("AccountSiteID", CurrentAccount.AccountSiteID); } // Global accounts only else { where.WhereNull("AccountSiteID"); } } return(where.ToString(expand: true)); }
/// <summary> /// Returns e-mail domain name. /// </summary> /// <param name="email">E-mail address</param> public static string GetEmailDomain(object email) { return(ContactHelper.GetEmailDomain(ValidationHelper.GetString(email, string.Empty))); }
/// <summary> /// Returns SQL WHERE condition depending on selected checkboxes. /// </summary> /// <returns>Returns SQL WHERE condition</returns> public string GetWhereCondition() { string where = null; // IP address checked if (chkIPaddress.Checked) { where = "ContactID IN (SELECT IP2.IPActiveContactID FROM OM_IP AS IP1 LEFT JOIN OM_IP AS IP2 ON IP1.IPAddress LIKE IP2.IPAddress WHERE IP1.IPID <> IP2.IPID AND IP1.IPActiveContactID = " + CurrentContact.ContactID + ")"; } // Email address checked if (chkEmail.Checked) { string domain = ContactHelper.GetEmailDomain(CurrentContact.ContactEmail); if (!String.IsNullOrEmpty(domain)) { string emailWhere = "ContactEmail LIKE N'%@" + SqlHelperClass.GetSafeQueryString(domain) + "'"; where = SqlHelperClass.AddWhereCondition(where, emailWhere); } } // Address checked if (chkAddress.Checked) { string addressWhere = null; if (!String.IsNullOrEmpty(CurrentContact.ContactAddress1)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "ContactAddress1 LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactAddress1, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(CurrentContact.ContactAddress2)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "ContactAddress2 LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactAddress2, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(CurrentContact.ContactCity)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "ContactCity LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactCity, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(CurrentContact.ContactZIP)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "ContactZIP LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactZIP, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(addressWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + addressWhere + ")"); } } // Birthday checked if (chkBirthDay.Checked && (CurrentContact.ContactBirthday != DateTimeHelper.ZERO_TIME)) { where = SqlHelperClass.AddWhereCondition(where, "ContactBirthDay = '" + FormHelper.GetDateTimeValueInDBCulture(CurrentContact.ContactBirthday.ToString()) + "'"); } // Phone checked if (chkPhone.Checked) { string phoneWhere = null; if (!String.IsNullOrEmpty(CurrentContact.ContactBusinessPhone)) { phoneWhere = SqlHelperClass.AddWhereCondition(phoneWhere, "ContactBusinessPhone LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactBusinessPhone, false) + "%'"); } if (!String.IsNullOrEmpty(CurrentContact.ContactHomePhone)) { phoneWhere = SqlHelperClass.AddWhereCondition(phoneWhere, "ContactHomePhone LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactHomePhone, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(CurrentContact.ContactMobilePhone)) { phoneWhere = SqlHelperClass.AddWhereCondition(phoneWhere, "ContactMobilePhone LIKE N'%" + SqlHelperClass.GetSafeQueryString(CurrentContact.ContactMobilePhone, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(phoneWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + phoneWhere + ")"); } } // Membership checked if (chkMembership.Checked) { where = SqlHelperClass.AddWhereCondition(where, "ContactID IN (SELECT Member2.ActiveContactID FROM OM_Membership AS Member1 LEFT JOIN OM_Membership AS Member2 ON Member1.RelatedID = Member2.RelatedID AND Member1.MemberType LIKE Member2.MemberType WHERE Member1.MembershipID <> Member2.MembershipID AND Member1.ActiveContactID = " + CurrentContact.ContactID + ")"); } if ((!chkAddress.Checked && !chkBirthDay.Checked && !chkEmail.Checked && !chkIPaddress.Checked && !chkPhone.Checked && !chkMembership.Checked) || (String.IsNullOrEmpty(where))) { return("(1 = 0)"); } // Filter out records related to current contact where = SqlHelperClass.AddWhereCondition(where, "ContactID <> " + CurrentContact.ContactID); // Filter out merged records - merging into global contact if (CurrentContact.ContactSiteID == 0) { where = SqlHelperClass.AddWhereCondition(where, "(ContactMergedWithContactID IS NULL AND ContactGlobalContactID IS NULL AND ContactSiteID > 0) OR (ContactGlobalContactID IS NULL AND ContactSiteID IS NULL)"); } // Merging into site contact else { where = SqlHelperClass.AddWhereCondition(where, "(ContactMergedWithContactID IS NULL AND ContactSiteID > 0)"); } // For global object use siteselector's value if (plcSite.Visible) { mSelectedSiteID = UniSelector.US_ALL_RECORDS; if (siteSelector.Visible) { mSelectedSiteID = siteSelector.SiteID; } else if (siteOrGlobalSelector.Visible) { mSelectedSiteID = siteOrGlobalSelector.SiteID; } // Only global objects if (mSelectedSiteID == UniSelector.US_GLOBAL_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID IS NULL"); } // Global and site objects else if (mSelectedSiteID == UniSelector.US_GLOBAL_OR_SITE_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID IS NULL OR ContactSiteID = " + CMSContext.CurrentSiteID); } // Site objects else if (mSelectedSiteID != UniSelector.US_ALL_RECORDS) { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID = " + mSelectedSiteID); } } // Filter out contacts from different sites else { // Site contacts only if (CurrentContact.ContactSiteID > 0) { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID = " + CurrentContact.ContactSiteID); } // Global contacts only else { where = SqlHelperClass.AddWhereCondition(where, "ContactSiteID IS NULL"); } } return(where); }
/// <summary> /// Returns SQL WHERE condition depending on selected checkboxes. /// </summary> /// <returns>Returns SQL WHERE condition</returns> public string GetWhereCondition() { string where = null; // Contacts checked if (chkContacts.Checked) { string contactWhere = null; ContactInfo contact; // Get primary contact WHERE condition if (this.CurrentAccount.AccountPrimaryContactID != 0) { contact = ContactInfoProvider.GetContactInfo(this.CurrentAccount.AccountPrimaryContactID); if (contact != null) { if (!String.IsNullOrEmpty(contact.ContactFirstName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactFirstName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactFirstName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactMiddleName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactMiddleName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactMiddleName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactLastName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "PrimaryContactLastName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactLastName, false) + "%'", "OR"); } } } // Get secondary contact WHERE condition if (this.CurrentAccount.AccountSecondaryContactID != 0) { contact = ContactInfoProvider.GetContactInfo(this.CurrentAccount.AccountSecondaryContactID); if (contact != null) { if (!String.IsNullOrEmpty(contact.ContactFirstName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactFirstName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactFirstName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactMiddleName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactMiddleName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactMiddleName, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(contact.ContactLastName)) { contactWhere = SqlHelperClass.AddWhereCondition(contactWhere, "SecondaryContactLastName LIKE '%" + SqlHelperClass.GetSafeQueryString(contact.ContactLastName, false) + "%'", "OR"); } } } if (!String.IsNullOrEmpty(contactWhere)) { where = SqlHelperClass.AddWhereCondition(where, contactWhere); } } // Address checked if (chkAddress.Checked) { string addressWhere = null; if (!String.IsNullOrEmpty(this.CurrentAccount.AccountAddress1)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountAddress1 LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountAddress1, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountAddress2)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountAddress2 LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountAddress2, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountCity)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountCity LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountCity, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountZIP)) { addressWhere = SqlHelperClass.AddWhereCondition(addressWhere, "AccountZIP LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountZIP, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(addressWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + addressWhere + ")"); } } // Email address checked if (chkEmail.Checked && !String.IsNullOrEmpty(ContactHelper.GetEmailDomain(this.CurrentAccount.AccountEmail))) { string emailWhere = "(AccountEmail LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountEmail, false) + "%' OR AccountEmail LIKE '%" + SqlHelperClass.GetSafeQueryString(ContactHelper.GetEmailDomain(this.CurrentAccount.AccountEmail)) + "%')"; where = SqlHelperClass.AddWhereCondition(where, emailWhere); } // URL checked if (chkURL.Checked && !String.IsNullOrEmpty(this.CurrentAccount.AccountWebSite)) { string urlWhere = "(AccountWebSite LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountWebSite, false) + "%' OR AccountWebSite LIKE '%" + SqlHelperClass.GetSafeQueryString(URLHelper.CorrectDomainName(this.CurrentAccount.AccountWebSite)) + "%')"; where = SqlHelperClass.AddWhereCondition(where, urlWhere); } // Phone & fax checked if (chkPhone.Checked && (!String.IsNullOrEmpty(this.CurrentAccount.AccountPhone) || !String.IsNullOrEmpty(this.CurrentAccount.AccountFax))) { string phoneWhere = null; if (!String.IsNullOrEmpty(this.CurrentAccount.AccountPhone)) { phoneWhere = "AccountPhone LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountPhone, false) + "%'"; } if (!String.IsNullOrEmpty(this.CurrentAccount.AccountFax)) { phoneWhere = SqlHelperClass.AddWhereCondition(phoneWhere, "AccountFax LIKE '%" + SqlHelperClass.GetSafeQueryString(this.CurrentAccount.AccountFax, false) + "%'", "OR"); } if (!String.IsNullOrEmpty(phoneWhere)) { where = SqlHelperClass.AddWhereCondition(where, "(" + phoneWhere + ")"); } } if ((!chkContacts.Checked && !chkAddress.Checked && !chkEmail.Checked && !chkURL.Checked && !chkPhone.Checked) || (String.IsNullOrEmpty(where))) { return("(1 = 0)"); } // Filter out current account where = SqlHelperClass.AddWhereCondition(where, "AccountID <> " + this.CurrentAccount.AccountID); // Filter out merged records where = SqlHelperClass.AddWhereCondition(where, "(AccountMergedWithAccountID IS NULL AND AccountGlobalAccountID IS NULL AND AccountSiteID > 0) OR (AccountGlobalAccountID IS NULL AND AccountSiteID IS NULL)"); // For global object use siteselector's value if (plcSite.Visible) { mSelectedSiteID = UniSelector.US_ALL_RECORDS; if (siteSelector.Visible) { mSelectedSiteID = siteSelector.SiteID; } else if (siteOrGlobalSelector.Visible) { mSelectedSiteID = siteOrGlobalSelector.SiteID; } // Only global objects if (mSelectedSiteID == UniSelector.US_GLOBAL_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL"); } // Global and site objects else if (mSelectedSiteID == UniSelector.US_GLOBAL_OR_SITE_RECORD) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL OR AccountSiteID = " + CMSContext.CurrentSiteID); } // Site objects else if (mSelectedSiteID != UniSelector.US_ALL_RECORDS) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID = " + mSelectedSiteID); } } // Filter out accounts from different sites else { // Site accounts only if (this.CurrentAccount.AccountSiteID > 0) { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID = " + this.CurrentAccount.AccountSiteID); } // Global accounts only else { where = SqlHelperClass.AddWhereCondition(where, "AccountSiteID IS NULL"); } } return(where); }