Ejemplo n.º 1
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);
    }
    /// <summary>
    /// Returns WHERE condition when libraries are being displayed. Sets also group identifier if specified
    /// </summary>
    private string GetDisplayedLibrariesCondition()
    {
        AvailableLibrariesEnum availableLibrariesEnum;

        // Get correct libraries
        availableLibrariesEnum = GlobalLibraries;
        string libraryName = GlobalLibraryName;

        var condition = new WhereCondition();

        switch (availableLibrariesEnum)
        {
        case AvailableLibrariesEnum.OnlySingleLibrary:
            librarySelector.SiteID = SiteID;
            return(condition.WhereEquals("LibraryName", libraryName).ToString(true));

        case AvailableLibrariesEnum.OnlyCurrentLibrary:
            int libraryId = (MediaLibraryContext.CurrentMediaLibrary != null) ? MediaLibraryContext.CurrentMediaLibrary.LibraryID : 0;
            return(condition.WhereEquals("LibraryID", libraryId).ToString(true));

        case AvailableLibrariesEnum.None:
            return(condition.NoResults().ToString(true));

        default:
            librarySelector.SiteID = SiteID;
            return(String.Empty);
        }
    }
    /// <summary>
    /// Gets WHERE condition to retrieve available sites according specified type.
    /// </summary>
    private string GetSitesWhere()
    {
        WhereCondition condition = new WhereCondition().WhereEquals("SiteStatus", SiteStatusEnum.Running.ToStringRepresentation());

        // If not global admin display only related sites
        if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator)
        {
            condition.WhereIn("SiteID", new IDQuery <UserSiteInfo>(UserSiteInfo.TYPEINFO.SiteIDColumn)
                              .WhereEquals("UserID", MembershipContext.AuthenticatedUser.UserID));
        }

        switch (Sites)
        {
        case AvailableSitesEnum.OnlySingleSite:
            if (!string.IsNullOrEmpty(SelectedSiteName))
            {
                condition.WhereEquals("SiteName", SelectedSiteName);
            }
            break;

        case AvailableSitesEnum.OnlyCurrentSite:
            condition.WhereEquals("SiteName", SiteContext.CurrentSiteName);
            break;
        }

        return(condition.ToString(true));
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    /// <param name="reloadUniSelector">If true, UniSelector is also reloaded</param>
    public void ReloadData(bool reloadUniSelector = false)
    {
        uniSelector.IsLiveSite = IsLiveSite;
        var where = new WhereCondition();

        if (OnlyDocumentTypes)
        {
            where.WhereEquals("ClassIsDocumentType", 1);
        }
        else if (OnlyCustomTables)
        {
            where.WhereEquals("ClassIsCustomTable", 1);
        }

        if (mSiteId != null)
        {
            where.WhereIn("ClassID", ClassSiteInfo.Provider.Get().Column("ClassID").WhereEquals("SiteID", mSiteId));
        }

        // Combine default where condition with external
        if (!String.IsNullOrEmpty(WhereCondition))
        {
            where.Where(WhereCondition);
        }

        uniSelector.WhereCondition = where.ToString(true);

        if (reloadUniSelector)
        {
            uniSelector.Reload(true);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Creates filter condition and raise filter change event.
    /// </summary>
    private void FilterData()
    {
        WhereCondition where = new WhereCondition();
        int    paging = 0;
        string order  = string.Empty;

        // Build where condition according to drop-downs settings
        if (statusSelector.SelectedID > 0)
        {
            where.WhereEquals("SKUPublicStatusID", statusSelector.SelectedID);
        }

        if (manufacturerSelector.SelectedID > 0)
        {
            where.WhereEquals("SKUManufacturerID", manufacturerSelector.SelectedID);
        }

        if (chkStock.Checked)
        {
            where.Where(w => w.WhereNull("SKUTrackInventory")
                        .Or()
                        .WhereGreaterThan("SKUAvailableItems", 0)
                        .Or()
                        .WhereIn("SKUID", new IDQuery <SKUInfo>("SKUParentSKUID").WhereGreaterThan("SKUAvailableItems", 0)));
        }

        if (!string.IsNullOrEmpty(txtSearch.Text))
        {
            where.WhereContains("SKUName", txtSearch.Text);
        }

        // Process drpSort drop-down
        if (ValidationHelper.GetInteger(drpPaging.SelectedValue, 0) > 0)
        {
            paging = ValidationHelper.GetInteger(drpPaging.SelectedValue, 0);
        }

        if (!string.IsNullOrEmpty(drpSort.SelectedValue))
        {
            order = drpSort.SelectedValue;
        }

        // Set where condition
        WhereCondition = where.ToString(true);

        if (paging > 0)
        {
            // Set paging
            PageSize = paging;
        }

        if (!string.IsNullOrEmpty(order))
        {
            // Set sorting
            OrderBy = GetOrderBy(order);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Returns complete WHERE condition.
    /// </summary>
    protected WhereCondition GetCompleteWhereCondition()
    {
        var allRecords = UniSelector.US_ALL_RECORDS.ToString();

        var customWhere = ValidationHelper.GetString(GetValue("WhereCondition"), "");

        var where = new WhereCondition();

        // Do not select product options and select only enabled products
        where.WhereNull("SKUOptionCategoryID")
        .WhereTrue("SKUEnabled");

        // Get products only with specified public status
        if (!String.IsNullOrEmpty(ProductPublicStatusName) && (ProductPublicStatusName != allRecords))
        {
            var pStatusSiteID = ECommerceSettings.UseGlobalPublicStatus(SiteName) ? 0 : SiteInfoProvider.GetSiteID(SiteName);
            where.WhereEquals("SKUPublicStatusID",
                              new IDQuery <PublicStatusInfo>("PublicStatusID")
                              .WhereEquals("PublicStatusSiteID".AsColumn().IsNull(0), pStatusSiteID)
                              .WhereEquals("PublicStatusName", ProductPublicStatusName)
                              .TopN(1)
                              );
        }

        // Get products only with specified internal status
        if (!String.IsNullOrEmpty(ProductInternalStatusName) && (ProductInternalStatusName != allRecords))
        {
            var iStatusSiteID = ECommerceSettings.UseGlobalInternalStatus(SiteName) ? 0 : SiteInfoProvider.GetSiteID(SiteName);
            where.WhereEquals("SKUInternalStatusID",
                              new IDQuery <InternalStatusInfo>("InternalStatusID")
                              .WhereEquals("InternalStatusSiteID".AsColumn().IsNull(0), iStatusSiteID)
                              .WhereEquals("InternalStatusName", ProductInternalStatusName)
                              .TopN(1)
                              );
        }

        // Get products only from specified department
        if (!String.IsNullOrEmpty(ProductDepartmentName) && (ProductDepartmentName != allRecords))
        {
            var dept = DepartmentInfoProvider.GetDepartmentInfo(ProductDepartmentName, SiteName);

            var departmentID = (dept != null) ? dept.DepartmentID : 0;
            where.WhereEquals("SKUDepartmentID", departmentID);
        }

        // Include user custom WHERE condition
        if (customWhere.Trim() != "")
        {
            where.Where(customWhere);
        }

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

        switch (EmailFeedSelection)
        {
        case "newsletters":
            whereCondition.WhereEquals("NewsletterType", (int)EmailCommunicationTypeEnum.Newsletter);
            break;

        case "emailCampaigns":
            whereCondition.WhereEquals("NewsletterType", (int)EmailCommunicationTypeEnum.EmailCampaign);
            break;
        }
        return(whereCondition);
    }
    /// <summary>
    /// Get where condition for unigrid
    /// </summary>
    /// <returns>Where condition</returns>
    private WhereCondition GetWhereCondition()
    {
        string productNameFilter = txtProductName.Text;
        string productCodeFilter = txtProductCode.Text;

        // To display ONLY product - not product options
        var where = new WhereCondition().WhereTrue("SKUEnabled").And().WhereNull("SKUOptionCategoryID");

        if (!string.IsNullOrEmpty(productNameFilter))
        {
            // Condition to get also products with variants that contains
            where.Where(w => w.WhereContains("SKUName", productNameFilter)
                        .Or()
                        .WhereIn("SKUID", new IDQuery <SKUInfo>("SKUParentSKUID").WhereContains("SKUName", productNameFilter)));
        }
        if (productCodeFilter != "")
        {
            // Condition to get also products with variants that contains
            where.Where(w => w.WhereContains("SKUNumber", productCodeFilter).Or().WhereIn("SKUID", new IDQuery <SKUInfo>("SKUParentSKUID").WhereContains("SKUNumber", productCodeFilter)));
        }
        if (departmentElem.SelectedID > 0)
        {
            where.WhereEquals("SKUDepartmentID", departmentElem.SelectedID);
        }

        where.Where(SKUInfoProvider.ProviderObject.AddSiteWhereCondition(string.Empty, SiteContext.CurrentSiteID, ECommerceSettings.ALLOW_GLOBAL_PRODUCTS, true));

        return(where);
    }
        public WhereCondition GetWhereCondition()
        {
            var where = new WhereCondition();

            if (DisplayFilterPacks() && !DisplayTablewares())
            {
                where.WhereEquals("ClassName", FilterPack.CLASS_NAME);
            }

            if (!DisplayFilterPacks() && DisplayTablewares())
            {
                where.WhereEquals("ClassName", Tableware.CLASS_NAME);
            }

            return(where);
        }
    /// <summary>
    /// Gets where condition based on value of given controls.
    /// </summary>
    /// <param name="where">Where condition</param>
    /// <param name="column">Column to compare</param>
    /// <param name="drpOperator">List control with operator</param>
    /// <param name="valueBox">Text control with value</param>
    /// <returns>Where condition for outdated documents</returns>
    private void AddOutdatedWhereCondition(WhereCondition where, string column, ListControl drpOperator, ITextControl valueBox)
    {
        var value = TextHelper.LimitLength(valueBox.Text, 100);

        if (!String.IsNullOrEmpty(value))
        {
            string condition = drpOperator.SelectedValue;

            // Create condition based on operator
            switch (condition)
            {
            case WhereBuilder.LIKE:
                where.WhereContains(column, value);
                break;

            case WhereBuilder.NOT_LIKE:
                where.WhereNotContains(column, value);
                break;

            case WhereBuilder.EQUAL:
                where.WhereEquals(column, value);
                break;

            case WhereBuilder.NOT_EQUAL:
                where.WhereNotEquals(column, value);
                break;
            }
        }
    }
    /// <summary>
    /// Generates complete filter where condition.
    /// </summary>
    private string GenerateWhereCondition()
    {
        var whereCondition = new WhereCondition();

        // Create WHERE condition for basic filter
        int contactStatus = ValidationHelper.GetInteger(fltAccountStatus.Value, -1);

        if (fltAccountStatus.Value == null)
        {
            whereCondition = whereCondition.WhereNull("AccountStatusID");
        }
        else if (contactStatus > 0)
        {
            whereCondition = whereCondition.WhereEquals("AccountStatusID", contactStatus);
        }

        whereCondition = whereCondition
                         .Where(fltName.GetCondition())
                         .Where(fltEmail.GetCondition())
                         .Where(fltContactName.GetCondition());

        if (IsAdvancedMode)
        {
            whereCondition = whereCondition
                             .Where(fltCity.GetCondition())
                             .Where(fltPhone.GetCondition())
                             .Where(fltCreated.GetCondition())
                             .Where(GetOwnerCondition(fltOwner))
                             .Where(GetCountryCondition(fltCountry))
                             .Where(GetStateCondition(fltState));
        }

        return(whereCondition.ToString(true));
    }
    /// <summary>
    /// Returns WHERE condition when libraries are being displayed. Sets also group identifier if specified
    /// </summary>
    private string GetDisplayedLibrariesCondition()
    {
        AvailableLibrariesEnum availableLibrariesEnum;
        string libraryName = String.Empty;

        // Get correct libraries
        if (SelectedGroupID != 0)
        {
            availableLibrariesEnum = GroupLibraries;

            if (groupsSelector != null)
            {
                // Get currently selected group ID
                int groupId = ValidationHelper.GetInteger(groupsSelector.GetValue("GroupID"), 0);
                if (groupId > 0)
                {
                    librarySelector.GroupID = groupId;
                    libraryName             = GroupLibraryName;
                }
            }
        }
        else
        {
            availableLibrariesEnum = GlobalLibraries;
            libraryName            = GlobalLibraryName;
        }

        var condition = new WhereCondition();

        switch (availableLibrariesEnum)
        {
        case AvailableLibrariesEnum.OnlySingleLibrary:
            librarySelector.SiteID = SiteID;
            return(condition.WhereEquals("LibraryName", libraryName).ToString(true));

        case AvailableLibrariesEnum.OnlyCurrentLibrary:
            int libraryId = (MediaLibraryContext.CurrentMediaLibrary != null) ? MediaLibraryContext.CurrentMediaLibrary.LibraryID : 0;
            return(condition.WhereEquals("LibraryID", libraryId).ToString(true));

        case AvailableLibrariesEnum.None:
            return(condition.NoResults().ToString(true));

        default:
            librarySelector.SiteID = SiteID;
            return(String.Empty);
        }
    }
    private string CreateWhereCondition(string originalWhere)
    {
        var where = new WhereCondition();
        where.Where(new WhereCondition(originalWhere)
        {
            WhereIsComplex = true
        });

        // Add where conditions from filters
        where.Where(new WhereCondition(nameFilter.WhereCondition)
        {
            WhereIsComplex = true
        });

        string objType = ValidationHelper.GetString(objTypeSelector.Value, "");

        if (!String.IsNullOrEmpty(objType))
        {
#pragma warning disable BH2000 // Method 'WhereLike()' or 'WhereNotLike()' should not be used used.
            where.WhereLike("VersionObjectType", objType);
#pragma warning restore BH2000 // Method 'WhereLike()' or 'WhereNotLike()' should not be used used.
        }

        int userId = ValidationHelper.GetInteger(userSelector.Value, 0);
        if (userId > 0)
        {
            where.WhereEquals("VersionDeletedByUserID", userId);
        }

        // Get older than value
        if (DisplayDateTimeFilter)
        {
            DateTime olderThan     = DateTime.Now.Date.AddDays(1);
            int      dateTimeValue = ValidationHelper.GetInteger(txtFilter.Text, 0);

            switch (drpFilter.SelectedIndex)
            {
            case 0:
                olderThan = olderThan.AddDays(-dateTimeValue);
                break;

            case 1:
                olderThan = olderThan.AddDays(-dateTimeValue * 7);
                break;

            case 2:
                olderThan = olderThan.AddMonths(-dateTimeValue);
                break;

            case 3:
                olderThan = olderThan.AddYears(-dateTimeValue);
                break;
            }

            where.WhereLessOrEquals("VersionDeletedWhen", olderThan);
        }

        return(where.ToString(true));
    }
Ejemplo n.º 14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var whereCondition = new WhereCondition(gridElem.WhereCondition);

        if (ContactID != null)
        {
            whereCondition.WhereEquals("ContactID", ContactID);
        }
        if (SiteID != null)
        {
            whereCondition.WhereEquals("ScoreSiteID", SiteID);
        }

        gridElem.WhereCondition = whereCondition.ToString(true);

        gridElem.OnExternalDataBound += gridElem_OnExternalDataBound;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var whereCondition = new WhereCondition(gridElem.WhereCondition);

        if (ContactID != null)
        {
            whereCondition.WhereEquals("ContactID", ContactID);
        }
        if (SiteID != null)
        {
            whereCondition.WhereEquals("ScoreSiteID", SiteID);
        }

        gridElem.WhereCondition = whereCondition.ToString(true);

        gridElem.OnExternalDataBound += gridElem_OnExternalDataBound;
    }
Ejemplo n.º 16
0
        public WhereCondition  GetWhereCondition()
        {
            var where = new WhereCondition()
                        .And(GetManufacturerWhereCondition())
                        .And(GetPriceWhereCondition());

            if (grinderFilter.DisplayElectricGrinders() && !grinderFilter.DisplayManualGrinders())
            {
                where = where.WhereEquals("ClassName", ElectricGrinder.CLASS_NAME);
            }

            if (!grinderFilter.DisplayElectricGrinders() && grinderFilter.DisplayManualGrinders())
            {
                where = where.WhereEquals("ClassName", ManualGrinder.CLASS_NAME);
            }

            return(where);
        }
Ejemplo n.º 17
0
    /// <summary>
    /// Adds account lock condition to given <paramref name="whereCondition"/> when necessary.
    /// </summary>
    private void AddAccountLockCondition(WhereCondition whereCondition)
    {
        if (!DisplayUserEnabled)
        {
            return;
        }

        if (chkEnabled.Checked)
        {
            whereCondition.WhereEquals("UserEnabled", 0);

            int lockReason = ValidationHelper.GetInteger(drpLockReason.SelectedValue, -1);
            if (lockReason >= 0)
            {
                whereCondition.WhereEquals("ISNULL(UserAccountLockReason, 0)", lockReason);
            }
        }
    }
    /// <summary>
    /// Gets where condition for selecting relationship names
    /// </summary>
    private WhereCondition GetRelationshipNameCondition()
    {
        var relationshipNameCondition = new WhereCondition();

        if (!UseAdHocRelationshipName)
        {
            relationshipNameCondition.Where(new WhereCondition().WhereFalse("RelationshipNameIsAdHoc").Or().WhereNull("RelationshipNameIsAdHoc"));

            if (!String.IsNullOrEmpty(RelationshipName))
            {
                relationshipNameCondition.WhereEquals("RelationshipName", RelationshipName);
            }
        }
        else
        {
            relationshipNameCondition.WhereEquals("RelationshipName", AdHocRelationshipName);
        }

        return(relationshipNameCondition);
    }
    /// <summary>
    /// Gets where condition for selecting relationship names
    /// </summary>
    private WhereCondition GetRelationshipNameCondition()
    {
        var relationshipNameCondition = new WhereCondition();

        if (!UseAdHocRelationshipName)
        {
            relationshipNameCondition.Where(new WhereCondition().WhereFalse("RelationshipNameIsAdHoc").Or().WhereNull("RelationshipNameIsAdHoc"));
        }

        relationshipNameCondition.WhereEquals("RelationshipName", RelationshipName);

        return(relationshipNameCondition);
    }
Ejemplo n.º 20
0
    /// <summary>
    /// Adds condition based on privilege level dropdown to given <paramref name="whereCondition"/>.
    /// </summary>
    /// <remarks>Logic in this method mirrors <see cref="UserInfo.SiteIndependentPrivilegeLevel"/> behavior to get correct condition.</remarks>
    private void AddPrivilegeLevelCondition(WhereCondition whereCondition)
    {
        string drpPrivilegeSelectedItemValue = drpPrivilege.SelectedItem.Value;

        if (drpPrivilegeSelectedItemValue == UniGrid.ALL)
        {
            return;
        }

        var privilegeLevel = drpPrivilegeSelectedItemValue.ToInteger(0);

        whereCondition.WhereEquals("UserPrivilegeLevel", privilegeLevel);
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        gridElem.EditActionUrl = "Edit.aspx?variantid={0}&nodeid=" + NodeID;
        gridElem.ZeroRowsText  = GetString("contentvariant.nodata");

        // Grid initialization
        gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction);

        // If not set, get the page template id for the current node and its document template
        if ((PageTemplateID <= 0) && (Node != null))
        {
            PageTemplateID = Node.GetUsedPageTemplateId();
        }

        // Build where condition
        var where = new WhereCondition().WhereEquals("VariantPageTemplateID", PageTemplateID);

        // Display only variants for the current document
        if (Node != null)
        {
            where.WhereEqualsOrNull("VariantDocumentID", Node.DocumentID);
        }

        // Display variants just for a specific zone/webpart/widget
        if (!string.IsNullOrEmpty(ZoneID))
        {
            where.WhereEquals("VariantZoneID", ZoneID);

            if (InstanceGUID != Guid.Empty)
            {
                // Web part/widget condition
                where.WhereEquals("VariantInstanceGUID", InstanceGUID);
            }
        }

        gridElem.WhereCondition = where.ToString(expand: true);
    }
Ejemplo n.º 22
0
    /// <summary>
    /// Gets where condition for selecting relationship names
    /// </summary>
    private WhereCondition GetRelationshipNameCondition()
    {
        var relationshipNameCondition = new WhereCondition();

        if (!UseAdHocRelationshipName)
        {
            relationshipNameCondition.Where(new WhereCondition());

            if (!String.IsNullOrEmpty(RelationshipName))
            {
                relationshipNameCondition.WhereEquals("RelationshipName", RelationshipName);
            }
        }

        return(relationshipNameCondition);
    }
    /// <summary>
    /// Returns where condition.
    /// </summary>
    /// <param name="customWhere">Custom WHERE condition</param>
    private WhereCondition GetWhereCondition(string customWhere)
    {
        SiteInfo si;

        var where = new WhereCondition();

        // Get required site data
        if (!String.IsNullOrEmpty(SiteName))
        {
            si = SiteInfoProvider.GetSiteInfo(SiteName);
        }
        else
        {
            si = SiteContext.CurrentSite;
        }

        if (si != null)
        {
            // Build where condition
            var classWhere = new WhereCondition();

            // Get documents of the specified class only - without coupled data !!!
            if (!String.IsNullOrEmpty(ClassNames))
            {
                string[] classNames = ClassNames.Trim(';').Split(';');
                foreach (string className in classNames)
                {
                    classWhere.WhereEquals("ClassName", className).Or();
                }
            }

            where.WhereIn("NodeSKUID", new IDQuery <OrderItemInfo>("OrderItemSKUID").Source(s => s.Join <SKUInfo>("OrderItemSKUID", "SKUID")
                                                                                            .Join <OrderInfo>("COM_OrderItem.OrderItemOrderID", "OrderID"))
                          .WhereTrue("SKUEnabled")
                          .WhereNull("SKUOptionCategoryID")
                          .WhereEquals("OrderSiteID", si.SiteID)
                          .Where(classWhere));

            // Add custom WHERE condition
            if (!String.IsNullOrEmpty(customWhere))
            {
                where.Where(customWhere);
            }
        }

        return(where);
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Returns <see cref="WhereCondition"/> for filtering site roles.
    /// </summary>
    /// <param name="roles">Role names</param>
    private WhereCondition GetSiteRolesCondition(string[] roles)
    {
        var siteRolesCondition = new WhereCondition();
        var siteRoles          = roles.Where(item => !item.StartsWith(".", StringComparison.OrdinalIgnoreCase)).ToArray();

        if (!siteRoles.Any())
        {
            return(siteRolesCondition);
        }

        if (SelectedSite > 0)
        {
            siteRolesCondition.WhereEquals("SiteID", SelectedSite);
        }

        return(siteRolesCondition.WhereIn("RoleName", siteRoles));
    }
Ejemplo n.º 25
0
    /// <summary>
    /// Appends given selector filter to given <paramref name="whereCondition"/> accordingly to filter state.
    /// </summary>
    private void AppendSelectorFilter(FormEngineUserControl selector, string selectingColumn, WhereCondition whereCondition)
    {
        if (!selector.HasValue)
        {
            return;
        }

        var value = ValidationHelper.GetInteger(selector.Value, UniSelector.US_NONE_RECORD);

        if (value == UniSelector.US_NONE_RECORD)
        {
            whereCondition.WhereNull(selectingColumn);
        }
        else if (value != UniSelector.US_ALL_RECORDS)
        {
            whereCondition.WhereEquals(selectingColumn, value);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check hash
        if (!QueryHelper.ValidateHash("hash"))
        {
            URLHelper.Redirect(AdministrationUrlHelper.GetErrorPageUrl("dialogs.badhashtitle", "dialogs.badhashtext", true));
        }
        else
        {
            string element = QueryHelper.GetString("tasktype", null);

            // Check UI permissions for Staging
            var user = MembershipContext.AuthenticatedUser;
            if (!user.IsAuthorizedPerUIElement("cms.staging", element))
            {
                RedirectToUIElementAccessDenied("cms.staging", element);
            }

            // Check 'Manage XXX tasks' permission
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.staging", "Manage" + element + "Tasks"))
            {
                RedirectToAccessDenied("cms.staging", "Manage" + element + "Tasks");
            }

            // Register modal dialog scripts
            RegisterModalPageScripts();
            PageTitle.TitleText = GetString("Task.LogHeader");

            serverId = QueryHelper.GetInteger("serverid", 0);
            int taskId = QueryHelper.GetInteger("taskid", 0);

            var condition = new WhereCondition().WhereEquals("SynchronizationTaskID", taskId);

            if (serverId > 0)
            {
                condition.WhereEquals("SynchronizationServerID", serverId);
            }

            gridLog.WhereCondition      = condition.ToString(true);
            gridLog.ZeroRowsText        = GetString("Task.LogNoEvents");
            gridLog.OnBeforeDataReload += gridLog_OnBeforeDataReload;
        }
    }
Ejemplo n.º 27
0
    /// <summary>
    /// Loads data into Unigrid.
    /// </summary>
    private void LoadData()
    {
        var whereCondition = new WhereCondition();

        if (!String.IsNullOrEmpty(AliasPath))
        {
            whereCondition.WhereEquals("ABTestOriginalPage", AliasPath);
        }

        DataSet abTests = ABTestInfoProvider.GetABTests().OnSite(SiteContext.CurrentSiteID).Where(whereCondition);

        abTests.Tables[0].Columns.Add("ABTestStatus", typeof(int));

        foreach (DataRow abTestDataRow in abTests.Tables[0].Rows)
        {
            abTestDataRow["ABTestStatus"] = (int)ABTestStatusEvaluator.GetStatus(new ABTestInfo(abTestDataRow));
        }

        gridElem.DataSource = abTests;
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Adds session condition to given <see paramref="whereCondition"/>.
    /// </summary>
    private void AddSessionCondition(WhereCondition whereCondition, int siteID)
    {
        if (siteID > 0)
        {
            whereCondition.WhereEquals("SessionSiteID", siteID);
        }

        if (!DisplayGuests)
        {
            whereCondition.WhereGreaterThan("SessionUserID", 0);
        }

        if (chkDisplayHidden.Visible && !chkDisplayHidden.Checked)
        {
            whereCondition.Where(new WhereCondition()
                                 .WhereEquals("SessionUserIsHidden", 0)
                                 .Or()
                                 .WhereNull("SessionUserID"));
        }
    }
    /// <summary>
    /// Reloads grid.
    /// </summary>
    public void ReloadData()
    {
        WhereCondition where = new WhereCondition();

        if (!String.IsNullOrEmpty(drpCustom.SelectedValue))
        {
            string columnName = Views ? "TABLE_NAME" : "ROUTINE_NAME";
            string prefix     = Views ? "View_Custom_" : "Proc_Custom_";

            switch (drpCustom.SelectedValue)
            {
            case "1":
                where.WhereStartsWith(columnName, prefix);
                break;

            case "0":
                where.WhereNotStartsWith(columnName, prefix);
                break;
            }
        }

        // Filter system views
        if (Views)
        {
            where.WhereNotEquals("TABLE_SCHEMA", "sys");
        }

        where.Where(fltViews.GetCondition());

        TableManager tm = new TableManager(null);

        if (Views)
        {
            gridViews.DataSource = tm.GetList(where.ToString(true), "TABLE_NAME, TABLE_SCHEMA, IsCustom=CASE SUBSTRING(TABLE_NAME,0,13) WHEN 'View_Custom_' THEN 1 ELSE 0 END", true);
        }
        else
        {
            where.WhereEquals("ROUTINE_TYPE", "PROCEDURE");
            gridViews.DataSource = tm.GetList(where.ToString(true), "ROUTINE_NAME, ROUTINE_SCHEMA, IsCustom=CASE SUBSTRING(ROUTINE_NAME,0,13) WHEN 'Proc_Custom_' THEN 1 ELSE 0 END", false);
        }
    }
Ejemplo n.º 30
0
    /// <summary>
    /// Returns site condition for given site id.
    /// </summary>
    /// <param name="siteID">Site id</param>
    private static WhereCondition GetSiteCondition(int siteID)
    {
        var condition = new WhereCondition();

        switch (siteID)
        {
        case UniSelector.US_GLOBAL_RECORD:
            condition.WhereNull("StateSiteID");
            break;

        case UniSelector.US_ALL_RECORDS:
        case UniSelector.US_NONE_RECORD:
            break;

        default:
            condition.WhereEquals("StateSiteID", siteID);
            break;
        }

        return(condition);
    }
Ejemplo n.º 31
0
    private void CreateStagingTasksForScheduledTasks(int objectSiteId, int currentSiteId)
    {
        var where = new WhereCondition().And(new WhereCondition().WhereNull("TaskType").Or().WhereNotEquals("TaskType", (int)ScheduledTaskTypeEnum.System));

        // Synchronize tree root (all objects from current site and all global objects)
        if (objectSiteId < 0)
        {
            where.WhereEqualsOrNull("TaskSiteID", currentSiteId);
        }
        // Synchronize global objects
        else if (objectSiteId == 0)
        {
            where.WhereNull("TaskSiteID");
        }
        // Synchronize site objects
        else
        {
            where.WhereEquals("TaskSiteID", objectSiteId);
        }

        using (new CMSActionContext()
        {
            AllowAsyncActions = false
        })
        {
            var tasks = TaskInfoProvider.GetTasks().Where(where).TypedResult;
            foreach (var task in tasks)
            {
                task.Generalized.StoreSettings();
                task.Generalized.LogSynchronization = SynchronizationTypeEnum.LogSynchronization;
                task.Generalized.LogEvents          = true;

                TaskInfoProvider.SetTaskInfo(task);

                task.Generalized.RestoreSettings();
            }
        }
    }
    /// <summary>
    /// PageLoad event handler.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            UniGridRelationship.StopProcessing = StopProcessing;
        }
        else
        {
            // Set tree node from Form object
            if ((TreeNode == null) && (Form != null) && (Form.EditedObject != null))
            {
                TreeNode node = Form.EditedObject as TreeNode;
                if ((node != null) && (Form.Mode == FormModeEnum.Update))
                {
                    TreeNode = node;
                }
                else
                {
                    ShowError(GetString("relationship.editdocumenterror"));
                }
            }

            if (TreeNode != null)
            {
                // Set unigrid
                UniGridRelationship.OnExternalDataBound += UniGridRelationship_OnExternalDataBound;
                UniGridRelationship.OnBeforeDataReload += UniGridRelationship_OnBeforeDataReload;
                UniGridRelationship.OnAction += UniGridRelationship_OnAction;
                UniGridRelationship.ZeroRowsText = GetString("relationship.nodatafound");
                UniGridRelationship.ShowActionsMenu = !IsLiveSite;

                int nodeId = TreeNode.NodeID;
                bool oneRelationshipName = !string.IsNullOrEmpty(RelationshipName);

                WhereCondition condition = new WhereCondition();

                if (oneRelationshipName)
                {
                    condition.WhereIn("RelationshipNameID", new IDQuery<RelationshipNameInfo>().WhereEquals("RelationshipName", RelationshipName));
                }

                // Switch sides is disabled
                if (!AllowSwitchSides)
                {
                    condition.WhereEquals(DefaultSide ? "RightNodeID" : "LeftNodeID", nodeId);
                }
                else
                {
                    condition.Where(new WhereCondition().WhereEquals("RightNodeID", nodeId).Or().WhereEquals("LeftNodeID", nodeId));
                }

                UniGridRelationship.WhereCondition = condition.ToString(true);

                if (ShowAddRelation)
                {
                    btnNewRelationship.OnClientClick = GetAddRelatedDocumentScript() + " return false;";
                }
                else
                {
                    pnlNewLink.Visible = false;
                }
            }
            else
            {
                UniGridRelationship.StopProcessing = true;
                UniGridRelationship.Visible = false;
                pnlNewLink.Visible = false;
            }

            if (RequestHelper.IsPostBack())
            {
                string target = Request[Page.postEventSourceID];
                if ((target == pnlUpdate.ClientID) || (target == pnlUpdate.UniqueID))
                {
                    string action = Request[Page.postEventArgumentID];

                    if (!string.IsNullOrEmpty(action))
                    {
                        switch (action.ToLowerCSafe())
                        {
                            // Insert from 'Select document' dialog
                            case "insertfromselectdocument":
                                SaveRelationship();
                                break;
                        }
                    }
                }
            }
            else
            {
                bool inserted = QueryHelper.GetBoolean("inserted", false);
                if (inserted)
                {
                    ShowConfirmation(GetString("relationship.wasadded"));
                }
            }
        }
    }
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        // Orders from current site
        var where = new WhereCondition()
            .WhereEquals("OrderSiteID", SiteContext.CurrentSiteID);

        // Order status filter
        var status = OrderStatusInfoProvider.GetOrderStatusInfo(OrderStatus, SiteContext.CurrentSiteName);
        if (status != null)
        {
            where.WhereEquals("OrderStatusID", status.StatusID);
        }

        // Customer or company like filter
        if (!string.IsNullOrEmpty(CustomerOrCompany))
        {
            where.WhereIn("OrderCustomerID", new IDQuery<CustomerInfo>()
                .Where("CustomerFirstName + ' ' + CustomerLastName + ' ' + CustomerFirstName LIKE N'%"+ SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(CustomerOrCompany)) + "%'")
                .Or()
                .WhereContains("CustomerCompany", CustomerOrCompany));
        }

        // Filter for orders with note
        if (HasNote)
        {
            where.WhereNotEmpty("OrderNote");
        }

        // Payment method filter
        var payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(PaymentMethod, SiteContext.CurrentSiteName);
        if (payment != null)
        {
            where.WhereEquals("OrderPaymentOptionID", payment.PaymentOptionID);
        }

        // Payment status filter
        switch (PaymentStatus.ToLowerCSafe())
        {
            case PAY_STATUS_NOT_PAID:
                where.Where(new WhereCondition().WhereFalse("OrderIsPaid").Or().WhereNull("OrderIsPaid"));
                break;

            case PAY_STATUS_PAID:
                where.WhereTrue("OrderIsPaid");
                break;
        }

        // Currency filter
        var currencyObj = CurrencyInfoProvider.GetCurrencyInfo(Currency, SiteContext.CurrentSiteName);
        if (currencyObj != null)
        {
            where.WhereEquals("OrderCurrencyID", currencyObj.CurrencyID);
        }

        // Min price in main currency filter
        if (MinPriceInMainCurrency > 0)
        {
            where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LargerOrEquals, MinPriceInMainCurrency);
        }

        // Max price in main currency filter
        if (MaxPriceInMainCurrency > 0)
        {
            where.Where("OrderTotalPriceInMainCurrency", QueryOperator.LessOrEquals, MaxPriceInMainCurrency);
        }

        // Shipping option filter
        var shipping = ShippingOptionInfoProvider.GetShippingOptionInfo(ShippingOption, SiteContext.CurrentSiteName);
        if (shipping != null)
        {
            where.WhereEquals("OrderShippingOptionID", shipping.ShippingOptionID);
        }

        // Shipping country filter
        if (!string.IsNullOrEmpty(ShippingCountry) && ShippingCountry != "0")
        {
            AddCountryWhereCondition(where);
        }

        // Date filter
        AddDateWhereCondition(where);

        return where;
    }
    /// <summary>
    /// Creates filter condition and raise filter change event.
    /// </summary>
    private void FilterData()
    {
        WhereCondition where = new WhereCondition();
        int paging = 0;
        string order = string.Empty;

        // Build where condition according to drop-downs settings
        if (statusSelector.SelectedID > 0)
        {
            where.WhereEquals("SKUPublicStatusID", statusSelector.SelectedID);
        }

        if (manufacturerSelector.SelectedID > 0)
        {
            where.WhereEquals("SKUManufacturerID", manufacturerSelector.SelectedID);
        }

        if (chkStock.Checked)
        {
            where.Where(w => w.WhereNull("SKUTrackInventory")
                              .Or()
                              .WhereGreaterThan("SKUAvailableItems", 0)
                              .Or()
                              .WhereIn("SKUID", new IDQuery<SKUInfo>("SKUParentSKUID").WhereGreaterThan("SKUAvailableItems", 0)));
        }

        if (!string.IsNullOrEmpty(txtSearch.Text))
        {
            where.WhereContains("SKUName", txtSearch.Text);
        }

        // Process drpSort drop-down
        if (ValidationHelper.GetInteger(drpPaging.SelectedValue, 0) > 0)
        {
            paging = ValidationHelper.GetInteger(drpPaging.SelectedValue, 0);
        }

        if (!string.IsNullOrEmpty(drpSort.SelectedValue))
        {
            order = drpSort.SelectedValue;
        }

        // Set where condition
        WhereCondition = where.ToString(true);

        if (paging > 0)
        {
            // Set paging
            PageSize = paging;
        }

        if (!string.IsNullOrEmpty(order))
        {
            // Set sorting
            OrderBy = GetOrderBy(order);
        }
    }
    /// <summary>
    /// Gets WHERE condition to retrieve available sites according specified type.
    /// </summary>
    private string GetSitesWhere()
    {
        WhereCondition condition = new WhereCondition().WhereEquals("SiteStatus", "RUNNING");

        // If not global admin display only related sites
        if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator)
        {
            condition.WhereIn("SiteID", new IDQuery<UserSiteInfo>(UserSiteInfo.TYPEINFO.SiteIDColumn)
                                                    .WhereEquals("UserID", MembershipContext.AuthenticatedUser.UserID));
        }

        switch (Sites)
        {
            case AvailableSitesEnum.OnlySingleSite:
                if (!string.IsNullOrEmpty(SelectedSiteName))
                {
                    condition.WhereEquals("SiteName", SelectedSiteName);
                }
                break;

            case AvailableSitesEnum.OnlyCurrentSite:
                condition.WhereEquals("SiteName", SiteContext.CurrentSiteName);
                break;
        }

        return condition.ToString(true);
    }
