Exemple #1
0
    /// <summary>
    /// Gets the where condition for the selected object type.
    /// </summary>
    /// <param name="selectedObjectType">Selected object type</param>
    public string GetWhereCondition(string selectedObjectType)
    {
        if (Object != null)
        {
            string where = null;

            var relatedObject = RelatedObject;
            if (relatedObject != null)
            {
                // Get the site name
                var relatedTypeInfo = relatedObject.TypeInfo;
                if (relatedTypeInfo.SiteIDColumn != ObjectTypeInfo.COLUMN_NAME_UNKNOWN)
                {
                    if (siteSelector.DropDownSingleSelect.Items.Count == 0)
                    {
                        siteSelector.Value = SiteContext.CurrentSiteID;
                    }

                    if (siteSelector.HasData)
                    {
                        // Set the site name for registration
                        int selectedSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0);
                        if (selectedSiteId >= 0)
                        {
                            var siteCondition = (selectedSiteId > 0) ?
                                                new WhereCondition().WhereEquals(relatedTypeInfo.SiteIDColumn, selectedSiteId) :
                                                new WhereCondition().WhereNull(relatedTypeInfo.SiteIDColumn);

                            string siteQuery = new DataQuery(relatedTypeInfo.ObjectType, null)
                                               .Column(relatedTypeInfo.IDColumn)
                                               .Where(siteCondition)
                                               .QueryText;

                            // Where condition for the left object
                            string rightWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, false, true, selectedObjectType);
                            rightWhere += " AND RelationshipLeftObjectID IN (" + siteQuery + ")";

                            // Where condition for the left object
                            string leftWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, false, selectedObjectType);
                            leftWhere += " AND RelationshipRightObjectID IN (" + siteQuery + ")";

                            // --- Add site conditions here

                            where = SqlHelper.AddWhereCondition(leftWhere, rightWhere, "OR");
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(where))
            {
                // Get using regular where
                where = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, true, selectedObjectType);
            }

            return(where);
        }

        return(null);
    }
    /// <summary>
    /// Gets the where condition for the selected object type.
    /// </summary>
    /// <param name="selectedObjectType">Selected object type</param>
    public string GetWhereCondition(string selectedObjectType)
    {
        if (Object != null)
        {
            string where = null;

            if (RelatedObject != null)
            {
                // Get the site name

                if ((RelatedObject.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN) && (CMSObjectHelper.GetSiteBindingObject(RelatedObject) == null))
                {
                    if (siteSelector.DropDownSingleSelect.Items.Count == 0)
                    {
                        siteSelector.Value = CMSContext.CurrentSiteID;
                    }

                    if (siteSelector.HasData)
                    {
                        // Set the site name for registration
                        int selectedSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0);
                        if (selectedSiteId >= 0)
                        {
                            string siteWhere = QueryProvider.GetQuery(RelatedObject.ObjectType + ".selectall", RelatedObject.IDColumn, SqlHelperClass.GetSiteIDWhereCondition(RelatedObject.SiteIDColumn, selectedSiteId), null, 0);

                            // Where condition for the left object
                            string rightWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, false, true, selectedObjectType);
                            rightWhere += " AND RelationshipLeftObjectID IN (" + siteWhere + ")";

                            // Where condition for the left object
                            string leftWhere = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, false, selectedObjectType);
                            leftWhere += " AND RelationshipRightObjectID IN (" + siteWhere + ")";

                            // --- Add site conditions here

                            where = SqlHelperClass.AddWhereCondition(leftWhere, rightWhere, "OR");
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(where))
            {
                // Get using regular where
                where = ObjectRelationshipInfoProvider.GetWhereCondition(ObjectID, ObjectType, 0, true, true, selectedObjectType);
            }

            return(where);
        }

        return(null);
    }