/// <summary>
    /// Creates default where condition for product documents listing.
    /// </summary>
    private WhereCondition GetDocumentWhereCondition()
    {
        var where = new WhereCondition().WhereNotNull("NodeSKUID");
        if (ShowSections)
        {
            where.Or().WhereIn("NodeClassID", new IDQuery <DataClassInfo>("ClassID").WhereTrue("ClassIsProductSection"));
        }

        // Prepare site condition
        var siteWhere = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);

        if (AllowGlobalObjects)
        {
            siteWhere.Or().WhereNull("SKUSiteID");
        }
        else if (ShowSections)
        {
            siteWhere.Or().Where(w => w.WhereNull("SKUSiteID").And().WhereNull("SKUID"));
        }

        // Combine where conditions
        where.Where(siteWhere);
        if (docList.Node != null)
        {
            string path = docList.Node.NodeAliasPath ?? "";

            where.WhereStartsWith("NodeAliasPath", path);
        }

        return(where);
    }
    /// <summary>
    /// Initializes the selector.
    /// </summary>
    public void InitSelector()
    {
        uniSelector.IsLiveSite = IsLiveSite;

        // Set resource prefix if specified
        if (ResourcePrefix != null)
        {
            uniSelector.ResourcePrefix = ResourcePrefix;
        }

        // Initialize selector for on-line marketing
        if (ValidationHelper.GetString(GetValue("mode"), "").ToLowerCSafe() == "onlinemarketing")
        {
            UniSelector.SelectionMode    = SelectionModeEnum.MultipleButton;
            UniSelector.OnItemsSelected += UniSelector_OnItemsSelected;
            UniSelector.ReturnColumnName = "CustomerID";
            IsLiveSite = false;
            SiteID     = ValidationHelper.GetInteger(GetValue("SiteID"), 0);
            UniSelector.ResourcePrefix = "om.customerselector";
        }

        var where = new WhereCondition();
        // Add registered customers
        if (DisplayRegisteredCustomers)
        {
            where.WhereIn("CustomerUserID", new IDQuery <UserSiteInfo>("UserID").WhereEquals("SiteID", SiteID));
        }

        // Add anonymous customers
        if (DisplayAnonymousCustomers)
        {
            where.Or().Where(w => w.WhereEquals("CustomerSiteID", SiteID).And().WhereNull("CustomerUserID"));
        }

        where = new WhereCondition(where);

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("CustomerEnabled");
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems))
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if (CustomerID > 0)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
示例#3
0
    /// <summary>
    /// Creates level where condition.
    /// </summary>
    /// <param name="showAllLevels">Indicates if pages from all levels should be retrieved</param>
    /// <param name="orderBy">Current order by</param>
    private WhereCondition GetLevelWhereCondition(bool showAllLevels, ref string orderBy)
    {
        var levelCondition = new WhereCondition();

        if (showAllLevels)
        {
            string path = aliasPath ?? string.Empty;
            levelCondition.WhereStartsWith("NodeAliasPath", path.TrimEnd('/') + "/")
            .WhereGreaterThan("NodeLevel", 0);
        }
        else
        {
            levelCondition.WhereEquals("NodeParentID", Node.NodeID)
            .WhereEquals("NodeLevel", Node.NodeLevel + 1);

            // Extend the where condition to include the root document
            if (RequiresDialog && (Node != null) && (Node.NodeParentID == 0))
            {
                levelCondition.Or().WhereNull("NodeParentID");

                orderBy = String.Join(",", "NodeParentID ASC", orderBy);
            }
        }

        if (ClassID > 0)
        {
            levelCondition.WhereEquals("NodeClassID", ClassID);
        }

        return(levelCondition);
    }
示例#4
0
    /// <summary>
    /// Creates default where condition for product documents listing.
    /// </summary>
    private WhereCondition GetDocumentWhereCondition()
    {
        var where = new WhereCondition().WhereNotNull("NodeSKUID");
        if (ShowSections)
        {
            where.Or().WhereIn("NodeClassID", new IDQuery <DataClassInfo>("ClassID").WhereTrue("ClassIsProductSection"));
        }

        // Prepare site condition
        var siteWhere = InitSiteWhereCondition("SKUSiteID");

        if (ShowSections)
        {
            siteWhere.Or().Where(w => w.WhereNull("SKUSiteID").And().WhereNull("SKUID"));
        }

        // Combine where conditions
        where.Where(siteWhere);
        if (docList.Node != null)
        {
            where.WhereStartsWith("NodeAliasPath", docList.Node.NodeAliasPath.TrimEnd('/') + "/");
        }

        return(where);
    }
示例#5
0
    /// <summary>
    /// Generates where condition for simple filter.
    /// </summary>
    public WhereCondition SimpleSearch()
    {
        if (txtSearch.Text == String.Empty)
        {
            // There is no text to search for
            return(new WhereCondition());
        }

        // identify operation and prepare search expression
        string        searchExpression = txtSearch.Text.Trim();
        QueryOperator queryOperator    = GetQueryOperator(searchExpression);

        searchExpression = PrepareSearchedText(searchExpression, queryOperator);

        // Search among either online or persistent users
        string[] columns = SessionInsteadOfUser ? SESSION_USER_COLUMNS : DATABASE_USER_COLUMNS;

        // Assemble the where condition
        WhereCondition whereCondition = new WhereCondition();

        foreach (var column in columns)
        {
            whereCondition
            .Or()
            .Where(column, queryOperator, searchExpression);
        }

        return(whereCondition);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title");
        linkId = QueryHelper.GetInteger("linkid", 0);
        if (linkId == 0)
        {
            RequestHelper.EndResponse();
        }

        LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId);

        EditedObject = link;

        IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID);

        EditedObject = issue;

        // Prevent accessing issues from sites other than current site
        if (issue.IssueSiteID != SiteContext.CurrentSiteID)
        {
            RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID);
        }

        var where = new WhereCondition().Where("LinkID", QueryOperator.Equals, linkId);

        // Link's issue is the main A/B test issue
        if (issue.IssueIsABTest && !issue.IssueIsVariant)
        {
            // Get A/B test and its winner issue ID
            ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
            if (test != null)
            {
                // Get ID of the same link from winner issue
                var winnerLink = LinkInfoProvider.GetLinks()
                                 .WhereEquals("LinkIssueID", test.TestWinnerIssueID)
                                 .WhereEquals("LinkTarget", link.LinkTarget)
                                 .WhereEquals("LinkDescription", link.LinkDescription)
                                 .TopN(1)
                                 .Column("LinkID")
                                 .FirstOrDefault();

                if (winnerLink != null)
                {
                    if (winnerLink.LinkID > 0)
                    {
                        // Add link ID of winner issue link
                        where.Or(new WhereCondition().Where("LinkID", QueryOperator.Equals, winnerLink.LinkID));
                    }
                }
            }
        }
        where.And(new WhereCondition(fltOpenedBy.WhereCondition));

        UniGrid.WhereCondition        = where.WhereCondition;
        UniGrid.QueryParameters       = where.Parameters;
        UniGrid.Pager.DefaultPageSize = PAGESIZE;
        UniGrid.Pager.ShowPageSize    = false;
        UniGrid.FilterLimit           = 1;
        UniGrid.OnExternalDataBound  += UniGrid_OnExternalDataBound;
    }
    /// <summary>
    /// Creates where condition for SKUs listing.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        // Display ONLY products - not product options
        var where = new WhereCondition().WhereNull("SKUOptionCategoryID");

        // Select only products without documents
        if ((NodeID <= 0) && DisplayTreeInProducts)
        {
            where.WhereNotIn("SKUID", SKUInfoProvider.GetSKUs().Column("SKUID").From("View_CMS_Tree_Joined").WhereNotNull("NodeSKUID").And().WhereEquals("NodeSiteID", SiteContext.CurrentSiteID));
        }

        // Ordinary user can see only product from departments he can access
        var cui = MembershipContext.AuthenticatedUser;

        if (!cui.IsGlobalAdministrator && !cui.IsAuthorizedPerResource("CMS.Ecommerce", "AccessAllDepartments"))
        {
            where.Where(w => w.WhereNull("SKUDepartmentID").Or().WhereIn("SKUDepartmentID", new IDQuery <UserDepartmentInfo>("DepartmentID").WhereEquals("UserID", cui.UserID)));
        }

        // Reflect "Allow global products" setting
        var siteWhere = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);

        if (AllowGlobalObjects)
        {
            siteWhere.Or().WhereNull("SKUSiteID");
        }

        return(where.Where(siteWhere));
    }