Ejemplo n.º 36
0
    /// <summary>
    /// Generates complete filter where condition.
    /// </summary>    
    private string GenerateWhereCondition()
    {
        var whereCondition = new WhereCondition();

        // Create WHERE condition for basic filter
        int contactStatus = ValidationHelper.GetInteger(fltAccountStatus.Value, -1);
        if (fltAccountStatus.Value == null)
        {
            whereCondition = whereCondition.WhereNull("AccountStatusID");
        }
        else if (contactStatus > 0)
        {
            whereCondition = whereCondition.WhereEquals("AccountStatusID", contactStatus);
        }

        whereCondition = whereCondition
            .Where(fltName.GetCondition())
            .Where(fltEmail.GetCondition())
            .Where(fltContactName.GetCondition());

        if (IsAdvancedMode)
        {
            whereCondition = whereCondition
                .Where(fltCity.GetCondition())
                .Where(fltPhone.GetCondition())
                .Where(fltCreated.GetCondition())
                .Where(GetOwnerCondition(fltOwner))
                .Where(GetCountryCondition(fltCountry))
                .Where(GetStateCondition(fltState));
        }

        // When "merged/not merged" filter is hidden
        if ((HideMergedFilter && NotMerged) ||
            (IsAdvancedMode && !HideMergedFilter && !chkMerged.Checked) ||
            (!IsAdvancedMode && !HideMergedFilter && !NotMerged))
        {
            whereCondition = whereCondition
               .Where(
                   new WhereCondition(
                       new WhereCondition()
                           .WhereNull("AccountMergedWithAccountID")
                           .WhereGreaterOrEquals("AccountSiteID", 0)
                       )
                       .Or(
                           new WhereCondition()
                               .WhereNull("AccountGlobalAccountID")
                               .WhereNull("AccountSiteID")
                       ));
        }

        // Hide accounts merged into global account when displaying list of available accounts for global account
        if (HideMergedIntoGlobal)
        {
            whereCondition = whereCondition.WhereNull("AccountGlobalAccountID");
        }

        if (!DisableGeneratingSiteClause)
        {
            // Filter current account's site
            if (!plcSite.Visible)
            {
                // Filter site objects
                if (SiteID > 0)
                {
                    whereCondition = whereCondition.WhereEquals("AccountSiteID", SiteID);
                }
                // Filter only global objects
                else if (SiteID == UniSelector.US_GLOBAL_RECORD)
                {
                    whereCondition = whereCondition.WhereNull("AccountSiteID");
                }
            }
            // Filter by site filter
            else
            {
                // Only global objects
                if (SelectedSiteID == UniSelector.US_GLOBAL_RECORD)
                {
                    whereCondition = whereCondition.WhereNull("AccountSiteID");
                }
                // Global and site objects
                else if (SelectedSiteID == UniSelector.US_GLOBAL_AND_SITE_RECORD)
                {
                    whereCondition = whereCondition.WhereEqualsOrNull("AccountSiteID", SiteContext.CurrentSiteID);
                }
                // Site objects
                else if (SelectedSiteID != UniSelector.US_ALL_RECORDS)
                {
                    whereCondition = whereCondition.WhereEquals("AccountSiteID", mSelectedSiteID);
                }
            }
        }

        return whereCondition.ToString(true);
    }
