예제 #1
0
        /// <summary>
        /// Gets the parent values.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <returns>Returns <c>true</c> if this element exists; otherwise, <c>false</c>.</returns>
        public static GroupBy GetGroupBy(CamlQuery parent)
        {
            if (parent == null)
                return null;

            var qroupByElement = XElement.Parse(parent.Query).Element(GroupByElementName);
            if (qroupByElement == null)
                return null;

            var isCollapsed = false;
            var fieldName = string.Empty;

            bool.TryParse(qroupByElement.Attribute(CollapseAttributeName).Value, out isCollapsed);

            var fieldRef = qroupByElement.Element(FieldRefElementName);
            if (fieldRef == null)
                return null;

            fieldName = fieldRef.Attribute(NameAttributeName).Value;

            var groupBy = new GroupBy();
            groupBy._parent = parent;
            groupBy._fieldName = fieldName;
            groupBy._isCollapsed = isCollapsed;

            return groupBy;
        }
예제 #2
0
        /// <summary>
        /// Gets the query.
        /// </summary>
        /// <returns>
        /// Returns query.
        /// </returns>
        protected override CamlQuery GetQuery()
        {
            var condition = GetQueryCondition();
            var query = new CamlQuery() { Where = condition };
            query.ValidFields.Add(FieldName);

            return query;
        }
예제 #3
0
        /// <summary>
        /// Merges the query condition.
        /// </summary>
        /// <param name="querySchemaElement">The query schema element.</param>
        /// <param name="mainQuery">The main query.</param>
        /// <param name="queryItems">The query items.</param>
        /// <returns>Returns merged query.</returns>
        public static CamlQuery MergeQueryCondition(CamlQuerySchemaElements querySchemaElement, CamlQuery mainQuery, params CamlQuery[] queryItems)
        {
            var queryItemList = queryItems.ToList();

            if (mainQuery == null || !queryItemList.Any())
                return null;

            foreach (CamlQuery camlQuery in queryItems)
            {
                mainQuery.ValidFields.AddRange(camlQuery.ValidFields);
                mainQuery.InvalidFields.AddRange(camlQuery.InvalidFields);

                var newQueryCondition = string.Empty;
                var itemQueryConditions = camlQuery.Query.Split(WhereSplitingArray, StringSplitOptions.None);

                // If there is no wehre conditon or condition is empty merge not requierd
                if (itemQueryConditions.Length < WhereSplitingArray.Length || itemQueryConditions[1].IsNullOrEmpty())
                    continue;

                // If there is where condition in main query
                if (mainQuery.Query.Contains(WhereSplitingArray[0]))
                {
                    var mainQueryCondition = mainQuery.Query.Split(WhereSplitingArray, StringSplitOptions.None)[1];

                    // If where query in main query is empty insert item query only
                    if (mainQueryCondition.IsNullOrEmpty())
                        mainQuery.Query = mainQuery.Query.Replace(WhereSplitingArray[0], WhereSplitingArray[0] + itemQueryConditions[1]);
                    else
                    {
                        newQueryCondition = CreateQueryCondition(querySchemaElement, mainQueryCondition, itemQueryConditions[1]);
                        mainQuery.Query = mainQuery.Query.Replace(mainQueryCondition, newQueryCondition);
                    }
                }
                else
                {
                    mainQuery.Where = CreateQueryCondition(CamlQuerySchemaElements.Where, itemQueryConditions[1]);
                }
            }

            return mainQuery;
        }
        /// <summary>
        /// Gets the query.
        /// </summary>
        /// <returns>Return query.</returns>
        protected virtual CamlQuery GetQuery()
        {
            var fieldValue = FieldValue;
            var fieldType = FieldType;
            var aditionalFieldAttributes = new Dictionary<CamlQuerySchemaAttributes, object>();
            var aditionalValueAttributes = new Dictionary<CamlQuerySchemaAttributes, object>();
            var query = new CamlQuery();

            if (Field != null)
            {
                // Lookup field actions
                var lookupField = _field as SPFieldLookup;
                if (lookupField != null)
                {
                    if (lookupField.CountRelated)
                        fieldType = SPFieldType.Integer;

                    if (lookupField.IsDependentLookup)
                        fieldType = SPFieldType.Invalid;
                }

                // Calculated field actions
                var calculatedField = _field as SPFieldCalculated;
                if (calculatedField != null)
                    fieldType = calculatedField.OutputType;
            }

            if (IsFieldValidListField && CamlQueryHelper.IsValidFieldForQuery(FieldType, FieldName) && CamlQueryHelper.TryParseValue(fieldType, ref fieldValue))
            {
                // Setting attributres
                if (IsLookupId)
                {
                    aditionalFieldAttributes.Add(CamlQuerySchemaAttributes.LookupId, true);
                    _elementType = CamlQuerySchemaElements.Eq;
                }

                // Setting paresd value and proper field type
                FieldValue = fieldValue;
                FieldType = fieldType;

                // Creating query
                query = new CamlQuery();
                query.Where = GetQueryCondition(aditionalFieldAttributes, aditionalValueAttributes);
                query.ValidFields.Add(FieldName);
            }
            else
                query.InvalidFields.Add(FieldName);

            query.List = _list;
            return query;
        }
예제 #5
0
 /// <summary>
 /// Sets the parent.
 /// </summary>
 /// <param name="parent">The parent.</param>
 public void SetParent(CamlQuery parent)
 {
     _parent = parent;
     SetParentValues();
 }
예제 #6
0
        /// <summary>
        /// Removes the group by.
        /// </summary>
        /// <param name="parent">The parent.</param>
        public static void RemoveGroupBy(CamlQuery parent)
        {
            var currentQueryElement = XElement.Parse(parent.Query);
            var groupByElement = currentQueryElement.Element(GroupByElementName);

            if (groupByElement != null)
                currentQueryElement.Element(GroupByElementName).Remove();
        }