示例#8
0
    private DataSet GetRecycleBinSeletedItems(BinSettingsContainer settings, string columns)
    {
        var where = new WhereCondition();

        switch (settings.CurrentWhat)
        {
        case What.AllObjects:
            if (IsSingleSite)
            {
                where.WhereNull("VersionObjectSiteID");
            }
            if (settings.Site != null)
            {
                where.Or().WhereEquals("VersionObjectSiteID", settings.Site.SiteID);
            }

            // Wrap filter condition with brackets
            where.Where(new WhereCondition(filter.WhereCondition)
            {
                WhereIsComplex = true
            });
            where = GetWhereCondition(where);
            break;

        case What.SelectedObjects:
            // Restore selected objects
            var toRestore = settings.SelectedItems;
            where.WhereIn("VersionID", toRestore);
            break;
        }

        return(ObjectVersionHistoryInfoProvider.GetRecycleBin(where.ToString(true), OrderBy, -1, columns));
    }
示例#9
0
    private WhereCondition AddIssueAssignedTemplate(WhereCondition assignedTemplatesWhere, int issueID)
    {
        var issueTemplateCondition = IssueInfoProvider.GetIssues()
                                     .Column("IssueTemplateID")
                                     .WhereEquals("IssueID", issueID);

        return(assignedTemplatesWhere.Or().WhereIn("TemplateID", issueTemplateCondition));
    }
示例#10
0
    /// <summary>
    /// Initializes the selector.
    /// </summary>
    public void InitSelector()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        uniSelector.AdditionalSearchColumns = "CustomerFirstName,CustomerCompany,CustomerEmail";

        // Set resource prefix if specified
        if (!string.IsNullOrEmpty(ResourcePrefix))
        {
            uniSelector.ResourcePrefix = ResourcePrefix;
        }

        var where = new WhereCondition();

        // Do not filter customer by UserID if both Anonymous and Registered are requested
        if (!DisplayRegisteredCustomers || !DisplayAnonymousCustomers)
        {
            // Add registered customers
            if (DisplayRegisteredCustomers)
            {
                where.WhereNotNull("CustomerUserID");
            }

            // Add anonymous customers
            if (DisplayAnonymousCustomers)
            {
                where.WhereNull("CustomerUserID");
            }
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems) && !where.WhereIsEmpty)
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if ((CustomerID > 0) && !where.WhereIsEmpty)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
示例#11
0
        private WhereCondition GetPriceWhereCondition()
        {
            var where = new WhereCondition();

            foreach (var range in GetSelectedRanges())
            {
                where.Or(GetWhereConditionForPriceRange(range));
            }

            return(where);
        }
    private WhereCondition GetCustomerCondition()
    {
        var where = new WhereCondition();

        // Add registered customers
        if (DisplayRegisteredCustomers)
        {
            where.WhereNotNull("CustomerUserID");
        }

        // Add anonymous customers
        if (DisplayAnonymousCustomers)
        {
            var condition = new WhereCondition().WhereNull("CustomerUserID")
                            .And()
                            .WhereEquals("CustomerSiteID", CurrentSite.SiteID);

            if (where.WhereIsEmpty)
            {
                where.Where(condition);
            }
            else
            {
                where.Or(condition);
            }
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems) && !where.WhereIsEmpty)
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if ((CustomerID > 0) && !where.WhereIsEmpty)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        return(where);
    }
示例#13
0
    private WhereCondition GetAddressWhereCondition()
    {
        var addressWhere = new WhereCondition();

        if (!String.IsNullOrEmpty(CurrentAccount.AccountAddress1))
        {
            addressWhere.Or().WhereContains("AccountAddress1", CurrentAccount.AccountAddress1);
        }
        if (!String.IsNullOrEmpty(CurrentAccount.AccountAddress2))
        {
            addressWhere.Or().WhereContains("AccountAddress2", CurrentAccount.AccountAddress2);
        }
        if (!String.IsNullOrEmpty(CurrentAccount.AccountCity))
        {
            addressWhere.Or().WhereContains("AccountCity", CurrentAccount.AccountCity);
        }
        if (!String.IsNullOrEmpty(CurrentAccount.AccountZIP))
        {
            addressWhere.Or().WhereContains("AccountZIP", CurrentAccount.AccountZIP);
        }
        return(addressWhere);
    }
示例#14
0
    private WhereCondition GetPhoneWhereCondition()
    {
        var phoneWhere = new WhereCondition();

        if (!String.IsNullOrEmpty(CurrentAccount.AccountPhone))
        {
            phoneWhere.WhereContains("AccountPhone", CurrentAccount.AccountPhone);
        }
        if (!String.IsNullOrEmpty(CurrentAccount.AccountFax))
        {
            phoneWhere.Or().WhereContains("AccountFax", CurrentAccount.AccountFax);
        }
        return(phoneWhere);
    }
示例#15
0
    /// <summary>
    /// Add site default currency according selector settings.
    /// </summary>
    /// <param name="whereCondition">Where condition.</param>
    /// <returns></returns>
    protected override string AppendInclusiveWhere(string whereCondition)
    {
        // Prepare where condition
        var where = new WhereCondition(whereCondition);

        // Add site main currency when required
        if (AddSiteDefaultCurrency && (MainCurrencyID > 0))
        {
            where.Or().WhereEquals("CurrencyID", MainCurrencyID);
        }

        // Append additional items
        return(base.AppendInclusiveWhere(where.ToString(true)));
    }
示例#16
0
        /// <summary>
        /// Filters the data to include only documents on given path(s).
        /// </summary>
        /// <typeparam name="TQuery">Type of the data query</typeparam>
        /// <param name="baseQuery">The query being filtered upon</param>
        /// <param name="paths">List of document paths</param>
        /// <returns>The filtered query</returns>
        /// <remarks>DocumentQuery.Path() adds parameters to a property "Paths", but if you are building a where condition that needs to 'OR' the path filter, it won't work since DocumentQuery.Path() doesn't add the path filter into the Where logic until query execution.</remarks>
        public static TQuery WhereInPath <TQuery>(this WhereConditionBase <TQuery> baseQuery, params string[] paths) where TQuery : WhereConditionBase <TQuery>, new()
        {
            var  whereCondition = new WhereCondition();
            bool combined       = paths.Count() > 1;

            foreach (string current in paths)
            {
                whereCondition.Or().Where(new IWhereCondition[]
                {
                    TreePathUtils.GetAliasPathCondition(current, false, combined)
                });
            }
            return(baseQuery.Where(whereCondition));
        }
示例#17
0
    /// <summary>
    /// Creates WHERE condition for VersionObjectSiteID column.
    /// </summary>
    private WhereCondition GetVersionObjectSiteIDWhereCondition()
    {
        var where = new WhereCondition();
        if (IsSingleSite || (SiteName == "##global##"))
        {
            where.Where("VersionObjectSiteID", QueryUnaryOperator.IsNull);
        }

        if (CurrentSite != null)
        {
            where.Or().Where("VersionObjectSiteID", QueryOperator.Equals, CurrentSite.SiteID);
        }

        return(where);
    }