Ejemplo n.º 37
0
    /// <summary>
    /// Generates complete filter where condition.
    /// </summary>    
    private string GenerateWhereCondition()
    {
        var whereCondition = new WhereCondition();

        // Create WHERE condition for basic filter
        int contactStatus = ValidationHelper.GetInteger(fltContactStatus.Value, -1);
        if (fltContactStatus.Value == null)
        {
            whereCondition = whereCondition.WhereNull("ContactStatusID");
        }
        else if (contactStatus > 0)
        {
            whereCondition = whereCondition.WhereEquals("ContactStatusID", contactStatus);
        }

        whereCondition = whereCondition
            .Where(fltFirstName.GetCondition())
            .Where(fltLastName.GetCondition())
            .Where(fltEmail.GetCondition());

        // Only monitored contacts
        if (radMonitored.SelectedIndex == 1)
        {
            whereCondition = whereCondition.WhereTrue("ContactMonitored");
        }
        // Only not monitored contacts
        else if (radMonitored.SelectedIndex == 2)
        {
            whereCondition = whereCondition.WhereEqualsOrNull("ContactMonitored", 0);
        }

        // Only contacts that were replicated to SalesForce leads
        if (radSalesForceLeadReplicationStatus.SelectedIndex == 1)
        {
            whereCondition = whereCondition.WhereNotNull("ContactSalesForceLeadID");
        }
        // Only contacts that were not replicated to SalesForce leads
        else if (radSalesForceLeadReplicationStatus.SelectedIndex == 2)
        {
            whereCondition = whereCondition.WhereNull("ContactSalesForceLeadID");
        }

        // Create WHERE condition for advanced filter (id needed)
        if (IsAdvancedMode)
        {
            whereCondition = whereCondition
               .Where(fltMiddleName.GetCondition())
               .Where(fltCity.GetCondition())
               .Where(fltPhone.GetCondition())
               .Where(fltCreated.GetCondition())
               .Where(GetOwnerCondition(fltOwner))
               .Where(GetCountryCondition(fltCountry))
               .Where(GetStateCondition(fltState));

            if (!String.IsNullOrEmpty(txtIP.Text))
            {
                var nestedIpQuery = IPInfoProvider.GetIps().WhereLike("IPAddress", SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(txtIP.Text)));

                whereCondition = whereCondition.WhereIn("ContactID", nestedIpQuery.Column("IPOriginalContactID")).Or().WhereIn("ContactID", nestedIpQuery.Column("IPActiveContactID"));
            }
        }

        // When "merged/not merged" filter is hidden or in advanced mode display contacts according to filter or in basic mode don't display merged contacts
        if ((HideMergedFilter && NotMerged) ||
            (IsAdvancedMode && !HideMergedFilter && !chkMerged.Checked) ||
            (!HideMergedFilter && !NotMerged && !IsAdvancedMode))
        {
            whereCondition = whereCondition
                .Where(
                    new WhereCondition(
                        new WhereCondition()
                            .WhereNull("ContactMergedWithContactID")
                            .WhereGreaterOrEquals("ContactSiteID", 0)
                        )
                        .Or(
                            new WhereCondition()
                                .WhereNull("ContactGlobalContactID")
                                .WhereNull("ContactSiteID")
                        ));
        }

        // Hide contacts merged into global contact when displaying list of available contacts for global contact
        if (HideMergedIntoGlobal)
        {
            whereCondition = whereCondition.WhereNull("ContactGlobalContactID");
        }

        if (!DisableGeneratingSiteClause)
        {
            // Filter by site
            if (!plcSite.Visible)
            {
                // Filter site objects
                if (SiteID > 0)
                {
                    whereCondition = whereCondition.WhereEquals("ContactSiteID", SiteID);
                }
                // Filter only global objects
                else if (SiteID == UniSelector.US_GLOBAL_RECORD)
                {
                    whereCondition = whereCondition.WhereNull("ContactSiteID");
                }
            }
            // Filter by site filter
            else
            {
                // Only global objects
                if (SelectedSiteID == UniSelector.US_GLOBAL_RECORD)
                {
                    whereCondition = whereCondition.WhereNull("ContactSiteID");
                }
                // Global and site objects
                else if (SelectedSiteID == UniSelector.US_GLOBAL_AND_SITE_RECORD)
                {
                    whereCondition = whereCondition.WhereEqualsOrNull("ContactSiteID", SiteContext.CurrentSiteID);
                }
                // Site objects
                else if (SelectedSiteID != UniSelector.US_ALL_RECORDS)
                {
                    whereCondition = whereCondition.WhereEquals("ContactSiteID", mSelectedSiteID);
                }
            }
        }

        return whereCondition.ToString(true);
    }
    /// <summary>
    /// Builds a SQL condition for filtering the order list, and returns it.
    /// </summary>
    /// <returns>A SQL condition for filtering the order list.</returns>
    private WhereCondition GetFilterWhereCondition()
    {
        var condition = new WhereCondition();

        // Order status
        if (statusSelector.SelectedID > 0)
        {
            condition.WhereEquals("OrderStatusID", statusSelector.SelectedID);
        }

        // Order site
        if (FilterSiteID > 0)
        {
            condition.WhereEquals("OrderSiteID", FilterSiteID);
        }

        // Order identifier
        string filterOrderId = txtOrderId.Text.Trim().Truncate(txtOrderId.MaxLength);
        if (filterOrderId != String.Empty)
        {
            int orderId = ValidationHelper.GetInteger(filterOrderId, 0);
            // Include also an invoice number
            condition.Where(w => w.WhereEquals("OrderID", orderId).Or().WhereContains("OrderInvoiceNumber", filterOrderId));
        }

        // Customer's properties, applicable only if a valid customer is not specified
        if (CustomerFilterEnabled)
        {
            // First, Last name and Company search
            string customerNameOrCompany = txtCustomerNameOrCompany.Text.Trim().Truncate(txtCustomerNameOrCompany.MaxLength);
            if (customerNameOrCompany != String.Empty)
            {
                condition.WhereIn("OrderCustomerID", new IDQuery<CustomerInfo>("CustomerID").WhereContains("CustomerFirstName", customerNameOrCompany)
                                                                                .Or()
                                                                                .WhereContains("CustomerLastName", customerNameOrCompany)
                                                                                .Or()
                                                                                .WhereContains("CustomerCompany", customerNameOrCompany));
            }
        }

        // Order is paid
        switch (drpOrderIsPaid.SelectedValue)
        {
            case "0":
                condition.Where("ISNULL(OrderIsPaid, 0) = 0");
                break;
            case "1":
                condition.Where("ISNULL(OrderIsPaid, 0) = 1");
                break;
        }

        // Advanced Filter
        if (AdvancedFilterEnabled)
        {
            // Specific currency was selected
            if (CurrencySelector.SelectedID > 0)
            {
                condition.WhereEquals("OrderCurrencyID", CurrencySelector.SelectedID);
            }

            // Specific payment method was selected
            if (PaymentSelector.SelectedID > 0)
            {
                condition.WhereEquals("OrderPaymentOptionID", PaymentSelector.SelectedID);
            }

            // Specific shipping option was selected
            if (ShippingSelector.SelectedID > 0)
            {
                condition.WhereEquals("OrderShippingOptionID", ShippingSelector.SelectedID);
            }

            // Specific tracking number was provided
            var trackingNumber = txtTrackingNumber.Text.Truncate(txtTrackingNumber.MaxLength);
            if (trackingNumber != string.Empty)
            {
                condition.WhereContains("OrderTrackingNumber", trackingNumber);
            }

            // Specific created date was selected
            if ((dtpCreatedTo.SelectedDateTime < dtpCreatedTo.MaxDate) && (dtpCreatedTo.SelectedDateTime > dtpCreatedTo.MinDate))
            {
                condition.WhereLessOrEquals("OrderDate", dtpCreatedTo.SelectedDateTime);
            }

            // Specific from date was selected
            if ((dtpFrom.SelectedDateTime < dtpFrom.MaxDate) && (dtpFrom.SelectedDateTime > dtpFrom.MinDate))
            {
                condition.WhereGreaterOrEquals("OrderDate", dtpFrom.SelectedDateTime);
            }
        }

        return condition;
    }
    /// <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>
    /// Gets all child nodes in the specified parent path.
    /// </summary>
    /// <param name="searchText">Text to filter searched nodes</param>
    /// <param name="parentAliasPath">Alias path of the parent</param>
    /// <param name="siteName">Name of the related site</param>
    /// <param name="totalRecords">Total records</param>
    private DataSet GetNodes(string searchText, string parentAliasPath, string siteName, out int totalRecords)
    {
        // Create WHERE condition
        var where = new WhereCondition()
            .WhereNotEquals("NodeAliasPath", "/");

        bool searchEnabled = !string.IsNullOrEmpty(searchText);
        if (searchEnabled)
        {
            var searchWhere = new WhereCondition().WhereContains("DocumentName", searchText)
                .Or().WhereContains("DocumentType", searchText);

            where = where.Where(searchWhere);
        }

        // If not all content is selectable and no additional content being displayed
        if ((SelectableContent != SelectableContentEnum.AllContent) && !IsFullListingMode)
        {
            where = where.WhereEquals("ClassName", SystemDocumentTypes.File);
        }

        var childClassNames = DocumentHelper.GetDocuments()
                                            .Path(parentAliasPath, PathTypeEnum.Children)
                                            .Column("ClassName")
                                            .OnSite(siteName)
                                            .NestingLevel(1)
                                            .Distinct();

        var classNames = String.Join(";", childClassNames.Select(name => name.ClassName));

        // Get nodes with coupled data to be able to recover presentation URL in case coupled data macro is used in URL pattern
        var query = DocumentHelper.GetDocuments()
                                  .Published(IsLiveSite)
                                  .WithCoupledColumns()
                                  .Types(classNames)
                                  .PublishedVersion(IsLiveSite)
                                  .OnSite(siteName)
                                  .Path(parentAliasPath, PathTypeEnum.Children)
                                  .Culture(Config.Culture)
                                  .CombineWithDefaultCulture()
                                  .Where(where)
                                  .OrderBy(mediaView.ListViewControl.SortDirect)
                                  .NestingLevel(1)
                                  .CheckPermissions();

        if (!searchEnabled)
        {
            // Don't use paged query for searching (works only for first page)
            query.Page(mediaView.CurrentPage - 1, mediaView.CurrentPageSize);
        }

        DataSet nodes = query.Result;
        totalRecords = query.TotalRecords;
        return nodes;
    }
    /// <summary>
    /// Creates where condition according to values selected in filter.
    /// </summary>
    private WhereCondition GenerateWhereCondition()
    {
        var where = new WhereCondition();

        string productNameColumnName = (ParentNode != null) ? "DocumentName" : "SKUName";

        // Append name/number condition
        var nameOrNumber = txtNameOrNumber.Text.Trim().Truncate(txtNameOrNumber.MaxLength);
        if (!string.IsNullOrEmpty(nameOrNumber))
        {
            // condition to get also products with variants that contains
            where.Where(k => k.Where(w => w.WhereContains(productNameColumnName, nameOrNumber)
                                           .Or()
                                           .WhereContains("SKUNumber", nameOrNumber))
                              .Or()
                              .Where(v => v.WhereIn("SKUID", new IDQuery<SKUInfo>("SKUParentSKUID").WhereContains("SKUName", nameOrNumber)
                                                                                                   .Or()
                                                                                                   .WhereContains("SKUNumber", nameOrNumber))));
        }

        // Append site condition
        if (allowGlobalProducts && (siteElem.SiteID != UniSelector.US_GLOBAL_AND_SITE_RECORD))
        {
            // Restrict SKUSiteID only for products not for product section (full listing mode)
            int selectedSiteID = (siteElem.SiteID > 0) ? siteElem.SiteID : 0;
            where.Where(w => w.Where("ISNULL(SKUSiteID, 0) = " + selectedSiteID).Or().WhereNull("SKUID"));
        }

        // Append department condition
        if (departmentElem.SelectedID > 0)
        {
            where.WhereEquals("SKUDepartmentID", departmentElem.SelectedID);
        }
        else if (departmentElem.SelectedID == -5)
        {
            where.WhereNull("SKUDepartmentID");
        }

        // Append one level condition
        if (ParentNode != null)
        {
            if (!chkShowAllChildren.Checked)
            {
                where.WhereEquals("NodeParentID", ParentNode.NodeID).And().WhereEquals("NodeLevel", ParentNode.NodeLevel + 1);
            }
        }

        // Handle advanced mode fields
        if (IsAdvancedMode)
        {
            // Append product type condition
            if ((selectProductTypeElem.Value != null) && (selectProductTypeElem.Value.ToString() != "ALL"))
            {
                where.WhereEquals("SKUProductType", selectProductTypeElem.Value);
            }

            // Manufacturer value
            if (manufacturerElem.SelectedID != UniSelector.US_ALL_RECORDS)
            {
                where.Where("ISNULL(SKUManufacturerID, 0) = " + manufacturerElem.SelectedID);
            }

            // Supplier value
            if (supplierElem.SelectedID != UniSelector.US_ALL_RECORDS)
            {
                where.Where("ISNULL(SKUSupplierID, 0) = " + supplierElem.SelectedID);
            }

            // Internal status value
            if (internalStatusElem.SelectedID != UniSelector.US_ALL_RECORDS)
            {
                where.Where("ISNULL(SKUInternalStatusID, 0) = " + internalStatusElem.SelectedID);
            }

            // Store status value
            if (publicStatusElem.SelectedID != UniSelector.US_ALL_RECORDS)
            {
                where.Where("ISNULL(SKUPublicStatusID, 0) = " + publicStatusElem.SelectedID);
            }

            // Append needs shipping condition
            int needsShipping = ValidationHelper.GetInteger(ddlNeedsShipping.SelectedValue, -1);
            if (needsShipping >= 0)
            {
                where.Where("ISNULL(SKUNeedsShipping, 0) = " + needsShipping);
            }

            // Append allow for sale condition
            int allowForSale = ValidationHelper.GetInteger(ddlAllowForSale.SelectedValue, -1);
            if (allowForSale >= 0)
            {
                where.WhereEquals("SKUEnabled", allowForSale);
            }

            // When in document mode
            if (ParentNode != null)
            {
                int docTypeId = ValidationHelper.GetInteger(drpDocTypes.SelectedValue, 0);
                if (docTypeId > 0)
                {
                    // Append document type condition
                    where.WhereEquals("NodeClassID", docTypeId);
                }
            }
        }

        return where;
    }
    /// <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);
    }
Ejemplo n.º 43
0
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        gridElem.EditActionUrl = "Edit.aspx?variantid={0}&nodeid=" + NodeID;
        gridElem.ZeroRowsText = GetString("contentvariant.nodata");

        // Grid initialization
        gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction);

        // If not set, get the page template id for the current node and its document template
        if ((PageTemplateID <= 0) && (Node != null))
        {
            PageTemplateID = Node.GetUsedPageTemplateId();
        }

        // Build where condition
        var where = new WhereCondition().WhereEquals("VariantPageTemplateID", PageTemplateID);

        // Display only variants for the current document
        if (Node != null)
        {
            where.WhereEqualsOrNull("VariantDocumentID", Node.DocumentID);
        }

        // Display variants just for a specific zone/webpart/widget
        if (!string.IsNullOrEmpty(ZoneID))
        {
            where.WhereEquals("VariantZoneID", ZoneID);

            if (InstanceGUID != Guid.Empty)
            {
                // Web part/widget condition
                where.WhereEquals("VariantInstanceGUID", InstanceGUID );
            }
        }

        gridElem.WhereCondition = where.ToString(expand: true);
    }
    /// <summary>
    /// Returns complete WHERE condition.
    /// </summary>
    protected WhereCondition GetCompleteWhereCondition()
    {
        string allRecords = UniSelector.US_ALL_RECORDS.ToString();

        string customWhere = ValidationHelper.GetString(GetValue("WhereCondition"), "");
        var where = new WhereCondition();

        // Do not select product options and select only enabled products
        where.WhereNull("SKUOptionCategoryID").And().WhereTrue("SKUEnabled");

        // Get products only with specified public status
        if (ProductPublicStatusName != allRecords)
        {
            int pStatusSiteID = ECommerceSettings.UseGlobalPublicStatus(SiteName) ? 0 : SiteInfoProvider.GetSiteID(SiteName);
            where.WhereEquals("SKUPublicStatusID", new IDQuery<PublicStatusInfo>("PublicStatusID").Where("ISNULL(PublicStatusSiteID, 0) = " + pStatusSiteID).And().WhereEquals("PublicStatusName", ProductPublicStatusName).TopN(1));
        }

        // Get products only with specified internal status
        if (ProductInternalStatusName != allRecords)
        {
            int iStatusSiteID = ECommerceSettings.UseGlobalInternalStatus(SiteName) ? 0 : SiteInfoProvider.GetSiteID(SiteName);
            where.WhereEquals("SKUInternalStatusID", new IDQuery<InternalStatusInfo>("InternalStatusID").Where("ISNULL(InternalStatusSiteID, 0) = " + iStatusSiteID).And().WhereEquals("InternalStatusName", ProductInternalStatusName).TopN(1));
        }

        // Get products only from specified department
        if (!string.IsNullOrEmpty(ProductDepartmentName) && (ProductDepartmentName != allRecords))
        {
            DepartmentInfo dept = DepartmentInfoProvider.GetDepartmentInfo(ProductDepartmentName, SiteName);

            int departmentID = (dept != null) ? dept.DepartmentID : 0;
            where.WhereEquals("SKUDepartmentID", departmentID);
        }

        // Include user custom WHERE condition
        if (customWhere.Trim() != "")
        {
            where.Where(customWhere);
        }

        return where;
    }