示例#18
0
        /// <summary>
        /// Filters the data to include only documents on given path.
        /// </summary>
        /// <typeparam name="TQuery">Type of the data query</typeparam>
        /// <param name="condition">The query being filtered upon</param>
        /// <param name="path">Document path</param>
        /// <param name="type">Path type to define selection scope</param>
        /// <returns>The filtered query</returns>
        /// <remarks>
        /// DocumentQuery.Path() adds parameters to a property "Paths", but if you are building a where condition that needs to 'OR' the path filter,
        /// it won't work since DocumentQuery.Path() doesn't add the path filter into the Where logic until query execution.
        /// </remarks>
        public static TQuery WhereInPath <TQuery>(this WhereConditionBase <TQuery> condition, string path, PathTypeEnum type = PathTypeEnum.Explicit) where TQuery : WhereConditionBase <TQuery>, new()
        {
            var paths = new List <string>();

            switch (type)
            {
            case PathTypeEnum.Single:
            {
                path = SqlHelper.EscapeLikeQueryPatterns(path, true, true, true);
                paths.Add(path);
                break;
            }

            case PathTypeEnum.Children:
            {
                path = SqlHelper.EscapeLikeQueryPatterns(path, true, true, true);
                paths.Add(TreePathUtils.EnsureChildPath(path));
                break;
            }

            case PathTypeEnum.Section:
            {
                path = SqlHelper.EscapeLikeQueryPatterns(path, true, true, true);
                paths.Add(TreePathUtils.EnsureChildPath(path));
                paths.Add(TreePathUtils.EnsureSinglePath(path));
                break;
            }

            case PathTypeEnum.Explicit:
                break;

            default:
                break;
            }

            bool combined             = paths.Count > 1;
            var  customWhereCondition = new WhereCondition();

            foreach (string current in paths)
            {
                customWhereCondition.Or().Where(new IWhereCondition[]
                {
                    TreePathUtils.GetAliasPathCondition(current, false, combined)
                });
            }

            return(condition.Where(customWhereCondition));
        }
示例#19
0
    /// <summary>
    /// Reloads control.
    /// </summary>
    public void ReloadData()
    {
        var where            = new WhereCondition(WhereCondition);
        uniselector.AllowAll = AllowAllItem;

        // Do not add condition to empty condition which allows everything
        if (!String.IsNullOrEmpty(where.WhereCondition))
        {
            string status = ValidationHelper.GetString(Value, "");
            if (!String.IsNullOrEmpty(status))
            {
                where.Or().WhereEquals(uniselector.ReturnColumnName, status);
            }
        }

        uniselector.WhereCondition = where.ToString(true);
        uniselector.Reload(true);
    }
示例#20
0
    private WhereCondition GetContactWhereCondition()
    {
        var         contactWhere = new WhereCondition();
        ContactInfo contact;

        // Get primary contact WHERE condition
        if (CurrentAccount.AccountPrimaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountPrimaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactLastName", contact.ContactLastName);
                }
            }
        }

        // Get secondary contact WHERE condition
        if (CurrentAccount.AccountSecondaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountSecondaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactLastName", contact.ContactLastName);
                }
            }
        }
        return(contactWhere);
    }