Ejemplo n.º 45
0
    /// <summary>
    /// Returns where condition.
    /// </summary>
    /// <param name="customWhere">Custom WHERE condition</param>
    private WhereCondition GetWhereCondition(string customWhere)
    {
        SiteInfo si;
        var where = new WhereCondition();

        // Get required site data
        if (!String.IsNullOrEmpty(SiteName))
        {
            si = SiteInfoProvider.GetSiteInfo(SiteName);
        }
        else
        {
            si = SiteContext.CurrentSite;
        }

        if (si != null)
        {
            // Build where condition
            var classWhere = new WhereCondition();

            // Get documents of the specified class only - without coupled data !!!
            if (!String.IsNullOrEmpty(ClassNames))
            {
                string[] classNames = ClassNames.Trim(';').Split(';');
                foreach (string className in classNames)
                {
                    classWhere.WhereEquals("ClassName", className).Or();
                }
            }

            where.WhereIn("NodeSKUID", new IDQuery<OrderItemInfo>("OrderItemSKUID").Source(s => s.Join<SKUInfo>("OrderItemSKUID", "SKUID")
                                                                                   .Join<OrderInfo>("COM_OrderItem.OrderItemOrderID", "OrderID"))
                                                                                   .WhereTrue("SKUEnabled")
                                                                                   .WhereNull("SKUOptionCategoryID")
                                                                                   .WhereEquals("OrderSiteID", si.SiteID)
                                                                                   .Where(classWhere));

            // Add custom WHERE condition
            if (!String.IsNullOrEmpty(customWhere))
            {
                where.Where(customWhere);
            }
        }

        return where;
    }
    /// <summary>
    /// Reloads the data.
    /// </summary>
    /// <param name="forceReload">If true, the data is reloaded even when already loaded</param>
    public void ReloadData(bool forceReload)
    {
        if (!dataLoaded || forceReload)
        {
            drpWebpart.Items.Clear();

            if (DisplayNone)
            {
                drpWebpart.Items.Add(new ListItem(ResHelper.GetString("General.SelectNone"), ""));
            }

            // Do not retrieve webparts
            WhereCondition condition = new WhereCondition(WhereCondition);
            if (!ShowWebparts)
            {
                condition.WhereEquals("ObjectType", "webpartcategory");
            }

            if (!ShowInheritedWebparts)
            {
                condition.WhereNull("WebPartParentID");
            }

            if (!String.IsNullOrEmpty(RootPath))
            {
                string rootPath = RootPath.TrimEnd('/');
                condition.Where(new WhereCondition().WhereEquals("ObjectPath", rootPath).Or().WhereStartsWith("ObjectPath", rootPath + "/"));
            }

            ds = WebPartCategoryInfoProvider.GetCategoriesAndWebparts(condition.ToString(true), "DisplayName", 0, "ObjectID, DisplayName, ParentID, ObjectType");

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int counter = 0;

                // Make special collection for "tree mapping"
                Dictionary<int, SortedList<string, object[]>> categories = new Dictionary<int, SortedList<string, object[]>>();

                // Fill collection from dataset
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int parentId = ValidationHelper.GetInteger(dr["ParentID"], 0);
                    int id = ValidationHelper.GetInteger(dr["ObjectID"], 0);
                    string name = ResHelper.LocalizeString(ValidationHelper.GetString(dr["DisplayName"], String.Empty));
                    string type = ValidationHelper.GetString(dr["ObjectType"], String.Empty);

                    // Skip webpart, take only WebpartCategory
                    if (type == "webpart")
                    {
                        continue;
                    }

                    SortedList<string, object[]> list;
                    categories.TryGetValue(parentId, out list);

                    // Sub categories list not created yet
                    if (list == null)
                    {
                        list = new SortedList<string, object[]>();
                        categories.Add(parentId, list);
                    }

                    list.Add(name + "_" + counter, new object[] { id, name });

                    counter++;
                }

                // Start filling the dropdown from the root(parentId = 0)
                int level = 0;

                // Root is not shown, start indentation later
                if (!ShowRoot)
                {
                    level = -1;
                }

                AddSubCategories(categories, 0, level);
            }

            dataLoaded = true;
        }
    }
    /// <summary>
    /// Loads data into Unigrid.
    /// </summary>
    private void LoadData()
    {
        var whereCondition = new WhereCondition();
        if (!String.IsNullOrEmpty(AliasPath))
        {
            whereCondition.WhereEquals("ABTestOriginalPage", AliasPath);
        }

        DataSet abTests = ABTestInfoProvider.GetABTests().OnSite(SiteContext.CurrentSiteID).Where(whereCondition);
        abTests.Tables[0].Columns.Add("ABTestStatus", typeof(int));

        foreach (DataRow abTestDataRow in abTests.Tables[0].Rows)
        {
            abTestDataRow["ABTestStatus"] = (int)ABTestStatusEvaluator.GetStatus(new ABTestInfo(abTestDataRow));
        }

        gridElem.DataSource = abTests;
    }
    /// <summary>
    /// Gets where condition based on value of given controls.
    /// </summary>
    /// <param name="where">Where condition</param>
    /// <param name="column">Column to compare</param>
    /// <param name="drpOperator">List control with operator</param>
    /// <param name="valueBox">Text control with value</param>
    /// <returns>Where condition for outdated documents</returns>
    private void AddOutdatedWhereCondition(WhereCondition where, string column, ListControl drpOperator, ITextControl valueBox)
    {
        var value = TextHelper.LimitLength(valueBox.Text, 100);

        if (!String.IsNullOrEmpty(value))
        {
            string condition = drpOperator.SelectedValue;

            // Create condition based on operator
            switch (condition)
            {
                case WhereBuilder.LIKE:
                    where.WhereContains(column, value);
                    break;

                case WhereBuilder.NOT_LIKE:
                    where.WhereNotContains(column, value);
                    break;

                case WhereBuilder.EQUAL:
                    where.WhereEquals(column, value);
                    break;

                case WhereBuilder.NOT_EQUAL:
                    where.WhereNotEquals(column, value);
                    break;
            }
        }
    }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    /// <param name="reloadUniSelector">If true, UniSelector is also reloaded</param>
    public void ReloadData(bool reloadUniSelector = false)
    {
        uniSelector.IsLiveSite = IsLiveSite;
        var where = new WhereCondition();

        if (OnlyDocumentTypes)
        {
            where.WhereEquals("ClassIsDocumentType", 1);
        }
        else if (OnlyCustomTables)
        {
            where.WhereEquals("ClassIsCustomTable", 1);
        }

        if (mSiteId != null)
        {
            where.WhereIn("ClassID", ClassSiteInfoProvider.GetClassSites().Column("ClassID").WhereEquals("SiteID", mSiteId));
        }

        // Combine default where condition with external
        if (!String.IsNullOrEmpty(WhereCondition))
        {
            where.Where(WhereCondition);
        }

        uniSelector.WhereCondition = where.ToString(true);

        if (reloadUniSelector)
        {
            uniSelector.Reload(true);
        }
    }
    private string CreateWhereCondition(string originalWhere)
    {
        var where = new WhereCondition();
        where.Where(new WhereCondition(originalWhere){ WhereIsComplex = true });

        // Add where conditions from filters
        where.Where(new WhereCondition(nameFilter.WhereCondition) { WhereIsComplex = true });

        string objType = ValidationHelper.GetString(objTypeSelector.Value, "");
        if (!String.IsNullOrEmpty(objType))
        {
            where.WhereLike("VersionObjectType", objType);
        }

        int userId = ValidationHelper.GetInteger(userSelector.Value, 0);
        if (userId > 0)
        {
            where.WhereEquals("VersionDeletedByUserID", userId);
        }

        // Get older than value
        if (DisplayDateTimeFilter)
        {
            DateTime olderThan = DateTime.Now.Date.AddDays(1);
            int dateTimeValue = ValidationHelper.GetInteger(txtFilter.Text, 0);

            switch (drpFilter.SelectedIndex)
            {
                case 0:
                    olderThan = olderThan.AddDays(-dateTimeValue);
                    break;

                case 1:
                    olderThan = olderThan.AddDays(-dateTimeValue * 7);
                    break;

                case 2:
                    olderThan = olderThan.AddMonths(-dateTimeValue);
                    break;

                case 3:
                    olderThan = olderThan.AddYears(-dateTimeValue);
                    break;
            }

            where.WhereLessOrEquals("VersionDeletedWhen", olderThan);
        }

        return where.ToString(true);
    }
    /// <summary>
    /// Gets WHERE condition for available sites according field configuration.
    /// </summary>
    private string GetSiteWhere()
    {
        // First check configuration
        WhereCondition condition = new WhereCondition();

        if (!IsCopyMoveLinkDialog)
        {
            condition.WhereEquals("SiteStatus", "RUNNING");
        }

        switch (Config.ContentSites)
        {
            case AvailableSitesEnum.OnlySingleSite:
                condition.WhereEquals("SiteName", Config.ContentSelectedSite);
                break;

            case AvailableSitesEnum.OnlyCurrentSite:
                condition.WhereEquals("SiteName", SiteContext.CurrentSiteName);
                break;
        }

        // Get only current user's sites
        if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator)
        {
            condition.WhereIn("SiteID", new IDQuery<UserSiteInfo>(UserSiteInfo.TYPEINFO.SiteIDColumn)
                                                    .WhereEquals("UserID", MembershipContext.AuthenticatedUser.UserID));
        }
        return condition.ToString(true);
    }
    /// <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>
    /// 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;
        }
    }
    /// <summary>
    /// Get where condition for unigrid
    /// </summary>
    /// <returns>Where condition</returns>
    private WhereCondition GetWhereCondition()
    {
        string productNameFilter = txtProductName.Text;
        string productCodeFilter = txtProductCode.Text;

        // To display ONLY product - not product options
        var where = new WhereCondition().WhereTrue("SKUEnabled").And().WhereNull("SKUOptionCategoryID");

        if (!string.IsNullOrEmpty(productNameFilter))
        {
            // Condition to get also products with variants that contains
            where.Where(w => w.WhereContains("SKUName", productNameFilter)
                              .Or()
                              .WhereIn("SKUID", new IDQuery<SKUInfo>("SKUParentSKUID").WhereContains("SKUName", productNameFilter)));
        }
        if (productCodeFilter != "")
        {
            // Condition to get also products with variants that contains
            where.Where(w => w.WhereContains("SKUNumber", productNameFilter).Or().WhereIn("SKUID", new IDQuery<SKUInfo>("SKUParentSKUID").WhereContains("SKUNumber", productNameFilter)));
        }
        if (departmentElem.SelectedID > 0)
        {
            where.WhereEquals("SKUDepartmentID", departmentElem.SelectedID);
        }

        where.Where(SKUInfoProvider.ProviderObject.AddSiteWhereCondition(string.Empty, SiteContext.CurrentSiteID, ECommerceSettings.ALLOW_GLOBAL_PRODUCTS, true));

        return where;
    }
    /// <summary>
    /// PageLoad event handler.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Object type cannot be defined in xml definition -> it would ignore code behind configuration
        UniGridRelationship.ObjectType = (IsAdHocRelationship) ? RelationshipInfo.OBJECT_TYPE_ADHOC : RelationshipInfo.OBJECT_TYPE;

        if (StopProcessing)
        {
            UniGridRelationship.StopProcessing = StopProcessing;
            return;
        }

        // Set tree node from Form object
        if ((TreeNode == null) && (Form != null) && (Form.EditedObject != null))
        {
            var node = Form.EditedObject as TreeNode;
            if ((node != null) && (Form.Mode == FormModeEnum.Update))
            {
                TreeNode = node;
            }
            else
            {
                ShowInformation(GetString("relationship.editdocumenterror"));
            }
        }

        if (TreeNode != null)
        {
            InitUniGrid();

            int nodeId = TreeNode.NodeID;

            // Add relationship name condition
            var condition = new WhereCondition().WhereIn("RelationshipNameID", new IDQuery<RelationshipNameInfo>().Where(GetRelationshipNameCondition()));

            // Switch sides is disabled
            if (!AllowSwitchSides)
            {
                condition.WhereEquals(DefaultSide ? "RightNodeID" : "LeftNodeID", nodeId);
            }
            else
            {
                condition.Where(new WhereCondition().WhereEquals("RightNodeID", nodeId).Or().WhereEquals("LeftNodeID", nodeId));
            }

            InitFilterVisibility();

            UniGridRelationship.WhereCondition = condition.ToString(true);

            if (ShowAddRelation)
            {
                btnNewRelationship.OnClientClick = GetAddRelatedDocumentScript() + " return false;";
            }
            else
            {
                pnlNewLink.Visible = false;
            }
        }
        else
        {
            UniGridRelationship.StopProcessing = true;
            UniGridRelationship.Visible = false;

            btnNewRelationship.Enabled = false;
        }

        if (RequestHelper.IsPostBack())
        {
            string target = Request[Page.postEventSourceID];
            if ((target != pnlUpdate.ClientID) && (target != pnlUpdate.UniqueID))
            {
                return;
            }

            string action = Request[Page.postEventArgumentID];
            if (string.IsNullOrEmpty(action))
            {
                return;
            }

            switch (action.ToLowerCSafe())
            {
                // Insert from 'Select document' dialog
                case "insertfromselectdocument":
                    SaveRelationship();
                    break;
            }
        }
        else
        {
            bool inserted = QueryHelper.GetBoolean("inserted", false);
            if (inserted)
            {
                ShowConfirmation(GetString("relationship.wasadded"));
            }
        }
    }
    /// <summary>
    /// Returns WHERE condition when libraries are being displayed. Sets also group identifier if specified
    /// </summary>
    private string GetDisplayedLibrariesCondition()
    {
        AvailableLibrariesEnum availableLibrariesEnum;
        string libraryName = String.Empty;

        // Get correct libraries
        if (SelectedGroupID != 0)
        {
            availableLibrariesEnum = GroupLibraries;

            if (groupsSelector != null)
            {
                // Get currently selected group ID
                int groupId = ValidationHelper.GetInteger(groupsSelector.GetValue("GroupID"), 0);
                if (groupId > 0)
                {
                    librarySelector.GroupID = groupId;
                    libraryName = GroupLibraryName;
                }
            }
        }
        else
        {
            availableLibrariesEnum = GlobalLibraries;
            libraryName = GlobalLibraryName;
        }

        var condition = new WhereCondition();

        switch (availableLibrariesEnum)
        {
            case AvailableLibrariesEnum.OnlySingleLibrary:
                librarySelector.SiteID = SiteID;
                return condition.WhereEquals("LibraryName", libraryName).ToString(true);

            case AvailableLibrariesEnum.OnlyCurrentLibrary:
                int libraryId = (MediaLibraryContext.CurrentMediaLibrary != null) ? MediaLibraryContext.CurrentMediaLibrary.LibraryID : 0;
                return condition.WhereEquals("LibraryID", libraryId).ToString(true);

            case AvailableLibrariesEnum.None:
                return condition.NoResults().ToString(true);

            default:
                librarySelector.SiteID = SiteID;
                return String.Empty;
        }
    }
    /// <summary>
    /// Returns site condition for given site id.
    /// </summary>
    /// <param name="siteID">Site id</param>
    private static WhereCondition GetSiteCondition(int siteID)
    {
        var condition = new WhereCondition();

        switch (siteID)
        {
            case UniSelector.US_GLOBAL_RECORD:
                condition.WhereNull("StateSiteID");
                break;

            case UniSelector.US_ALL_RECORDS:
            case UniSelector.US_NONE_RECORD:
                break;

            default:
                condition.WhereEquals("StateSiteID", siteID);
                break;
        }

        return condition;
    }
    /// <summary>
    /// Gets where condition for selecting relationship names
    /// </summary>
    private WhereCondition GetRelationshipNameCondition()
    {
        var relationshipNameCondition = new WhereCondition();

        if (!UseAdHocRelationshipName)
        {
            relationshipNameCondition.Where(new WhereCondition().WhereFalse("RelationshipNameIsAdHoc").Or().WhereNull("RelationshipNameIsAdHoc"));

            if (!String.IsNullOrEmpty(RelationshipName))
            {
                relationshipNameCondition.WhereEquals("RelationshipName", RelationshipName);
            }
        }
        else
        {
            relationshipNameCondition.WhereEquals("RelationshipName", AdHocRelationshipName);
        }

        return relationshipNameCondition;
    }