示例#21
0
        public override string GetWhereCondition()
        {
            var whereCondition = new WhereCondition();
            var originalQuery  = fltCountry.WhereCondition;

            if (string.IsNullOrEmpty(originalQuery) || string.IsNullOrEmpty(CountryIDColumnName))
            {
                return(string.Empty);
            }

            var countryIDs = CountryInfo.Provider.Get()
                             .Where(originalQuery)
                             .AsMaterializedList("CountryID");

            whereCondition.WhereIn(CountryIDColumnName, countryIDs);
            if (fltCountry.FilterOperator == WhereBuilder.NOT_LIKE || fltCountry.FilterOperator == WhereBuilder.NOT_EQUAL)
            {
                whereCondition.Or().WhereNull(CountryIDColumnName);
            }

            return(whereCondition.ToString(true));
        }
    private static IWhereCondition GetSiteWhereCondition(int siteId)
    {
        var siteWhere = new WhereCondition();

        // Allow global objects if global objects are requested
        var allowGlobal = siteId <= 0;

        // Allow global objects according to the site settings
        var siteName = SiteInfoProvider.GetSiteName(siteId);

        if (!string.IsNullOrEmpty(siteName))
        {
            allowGlobal = SettingsKeyInfoProvider.GetBoolValue(siteName + "." + ECommerceSettings.ALLOW_GLOBAL_PRODUCTS);
        }

        var siteIdcolumn = SKUInfoProvider.ProviderObject.TypeInfo.SiteIDColumn;

        if (allowGlobal)
        {
            // Include global objects
            siteWhere.WhereNull(siteIdcolumn);

            if (siteId > 0)
            {
                // Include site objects
                siteWhere.Or(new WhereCondition(siteIdcolumn, QueryOperator.Equals, siteId));
            }
        }
        else if (siteId > 0)
        {
            // Only site objects
            siteWhere.WhereEquals(siteIdcolumn, siteId);
        }

        return(siteWhere);
    }
    private DataSet GetRecycleBinSeletedItems(BinSettingsContainer settings, string columns)
    {
        var where = new WhereCondition();

        switch (settings.CurrentWhat)
        {
            case What.AllObjects:
                if (IsSingleSite)
                {
                    where.WhereNull("VersionObjectSiteID");
                }
                if (settings.Site != null)
                {
                    where.Or().WhereEquals("VersionObjectSiteID", settings.Site.SiteID);
                }

                // Wrap filter condition with brackets
                where.Where(new WhereCondition(filter.WhereCondition) { WhereIsComplex = true });
                where = GetWhereCondition(where);
                break;

            case What.SelectedObjects:
                // Restore selected objects
                var toRestore = settings.SelectedItems;
                where.WhereIn("VersionID", toRestore);
                break;
        }

        return ObjectVersionHistoryInfoProvider.GetRecycleBin(where.ToString(true), OrderBy, -1, columns);
    }
    /// <summary>
    /// Add site default currency according selector settings.
    /// </summary>
    /// <param name="whereCondition">Where condition.</param>
    /// <returns></returns>
    protected override string AppendInclusiveWhere(string whereCondition)
    {
        // Prepare where condition
        var where = new WhereCondition(whereCondition);

        // Add site main currency when required
        if (AddSiteDefaultCurrency && (MainCurrencyID > 0))
        {
            where.Or().WhereEquals("CurrencyID", MainCurrencyID);
        }

        // Append additional items
        return base.AppendInclusiveWhere(where.ToString(true));
    }
 private WhereCondition GetPhoneWhereCondition()
 {
     var phoneWhere = new WhereCondition();
     if (!String.IsNullOrEmpty(CurrentAccount.AccountPhone))
     {
         phoneWhere.WhereContains("AccountPhone", CurrentAccount.AccountPhone);
     }
     if (!String.IsNullOrEmpty(CurrentAccount.AccountFax))
     {
         phoneWhere.Or().WhereContains("AccountFax", CurrentAccount.AccountFax);
     }
     return phoneWhere;
 }
    private WhereCondition GetContactWhereCondition()
    {
        var contactWhere = new WhereCondition();
        ContactInfo contact;

        // Get primary contact WHERE condition
        if (CurrentAccount.AccountPrimaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountPrimaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactLastName", contact.ContactLastName);
                }
            }
        }

        // Get secondary contact WHERE condition
        if (CurrentAccount.AccountSecondaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountSecondaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactLastName", contact.ContactLastName);
                }
            }
        }
        return contactWhere;
    }
 private WhereCondition GetAddressWhereCondition()
 {
     var addressWhere = new WhereCondition();
     if (!String.IsNullOrEmpty(CurrentAccount.AccountAddress1))
     {
         addressWhere.Or().WhereContains("AccountAddress1", CurrentAccount.AccountAddress1);
     }
     if (!String.IsNullOrEmpty(CurrentAccount.AccountAddress2))
     {
         addressWhere.Or().WhereContains("AccountAddress2", CurrentAccount.AccountAddress2);
     }
     if (!String.IsNullOrEmpty(CurrentAccount.AccountCity))
     {
         addressWhere.Or().WhereContains("AccountCity", CurrentAccount.AccountCity);
     }
     if (!String.IsNullOrEmpty(CurrentAccount.AccountZIP))
     {
         addressWhere.Or().WhereContains("AccountZIP", CurrentAccount.AccountZIP);
     }
     return addressWhere;
 }
    /// <summary>
    /// Reloads the web part list.
    /// </summary>
    /// <param name="forceLoad">if set to <c>true</c>, reload the control even if the control has been already loaded</param>
    protected void LoadWebParts(bool forceLoad)
    {
        if (!dataLoaded || forceLoad)
        {
            var repeaterWhere = new WhereCondition();

            /* The order is category driven => first level category display name is used for all nodes incl. sub-nodes */
            string categoryOrder = @"
(SELECT CMS_WebPartCategory.CategoryDisplayName FROM CMS_WebPartCategory 
WHERE CMS_WebPartCategory.CategoryPath = (CASE WHEN (CHARINDEX('/', ObjectPath, 0) > 0) AND (CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1) = 0) 
THEN ObjectPath 
ELSE SUBSTRING(ObjectPath, 0, LEN(ObjectPath) - (LEN(ObjectPath) - CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1)))
END))
";

            // Set query repeater
            repItems.SelectedColumns = " ObjectID, DisplayName, ObjectType, ParentID, ThumbnailGUID, IconClass, ObjectLevel, WebPartDescription, WebPartSkipInsertProperties";
            repItems.OrderBy         = categoryOrder + ", ObjectType  DESC, DisplayName";

            // Setup the where condition
            if (SelectedCategory == CATEGORY_RECENTLY_USED)
            {
                // Recently used category
                RenderRecentlyUsedWebParts(true);
            }
            else
            {
                // Specific web part category
                int selectedCategoryId = ValidationHelper.GetInteger(SelectedCategory, 0);
                if (selectedCategoryId > 0)
                {
                    WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(selectedCategoryId);
                    if (categoryInfo != null)
                    {
                        string firstLevelCategoryPath = String.Empty;

                        // Select also all subcategories (using "/%")
                        string categoryPath = categoryInfo.CategoryPath;
                        if (!categoryPath.EndsWith("/", StringComparison.Ordinal))
                        {
                            categoryPath += "/";
                        }

                        // Do not limit items if not root category is selected
                        if (!categoryInfo.CategoryPath.EqualsCSafe("/"))
                        {
                            limitItems = false;
                        }

                        // Get all web parts for the selected category and its subcategories
                        if (categoryPath.EqualsCSafe("/"))
                        {
                            repeaterWhere.Where(repItems.WhereCondition).Where(w => w
                                                                               .WhereEquals("ObjectType", "webpart")
                                                                               .Or()
                                                                               .WhereEquals("ObjectLevel", 1)
                                                                               ).Where(w => w
                                                                                       .WhereEquals("ParentID", selectedCategoryId)
                                                                                       .Or()
                                                                                       .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                                                                                       );

                            // Set caching for query repeater
                            repItems.ForceCacheMinutes = true;
                            repItems.CacheMinutes      = 24 * 60;
                            repItems.CacheDependencies = "cms.webpart|all\ncms.webpartcategory|all";

                            // Show Recently used category
                            RenderRecentlyUsedWebParts(false);
                        }
                        else
                        {
                            // Prepare where condition -- the part that restricts web parts
                            repeaterWhere.WhereEquals("ObjectType", "webpart")
                            .Where(w => w
                                   .WhereEquals("ParentID", selectedCategoryId)
                                   .Or()
                                   .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                                   );

                            // Get first level category path
                            firstLevelCategoryPath = categoryPath.Substring(0, categoryPath.IndexOf('/', 2));

                            var selectedCategoryWhere = new WhereCondition();

                            // Distinguish special categories
                            if (categoryPath.StartsWithCSafe(CATEGORY_UIWEBPARTS, true))
                            {
                                if (!categoryPath.EqualsCSafe(firstLevelCategoryPath + "/", true))
                                {
                                    // Currently selected category is one of subcategories
                                    string specialCategoryPath = firstLevelCategoryPath;
                                    firstLevelCategoryPath = categoryPath.Substring(CATEGORY_UIWEBPARTS.Length + 1).TrimEnd('/');
                                    selectedCategoryWhere.WhereEquals("ObjectPath", specialCategoryPath + "/" + firstLevelCategoryPath);
                                }
                                else
                                {
                                    // Currently selected category is root category
                                    selectedCategoryWhere.WhereStartsWith("ObjectPath", firstLevelCategoryPath);
                                }
                            }
                            else
                            {
                                // All web part category
                                selectedCategoryWhere.WhereEquals("ObjectPath", firstLevelCategoryPath);
                            }

                            repeaterWhere.Or().Where(w => w
                                                     .WhereEquals("ObjectType", "webpartcategory")
                                                     .WhereEquals("ObjectLevel", 1)
                                                     .Where(selectedCategoryWhere)
                                                     );

                            // Set caching for query repeater
                            repItems.CacheMinutes      = 0;
                            repItems.ForceCacheMinutes = true;
                        }
                    }
                }

                // Do not display "Widget only" web parts in the toolbar
                repItems.WhereCondition = new WhereCondition()
                                          .Where(repeaterWhere)
                                          .Where(w => w
                                                 .WhereNull("WebPartType")
                                                 .Or()
                                                 .WhereNotEquals("WebPartType", (int)WebPartTypeEnum.WidgetOnly)
                                                 )
                                          .ToString(true);

                // Limit items if required
                if (limitItems)
                {
                    repItems.SelectTopN = DEFAULT_WEBPART_COUNT;
                }

                repItems.ReloadData(false);
                repItems.DataBind();
            }

            dataLoaded = true;
        }
    }
    /// <summary>
    /// Reloads control.
    /// </summary>
    public void ReloadData()
    {
        var where = new WhereCondition(WhereCondition);

        var siteName    = SiteID > 0 ? SiteInfoProvider.GetSiteName(SiteID) : SiteContext.CurrentSiteName;
        var allowGlobal = SettingsKeyInfoProvider.GetBoolValue(siteName + ".cmscmglobalconfiguration");

        uniselector.AllowAll = AllowAllItem;

        if (DisplayAll || DisplaySiteOrGlobal)
        {
            // Display all site and global statuses
            if (DisplayAll && allowGlobal)
            {
                // No WHERE condition required
            }
            // Display current site and global statuses
            else if (DisplaySiteOrGlobal && allowGlobal && (SiteID > 0))
            {
                where.WhereEqualsOrNull("AccountStatusSiteID", SiteID);
            }
            // Current site
            else if (SiteID > 0)
            {
                where.WhereEquals("AccountStatusSiteID", SiteID);
            }
            // Display global statuses
            else if (allowGlobal)
            {
                where.WhereNull("AccountStatusSiteID");
            }

            // Don't display anything
            if (String.IsNullOrEmpty(where.WhereCondition) && !DisplayAll)
            {
                where.NoResults();
            }
        }
        // Display either global or current site statuses
        else
        {
            // Current site
            if (SiteID > 0)
            {
                where.WhereEquals("AccountStatusSiteID", SiteID);
            }
            // Display global statuses
            else if (((SiteID == UniSelector.US_GLOBAL_RECORD) || (SiteID == UniSelector.US_NONE_RECORD)) && allowGlobal)
            {
                where.WhereNull("AccountStatusSiteID");
            }
            // Don't display anything
            if (String.IsNullOrEmpty(where.WhereCondition))
            {
                where.NoResults();
            }
        }

        // Do not add condition to empty condition which allows everything
        if (!String.IsNullOrEmpty(where.WhereCondition))
        {
            string status = ValidationHelper.GetString(Value, "");
            if (!String.IsNullOrEmpty(status))
            {
                where.Or().WhereEquals(uniselector.ReturnColumnName, status);
            }
        }

        uniselector.WhereCondition = where.ToString(expand: true);
        uniselector.Reload(true);
    }
    /// <summary>
    /// Reloads the web part list.
    /// </summary>
    /// <param name="forceLoad">if set to <c>true</c>, reload the control even if the control has been already loaded</param>
    protected void LoadWebParts(bool forceLoad)
    {
        if (!dataLoaded || forceLoad)
        {
            var repeaterWhere = new WhereCondition();

            /* The order is category driven => first level category display name is used for all nodes incl. sub-nodes */
            string categoryOrder = @"
        (SELECT CMS_WebPartCategory.CategoryDisplayName FROM CMS_WebPartCategory
        WHERE CMS_WebPartCategory.CategoryPath = (CASE WHEN (CHARINDEX('/', ObjectPath, 0) > 0) AND (CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1) = 0)
        THEN ObjectPath
        ELSE SUBSTRING(ObjectPath, 0, LEN(ObjectPath) - (LEN(ObjectPath) - CHARINDEX('/', ObjectPath, CHARINDEX('/', ObjectPath, 0) + 1)))
        END))
        ";

            // Set query repeater
            repItems.SelectedColumns = " ObjectID, DisplayName, ObjectType, ParentID, ThumbnailGUID, IconClass, ObjectLevel, WebPartDescription, WebPartSkipInsertProperties";
            repItems.OrderBy = categoryOrder + ", ObjectType  DESC, DisplayName";

            // Setup the where condition
            if (SelectedCategory == CATEGORY_RECENTLY_USED)
            {
                // Recently used category
                RenderRecentlyUsedWebParts(true);
            }
            else
            {
                // Specific web part category
                int selectedCategoryId = ValidationHelper.GetInteger(SelectedCategory, 0);
                if (selectedCategoryId > 0)
                {
                    WebPartCategoryInfo categoryInfo = WebPartCategoryInfoProvider.GetWebPartCategoryInfoById(selectedCategoryId);
                    if (categoryInfo != null)
                    {
                        string firstLevelCategoryPath = String.Empty;

                        // Select also all subcategories (using "/%")
                        string categoryPath = categoryInfo.CategoryPath;
                        if (!categoryPath.EndsWith("/"))
                        {
                            categoryPath += "/";
                        }

                        // Do not limit items if not root category is selected
                        if (!categoryInfo.CategoryPath.EqualsCSafe("/"))
                        {
                            limitItems = false;
                        }

                        // Get all web parts for the selected category and its subcategories
                        if (categoryPath.EqualsCSafe("/"))
                        {
                            repeaterWhere.Where(repItems.WhereCondition).Where(w => w
                                .WhereEquals("ObjectType", "webpart")
                                .Or()
                                .WhereEquals("ObjectLevel", 1)
                            ).Where(w => w
                                .WhereEquals("ParentID", selectedCategoryId)
                                .Or()
                                .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                            );

                            // Set caching for query repeater
                            repItems.ForceCacheMinutes = true;
                            repItems.CacheMinutes = 24 * 60;
                            repItems.CacheDependencies = "cms.webpart|all\ncms.webpartcategory|all";

                            // Show Recently used category
                            RenderRecentlyUsedWebParts(false);
                        }
                        else
                        {
                            // Prepare where condition -- the part that restricts web parts
                            repeaterWhere.WhereEquals("ObjectType", "webpart")
                                .Where(w => w
                                    .WhereEquals("ParentID", selectedCategoryId)
                                    .Or()
                                    .WhereIn("ParentID", WebPartCategoryInfoProvider.GetCategories().WhereStartsWith("CategoryPath", categoryPath))
                                );

                            // Get first level category path
                            firstLevelCategoryPath = categoryPath.Substring(0, categoryPath.IndexOf('/', 2));

                            var selectedCategoryWhere = new WhereCondition();

                            // Distinguish special categories
                            if (categoryPath.StartsWithCSafe(CATEGORY_UIWEBPARTS, true))
                            {
                                if (!categoryPath.EqualsCSafe(firstLevelCategoryPath + "/", true))
                                {
                                    // Currently selected category is one of subcategories
                                    string specialCategoryPath = firstLevelCategoryPath;
                                    firstLevelCategoryPath = categoryPath.Substring(CATEGORY_UIWEBPARTS.Length + 1).TrimEnd('/');
                                    selectedCategoryWhere.WhereEquals("ObjectPath", specialCategoryPath + "/" + firstLevelCategoryPath);
                                }
                                else
                                {
                                    // Currently selected category is root category
                                    selectedCategoryWhere.WhereStartsWith("ObjectPath", firstLevelCategoryPath);
                                }
                            }
                            else
                            {
                                // All web part category
                                selectedCategoryWhere.WhereEquals("ObjectPath", firstLevelCategoryPath);
                            }

                            repeaterWhere.Or().Where(w => w
                                .WhereEquals("ObjectType", "webpartcategory")
                                .WhereEquals("ObjectLevel", 1)
                                .Where(selectedCategoryWhere)
                            );

                            // Set caching for query repeater
                            repItems.CacheMinutes = 0;
                            repItems.ForceCacheMinutes = true;
                        }
                    }
                }

                // Do not display "Widget only" web parts in the toolbar
                repItems.WhereCondition = new WhereCondition()
                    .Where(repeaterWhere)
                    .Where(w => w
                        .WhereNull("WebPartType")
                        .Or()
                        .WhereNotEquals("WebPartType", (int)WebPartTypeEnum.WidgetOnly)
                    )
                    .ToString(true);

                // Limit items if required
                if (limitItems)
                {
                    repItems.SelectTopN = DEFAULT_WEBPART_COUNT;
                }

                repItems.ReloadData(false);
                repItems.DataBind();
            }

            dataLoaded = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title");
        linkId = QueryHelper.GetInteger("linkid", 0);
        if (linkId == 0)
        {
            RequestHelper.EndResponse();
        }

        LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId);

        EditedObject = link;

        IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID);

        EditedObject = issue;

        // Prevent accessing issues from sites other than current site
        if (issue.IssueSiteID != SiteContext.CurrentSiteID)
        {
            RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID);
        }

        var listingWhereCondition = new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", linkId);

        // Link's issue is the main A/B test issue
        if (issue.IssueIsABTest && !issue.IssueIsVariant)
        {
            // Get A/B test and its winner issue ID
            ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
            if (test != null)
            {
                // Get ID of the same link from winner issue
                var winnerLink = LinkInfoProvider.GetLinks()
                                 .WhereEquals("LinkIssueID", test.TestWinnerIssueID)
                                 .WhereEquals("LinkTarget", link.LinkTarget)
                                 .WhereEquals("LinkDescription", link.LinkDescription)
                                 .TopN(1)
                                 .Column("LinkID")
                                 .FirstOrDefault();

                if (winnerLink != null)
                {
                    if (winnerLink.LinkID > 0)
                    {
                        // Add link ID of winner issue link
                        listingWhereCondition.Or(new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", winnerLink.LinkID));
                    }
                }
            }
        }

        UniGrid.Pager.DefaultPageSize = PAGESIZE;
        UniGrid.Pager.ShowPageSize    = false;
        UniGrid.FilterLimit           = 1;
        fltOpenedBy.EmailColumn       = "ClickedLinkEmail";

        // Get click count by email
        UniGrid.DataSource = ClickedLinkInfoProvider.GetClickedLinks()
                             .Columns(
            new QueryColumn("ClickedLinkEmail"),
            new AggregatedColumn(AggregationType.Count, null).As("ClickCount")
            )
                             .GroupBy("ClickedLinkEmail")
                             .Where(listingWhereCondition)
                             .And()
                             .Where(fltOpenedBy.WhereCondition)
                             .OrderByDescending("ClickCount")
                             .Result;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title");
        linkId = QueryHelper.GetInteger("linkid", 0);
        if (linkId == 0)
        {
            RequestHelper.EndResponse();
        }

        LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId);
        EditedObject = link;

        IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID);
        EditedObject = issue;

        // Prevent accessing issues from sites other than current site
        if (issue.IssueSiteID != SiteContext.CurrentSiteID)
        {
            RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID);
        }

        var listingWhereCondition = new WhereCondition().Where("LinkID", QueryOperator.Equals, linkId);

        // Link's issue is the main A/B test issue
        if (issue.IssueIsABTest && !issue.IssueIsVariant)
        {
            // Get A/B test and its winner issue ID
            ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
            if (test != null)
            {
                // Get ID of the same link from winner issue
                var winnerLink = LinkInfoProvider.GetLinks()
                                                 .WhereEquals("LinkIssueID", test.TestWinnerIssueID)
                                                 .WhereEquals("LinkTarget", link.LinkTarget)
                                                 .WhereEquals("LinkDescription", link.LinkDescription)
                                                 .TopN(1)
                                                 .Column("LinkID")
                                                 .FirstOrDefault();

                if (winnerLink != null)
                {
                    if (winnerLink.LinkID > 0)
                    {
                        // Add link ID of winner issue link
                        listingWhereCondition.Or(new WhereCondition().Where("LinkID", QueryOperator.Equals, winnerLink.LinkID));
                    }
                }
            }
        }
        var filterCondition = new WhereCondition(fltOpenedBy.WhereCondition)
        {
            // True ensures that where condition will be placed into brackets when combining with different WHERE condition
            WhereIsComplex = true
        };
        listingWhereCondition.And(filterCondition);

        UniGrid.WhereCondition = listingWhereCondition.WhereCondition;
        UniGrid.QueryParameters = listingWhereCondition.Parameters;
        UniGrid.Pager.DefaultPageSize = PAGESIZE;
        UniGrid.Pager.ShowPageSize = false;
        UniGrid.FilterLimit = 1;
        UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound;
    }
    /// <summary>
    /// Creates where condition for SKUs listing.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        // Display ONLY products - not product options
        var where = new WhereCondition().WhereNull("SKUOptionCategoryID");

        // Select only products without documents
        if ((NodeID <= 0) && DisplayTreeInProducts)
        {
            where.WhereNotIn("SKUID", SKUInfoProvider.GetSKUs().Column("SKUID").From("View_CMS_Tree_Joined").WhereNotNull("NodeSKUID").And().WhereEquals("NodeSiteID", SiteContext.CurrentSiteID));
        }

        // Ordinary user can see only product from departments he can access
        var cui = MembershipContext.AuthenticatedUser;
        if (!cui.IsGlobalAdministrator && !cui.IsAuthorizedPerResource("CMS.Ecommerce", "AccessAllDepartments"))
        {
            where.Where(w => w.WhereNull("SKUDepartmentID").Or().WhereIn("SKUDepartmentID", new IDQuery<UserDepartmentInfo>("DepartmentID").WhereEquals("UserID", cui.UserID)));
        }

        // Reflect "Allow global products" setting
        var siteWhere = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);
        if (AllowGlobalObjects)
        {
            siteWhere.Or().WhereNull("SKUSiteID");
        }

        return where.Where(siteWhere);
    }
    /// <summary>
    /// Creates level where condition.
    /// </summary>
    /// <param name="showAllLevels">Indicates if pages from all levels should be retrieved</param>
    /// <param name="orderBy">Current order by</param>
    private WhereCondition GetLevelWhereCondition(bool showAllLevels, ref string orderBy)
    {
        var levelCondition = new WhereCondition();
        if (showAllLevels)
        {
            string path = aliasPath ?? string.Empty;
            levelCondition.WhereStartsWith("NodeAliasPath", path.TrimEnd('/') + "/")
                          .WhereGreaterThan("NodeLevel", 0);
        }
        else
        {
            levelCondition.WhereEquals("NodeParentID", Node.NodeID)
                          .WhereEquals("NodeLevel", Node.NodeLevel + 1);

            // Extend the where condition to include the root document
            if (RequiresDialog && (Node != null) && (Node.NodeParentID == 0))
            {
                levelCondition.Or().WhereNull("NodeParentID");

                orderBy = String.Join(",","NodeParentID ASC", orderBy);
            }
        }

        if (ClassID > 0)
        {
            levelCondition.WhereEquals("NodeClassID", ClassID);
        }

        return levelCondition;
    }
    /// <summary>
    /// Creates WHERE condition for VersionObjectSiteID column.
    /// </summary>
    private WhereCondition GetVersionObjectSiteIDWhereCondition()
    {
        var where = new WhereCondition();
        if (IsSingleSite || (SiteName == "##global##"))
        {
            where.Where("VersionObjectSiteID", QueryUnaryOperator.IsNull);
        }

        if (CurrentSite != null)
        {
            where.Or().Where("VersionObjectSiteID", QueryOperator.Equals, CurrentSite.SiteID);
        }

        return where;
    }
    /// <summary>
    /// Reloads control.
    /// </summary>
    public void ReloadData()
    {
        var where = new WhereCondition(WhereCondition);

        var siteName = SiteID > 0 ? SiteInfoProvider.GetSiteName(SiteID) : SiteContext.CurrentSiteName;
        var allowGlobal = SettingsKeyInfoProvider.GetBoolValue(siteName + ".cmscmglobalconfiguration");

        uniselector.AllowAll = AllowAllItem;

        if (DisplayAll || DisplaySiteOrGlobal)
        {
            // Display all site and global statuses
            if (DisplayAll && allowGlobal)
            {
                // No WHERE condition required
            }
            // Display current site and global statuses
            else if (DisplaySiteOrGlobal && allowGlobal && (SiteID > 0))
            {
                where.WhereEqualsOrNull("AccountStatusSiteID", SiteID);
            }
            // Current site
            else if (SiteID > 0)
            {
                where.WhereEquals("AccountStatusSiteID", SiteID);
            }
            // Display global statuses
            else if (allowGlobal)
            {
                where.WhereNull("AccountStatusSiteID");
            }

            // Don't display anything
            if (String.IsNullOrEmpty(where.WhereCondition) && !DisplayAll)
            {
                where.NoResults();
            }
        }
        // Display either global or current site statuses
        else
        {
            // Current site
            if (SiteID > 0)
            {
                where.WhereEquals("AccountStatusSiteID", SiteID);
            }
            // Display global statuses
            else if (((SiteID == UniSelector.US_GLOBAL_RECORD) || (SiteID == UniSelector.US_NONE_RECORD)) && allowGlobal)
            {
                where.WhereNull("AccountStatusSiteID");
            }
            // Don't display anything
            if (String.IsNullOrEmpty(where.WhereCondition))
            {
                where.NoResults();
            }
        }

        // Do not add condition to empty condition which allows everything
        if (!String.IsNullOrEmpty(where.WhereCondition))
        {
            string status = ValidationHelper.GetString(Value, "");
            if (!String.IsNullOrEmpty(status))
            {
                where.Or().WhereEquals(uniselector.ReturnColumnName, status);
            }
        }

        uniselector.WhereCondition = where.ToString(expand: true);
        uniselector.Reload(true);
    }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        if (!DisplayNoDataMessage)
        {
            uniSelector.ZeroRowsText = string.Empty;
        }

        // Need to set uni-selector value again after basic form reload
        if (AllowMultipleChoice)
        {
            uniSelector.Value = mMultipleChoiceValue;
        }

        var where = new WhereCondition();

        if (ProductOptionCategoryID > 0)
        {
            where.WhereEquals("SKUOptionCategoryID", ProductOptionCategoryID);
        }
        else
        {
            var productSiteWhere = new WhereCondition();

            // Add global products
            if (DisplayGlobalProducts)
            {
                productSiteWhere.Where(w => w.WhereNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific products
            if (DisplaySiteProducts)
            {
                productSiteWhere.Or().Where(w => w.WhereNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Where(productSiteWhere);
        }

        // Exclude standard products if needed
        if (!DisplayStandardProducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Product.ToStringRepresentation());
        }

        // Exclude memberships if needed
        if (!DisplayMemberships)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Membership.ToStringRepresentation());
        }

        // Exclude e-products if needed
        if (!DisplayEproducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.EProduct.ToStringRepresentation());
        }

        // Exclude bundles if needed
        if (!DisplayBundles)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Bundle.ToStringRepresentation());
        }

        // Exclude products with product options if needed
        if (DisplayOnlyProductsWithoutOptions)
        {
            where.WhereNotIn("SKUID", new IDQuery <SKUOptionCategoryInfo>("SKUID"));
        }

        if (DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            var optionsSiteWhere = new WhereCondition();

            // Add global options
            if (DisplayGlobalOptions)
            {
                optionsSiteWhere.Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific options
            if (DisplaySiteOptions)
            {
                optionsSiteWhere.Or().Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Or().Where(optionsSiteWhere);
            where = new WhereCondition().Where(where);
        }

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("SKUEnabled");
        }

        if (!DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            where.WhereNull("SKUOptionCategoryID");
        }

        if (DisplayProductVariants)
        {
            // Alias for COM_SKU
            var parents = new QuerySourceTable("COM_SKU", "parentIDs");

            // Select IDs of all products that are not parents of variants
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(parents, "COM_SKU.SKUID", "parentIDs.SKUParentSKUID"))
                      .Where(new WhereCondition().WhereNull("parentIDs.SKUID"));

            where.WhereIn("SKUID", ids);
        }
        else
        {
            // Do not display variants
            where.WhereNull("SKUParentSKUID");
        }

        // Add items which have to be on the list
        var additionalList = AdditionalItems.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        if (additionalList.Length > 0)
        {
            var ids = ValidationHelper.GetIntegers(additionalList, 0);
            where.Or().WhereIn("SKUID", ids);
        }

        // Selected value must be on the list
        if (SKUID > 0)
        {
            where.Or().WhereEquals("SKUID", SKUID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        if (!DisplayNoDataMessage)
        {
            uniSelector.ZeroRowsText = string.Empty;
        }

        // Need to set uni-selector value again after basic form reload
        if (AllowMultipleChoice)
        {
            uniSelector.Value = mMultipleChoiceValue;
        }

        var where = new WhereCondition();

        if (ProductOptionCategoryID > 0)
        {
            where.WhereEquals("SKUOptionCategoryID", ProductOptionCategoryID);
        }
        else
        {
            var productSiteWhere = new WhereCondition();

            // Add global products
            if (DisplayGlobalProducts)
            {
                productSiteWhere.Where(w => w.WhereNull("SKUOptionCategoryID")
                                             .WhereNull("SKUSiteID"));
            }

            // Add site specific products
            if (DisplaySiteProducts)
            {
                productSiteWhere.Or().Where(w => w.WhereNull("SKUOptionCategoryID")
                                                  .WhereEquals("SKUSiteID", SiteID));
            }

            where.Where(productSiteWhere);
        }

        // Exclude standard products if needed
        if (!DisplayStandardProducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Product.ToStringRepresentation());
        }

        // Exclude memberships if needed
        if (!DisplayMemberships)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Membership.ToStringRepresentation());
        }

        // Exclude e-products if needed
        if (!DisplayEproducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.EProduct.ToStringRepresentation());
        }

        // Exclude donations if needed
        if (!DisplayDonations)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Donation.ToStringRepresentation());
        }

        // Exclude bundles if needed
        if (!DisplayBundles)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Bundle.ToStringRepresentation());
        }

        // Exclude products with product options if needed
        if (DisplayOnlyProductsWithoutOptions)
        {
            where.WhereNotIn("SKUID", new IDQuery<SKUOptionCategoryInfo>("SKUID"));
        }

        if (DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            var optionsSiteWhere = new WhereCondition();

            // Add global options
            if (DisplayGlobalOptions)
            {
                optionsSiteWhere.Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                             .WhereNull("SKUSiteID"));
            }

            // Add site specific options
            if (DisplaySiteOptions)
            {
                optionsSiteWhere.Or().Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                                  .WhereEquals("SKUSiteID", SiteID));
            }

            where.Or().Where(optionsSiteWhere);
            where = new WhereCondition().Where(where);
        }

        // Filter out only product from users departments
        if (UserID > 0)
        {
            where.WhereIn("SKUDepartmentID", new IDQuery<UserDepartmentInfo>("DepartmentID").WhereEquals("UserID", UserID).Or().WhereNull("SKUDepartmentID"));
        }

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("SKUEnabled");
        }

        if (!DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            where.WhereNull("SKUOptionCategoryID");
        }

        if (DisplayProductVariants)
        {
            // Do not display parent product in selector
            where.WhereNotIn("SKUID", new IDQuery<SKUInfo>("SKUParentSKUID").WhereNotNull("SKUParentSKUID"));
        }
        else
        {
            // Do not display variants
            where.WhereNull("SKUParentSKUID");
        }

        // Add items which have to be on the list
        var additionalList = AdditionalItems.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        if (additionalList.Length > 0)
        {
            var ids = ValidationHelper.GetIntegers(additionalList, 0);
            where.Or().WhereIn("SKUID", ids);
        }

        // Selected value must be on the list
        if (SKUID > 0)
        {
            where.Or().WhereEquals("SKUID", SKUID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        PageTitle.TitleText = GetString("newsletter_issue_subscribersclicks.title");
        linkId = QueryHelper.GetInteger("linkid", 0);
        if (linkId == 0)
        {
            RequestHelper.EndResponse();
        }

        LinkInfo link = LinkInfoProvider.GetLinkInfo(linkId);
        EditedObject = link;

        IssueInfo issue = IssueInfoProvider.GetIssueInfo(link.LinkIssueID);
        EditedObject = issue;

        // Prevent accessing issues from sites other than current site
        if (issue.IssueSiteID != SiteContext.CurrentSiteID)
        {
            RedirectToResourceNotAvailableOnSite("Issue with ID " + link.LinkIssueID);
        }

        var listingWhereCondition = new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", linkId);

        // Link's issue is the main A/B test issue
        if (issue.IssueIsABTest && !issue.IssueIsVariant)
        {
            // Get A/B test and its winner issue ID
            ABTestInfo test = ABTestInfoProvider.GetABTestInfoForIssue(issue.IssueID);
            if (test != null)
            {
                // Get ID of the same link from winner issue
                var winnerLink = LinkInfoProvider.GetLinks()
                                                 .WhereEquals("LinkIssueID", test.TestWinnerIssueID)
                                                 .WhereEquals("LinkTarget", link.LinkTarget)
                                                 .WhereEquals("LinkDescription", link.LinkDescription)
                                                 .TopN(1)
                                                 .Column("LinkID")
                                                 .FirstOrDefault();

                if (winnerLink != null)
                {
                    if (winnerLink.LinkID > 0)
                    {
                        // Add link ID of winner issue link
                        listingWhereCondition.Or(new WhereCondition().WhereEquals("ClickedLinkNewsletterLinkID", winnerLink.LinkID));
                    }
                }
            }
        }

        UniGrid.Pager.DefaultPageSize = PAGESIZE;
        UniGrid.Pager.ShowPageSize = false;
        UniGrid.FilterLimit = 1;
        fltOpenedBy.EmailColumn = "ClickedLinkEmail";

        // Get click count by email
        UniGrid.DataSource = ClickedLinkInfoProvider.GetClickedLinks()
            .Columns(
                new QueryColumn("ClickedLinkEmail"),
                new AggregatedColumn(AggregationType.Count, null).As("ClickCount")
            )
            .GroupBy("ClickedLinkEmail")
            .Where(listingWhereCondition)
            .And()
            .Where(fltOpenedBy.WhereCondition)
            .OrderByDescending("ClickCount")
            .Result;
    }
    protected void SetupControls()
    {
        // If current control context is widget or livesite hide site selector
        if (ControlsHelper.CheckControlContext(this, ControlContext.WIDGET_PROPERTIES) || ControlsHelper.CheckControlContext(this, ControlContext.LIVE_SITE))
        {
            ShowSiteFilter = false;
        }

        // Set prefix if not set
        if (ResourcePrefix == String.Empty)
        {
            // Set resource prefix based on mode
            if ((SelectionMode == SelectionModeEnum.Multiple) || (SelectionMode == SelectionModeEnum.MultipleButton) || (SelectionMode == SelectionModeEnum.MultipleTextBox))
            {
                usUsers.ResourcePrefix = "selectusers";
            }
        }

        // Add sites filter
        if (ShowSiteFilter)
        {
            usUsers.FilterControl = "~/CMSFormControls/Filters/SiteFilter.ascx";
            usUsers.SetValue("DefaultFilterValue", (SiteID > 0) ? SiteID : SiteContext.CurrentSiteID);
            usUsers.SetValue("FilterMode", "user");
        }

        // Generate WhereCondtion based on SelectUser's properties
        var usersWhereCondition = new WhereCondition();
        var userTypeInfo        = ObjectTypeManager.GetTypeInfo(UserInfo.OBJECT_TYPE);

        // Hide hidden users
        if (HideHiddenUsers)
        {
            var apparentUsersCondition = new WhereCondition().WhereEqualsOrNull("UserIsHidden", 0);
            usersWhereCondition.And(apparentUsersCondition);
        }

        // Hide disabled users
        if (HideDisabledUsers)
        {
            var enabledUsersCondition = new WhereCondition(UserInfoProvider.USER_ENABLED_WHERE_CONDITION);
            usersWhereCondition.And(enabledUsersCondition);
        }

        // Hide non-approved users
        if (HideNonApprovedUsers)
        {
            var approvedUserIDs = UserSettingsInfoProvider
                                  .GetUserSettings()
                                  .WhereEqualsOrNull("UserWaitingForApproval", 0)
                                  .Column("UserSettingsUserID");

            var approvedUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, approvedUserIDs);
            usersWhereCondition.And(approvedUsersCondition);
        }

        // Select group users
        if (GroupID > 0)
        {
            var groupUserIDs = new ObjectQuery(PredefinedObjectType.GROUPMEMBER)
                               .WhereEquals("MemberGroupID", GroupID)
                               .Column("MemberUserID");

            // Hide non-approved group users
            if (HideNonApprovedUsers)
            {
                groupUserIDs.WhereNull("MemberRejectedWhen");
            }

            var usersInGroupCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, groupUserIDs);
            usersWhereCondition.And(usersInGroupCondition);
        }

        // Select users in role
        if (RoleID > 0)
        {
            var usersInRoleIDs = UserRoleInfoProvider
                                 .GetUserRoles()
                                 .WhereEquals("RoleID", RoleID)
                                 .Column("UserID");

            var usersInRoleCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, usersInRoleIDs);
            usersWhereCondition.And(usersInRoleCondition);
        }

        // Select users depending on site; if filter enabled, where condition is added from filter itself
        if (!ShowSiteFilter && (SiteID >= 0) && !DisplayUsersFromAllSites)
        {
            int siteID      = (SiteID == 0) ? SiteContext.CurrentSiteID : SiteID;
            var siteUserIDs = UserSiteInfoProvider
                              .GetUserSites()
                              .WhereEquals("SiteID", siteID)
                              .Column("UserID");

            var siteUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, siteUserIDs);

            if (TreatGlobalAdminsAsSiteUsers)
            {
                siteUsersCondition.Or(GetPrivilegeLevelCondition());
            }

            usersWhereCondition.And(siteUsersCondition);
        }

        if (AlwaysShowGlobalAdministrators)
        {
            // New instance has to be created in order to produce brackets
            usersWhereCondition = new WhereCondition(usersWhereCondition).Or(GetPrivilegeLevelCondition());
        }

        // Add additional users
        if ((AdditionalUsers != null) && (AdditionalUsers.Length > 0))
        {
            var additionalUsersCondition = new WhereCondition().WhereIn(userTypeInfo.IDColumn, AdditionalUsers);

            new WhereCondition(usersWhereCondition).Or(additionalUsersCondition);
        }

        // Control where condition
        if (!String.IsNullOrEmpty(WhereCondition))
        {
            usersWhereCondition = new WhereCondition(usersWhereCondition).And(new WhereCondition(WhereCondition));
        }

        // Append generated where condition
        usUsers.WhereCondition = SqlHelper.AddWhereCondition(usUsers.WhereCondition, usersWhereCondition.ToString(expand: true));

        pnlUpdate.ShowProgress = (SelectionMode == SelectionModeEnum.Multiple);
    }
示例#41
0
 /// <summary>
 /// Returns where condition for a single column. It consider parent product for variants.
 /// </summary>
 /// <param name="column">Column to filter for.</param>
 /// <param name="condition">Condition to restrict.</param>
 private WhereCondition GetColumnWhereCondition(string column, WhereCondition condition)
 {
     return new WhereCondition().Where(condition.Or().WhereNull(column).And().Where(GetParentProductWhereCondition(condition)));
 }
    /// <summary>
    /// Initializes the selector.
    /// </summary>
    public void InitSelector()
    {
        uniSelector.IsLiveSite = IsLiveSite;

        // Set resource prefix if specified
        if (ResourcePrefix != null)
        {
            uniSelector.ResourcePrefix = ResourcePrefix;
        }

        // Initialize selector for on-line marketing
        if (ValidationHelper.GetString(GetValue("mode"), "").ToLowerCSafe() == "onlinemarketing")
        {
            UniSelector.SelectionMode = SelectionModeEnum.MultipleButton;
            UniSelector.OnItemsSelected += UniSelector_OnItemsSelected;
            UniSelector.ReturnColumnName = "CustomerID";
            IsLiveSite = false;
            SiteID = ValidationHelper.GetInteger(GetValue("SiteID"), 0);
            UniSelector.ResourcePrefix = "om.customerselector";
        }

        var where = new WhereCondition();
        // Add registered customers
        if (DisplayRegisteredCustomers)
        {
            where.WhereIn("CustomerUserID", new IDQuery<UserSiteInfo>("UserID").WhereEquals("SiteID", SiteID));
        }

        // Add anonymous customers
        if (DisplayAnonymousCustomers)
        {
            where.Or().Where(w => w.WhereEquals("CustomerSiteID", SiteID).And().WhereNull("CustomerUserID"));
        }

        where = new WhereCondition(where);

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("CustomerEnabled");
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems))
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if (CustomerID > 0)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
    /// <summary>
    /// Creates default where condition for product documents listing.
    /// </summary>
    private WhereCondition GetDocumentWhereCondition()
    {
        var where = new WhereCondition().WhereNotNull("NodeSKUID");
        if (ShowSections)
        {
            where.Or().WhereIn("NodeClassID", new IDQuery<DataClassInfo>("ClassID").WhereTrue("ClassIsProductSection"));
        }

        // Prepare site condition
        var siteWhere = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);
        if (AllowGlobalObjects)
        {
            siteWhere.Or().WhereNull("SKUSiteID");
        }
        else if (ShowSections)
        {
            siteWhere.Or().Where(w => w.WhereNull("SKUSiteID").And().WhereNull("SKUID"));
        }

        // Combine where conditions
        where.Where(siteWhere);
        if (docList.Node != null)
        {
            string path = docList.Node.NodeAliasPath ?? "";

            where.WhereStartsWith("NodeAliasPath", path);
        }

        return where;
    }
示例#44
0
 /// <summary>
 /// Returns where condition for a single column. It consider parent product for variants.
 /// </summary>
 /// <param name="column">Column to filter for.</param>
 /// <param name="condition">Condition to restrict.</param>
 private WhereCondition GetColumnWhereCondition(string column, WhereCondition condition)
 {
     return(new WhereCondition().Where(condition.Or().WhereNull(column).And().Where(GetParentProductWhereCondition(condition))));
 }