Ejemplo n.º 59
0
    /// <summary>
    /// Returns where condition based on webpart fields.
    /// </summary>
    private WhereCondition GetWhereCondition()
    {
        var where = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID);

        // Show products only from current site or global too, based on setting
        if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName))
        {
            where.Where(w => w.WhereEquals("SKUSiteID", SiteContext.CurrentSiteID).Or().WhereNull("SKUSiteID"));
        }

        // Show/hide product variants - it is based on type of inventory tracking for parent product
        string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation();
        where.Where(v => v.Where(w => w.WhereNull("SKUParentSKUID").And().WhereNotEquals("SKUTrackInventory", trackByVariants))
                          .Or()
                          .Where(GetParentProductWhereCondition(new WhereCondition().WhereEquals("SKUTrackInventory", trackByVariants))));

        // Product type filter
        if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL))
        {
            if (ProductType == PRODUCT_TYPE_PRODUCTS)
            {
                where.WhereNull("SKUOptionCategoryID");
            }
            else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS)
            {
                where.WhereNotNull("SKUOptionCategoryID");
            }
        }

        // Representing filter
        if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL))
        {
            SKUProductTypeEnum productTypeEnum = Representing.ToEnum<SKUProductTypeEnum>();
            string productTypeString = productTypeEnum.ToStringRepresentation();

            where.WhereEquals("SKUProductType", productTypeString);
        }

        // Product number filter
        if (!string.IsNullOrEmpty(ProductNumber))
        {
            where.WhereContains("SKUNumber", ProductNumber);
        }

        // Department filter
        DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName);
        di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null);

        if (di != null)
        {
            where.Where(GetColumnWhereCondition("SKUDepartmentID", new WhereCondition().WhereEquals("SKUDepartmentID", di.DepartmentID)));
        }

        // Manufacturer filter
        ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName);
        mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null);
        if (mi != null)
        {
            where.Where(GetColumnWhereCondition("SKUManufacturerID", new WhereCondition().WhereEquals("SKUManufacturerID", mi.ManufacturerID)));
        }

        // Supplier filter
        SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName);
        si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null);
        if (si != null)
        {
            where.Where(GetColumnWhereCondition("SKUSupplierID", new WhereCondition().WhereEquals("SKUSupplierID", si.SupplierID)));
        }

        // Needs shipping filter
        if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL))
        {
            if (NeedsShipping == NEEDS_SHIPPING_YES)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereTrue("SKUNeedsShipping")));
            }
            else if (NeedsShipping == NEEDS_SHIPPING_NO)
            {
                where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereFalse("SKUNeedsShipping").Or().WhereNull("SKUNeedsShipping")));
            }
        }

        // Price from filter
        if (PriceFrom > 0)
        {
            where.WhereGreaterOrEquals("SKUPrice", PriceFrom);
        }

        // Price to filter
        if (PriceTo > 0)
        {
            where.WhereLessOrEquals("SKUPrice", PriceTo);
        }

        // Public status filter
        PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName);
        if (psi != null)
        {
            where.Where(GetColumnWhereCondition("SKUPublicStatusID", new WhereCondition().WhereEquals("SKUPublicStatusID", psi.PublicStatusID)));
        }

        // Internal status filter
        InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName);
        if (isi != null)
        {
            where.Where(GetColumnWhereCondition("SKUInternalStatusID", new WhereCondition().WhereEquals("SKUInternalStatusID", isi.InternalStatusID)));
        }

        // Allow for sale filter
        if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL))
        {
            if (AllowForSale == ALLOW_FOR_SALE_YES)
            {
                where.WhereTrue("SKUEnabled");
            }
            else if (AllowForSale == ALLOW_FOR_SALE_NO)
            {
                where.WhereEqualsOrNull("SKUEnabled", false);
            }
        }

        // Available items filter
        if (!string.IsNullOrEmpty(AvailableItems))
        {
            int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue);
            where.WhereLessOrEquals("SKUAvailableItems", value);
        }

        // Needs to be reordered filter
        if (NeedsToBeReordered)
        {
            where.Where(w => w.Where(v => v.WhereNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems", 0))
                              .Or()
                              .Where(z => z.WhereNotNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems".AsColumn(), "SKUReorderAt".AsColumn())));
        }

        return where;
    }
    /// <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);
    }