Esempio n. 1
0
        private void ParseGroupByFieldList(string fieldList, int pos, bool allowRelation)
        {
            this.GroupByFields.Clear();
            if (string.IsNullOrEmpty(fieldList))
            {
                return;
            }
            Match match;

            do
            {
                match = GridGroupByExpression.groupByFieldParser.Match(fieldList.Substring(pos));
                if (!match.Success)
                {
                    throw new FormatException(string.Format("Cannot parse \"{0}\". Verify the correctness of the string.", (object)fieldList));
                }
                GridGroupByField groupByField = new GridGroupByField();
                if (match.Groups["aggregate"].Success)
                {
                    groupByField.SetAggregate(match.Groups["aggregate"].ToString());
                }
                groupByField.SortOrder = !match.Groups["sortDirection"].Success || string.Compare("DESC", match.Groups["sortDirection"].Value) != 0 ? RadSortOrder.Ascending : RadSortOrder.Descending;
                if (!match.Groups["fieldName"].Success)
                {
                    throw new FormatException("Could not parse field name. Please contact Telerik support");
                }
                groupByField.FieldName = match.Groups["fieldName"].ToString();
                GridGroupByExpression.UpdateGroupByReferences(this.selectFields, groupByField);
                this.groupByFields.Add(groupByField);
                pos += match.Length;
            }while (match.Groups["delimiter"].Success);
        }
Esempio n. 2
0
        public static string UpdateFormatString(
            string formatString,
            bool doubleQuote,
            bool forceChange)
        {
            string str = (string)null;

            switch (GridGroupByField.ValidateFormatString(formatString))
            {
            case 0:
                str = string.Format("'{0}'", (object)formatString);
                break;

            case 1:
                str = doubleQuote || !forceChange?string.Format("'{0}'", (object)formatString) : string.Format("\"{0}\"", (object)formatString.Replace('"', '\''));

                break;

            case 2:
                str = !doubleQuote || !forceChange?string.Format("\"{0}\"", (object)formatString) : string.Format("'{0}'", (object)formatString.Replace('\'', '"'));

                break;

            case 3:
                str = !doubleQuote?string.Format("\"{0}\"", (object)formatString.Replace('"', '\'')) : string.Format("'{0}'", (object)formatString.Replace('\'', '"'));

                break;
            }
            return(str);
        }
Esempio n. 3
0
        public string ToSelectString(string defaultFormatString)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (this.IsAggregate)
            {
                stringBuilder.AppendFormat("{0}([{1}])", (object)this.Aggregate.ToString().ToLower(), (object)this.FieldName);
            }
            else
            {
                stringBuilder.AppendFormat("[{0}]", (object)this.FieldName);
            }
            if (this.IsFieldAliasSet)
            {
                stringBuilder.AppendFormat(" as [{0}]", (object)this.FieldAlias);
            }
            string str = this.IsFormatStringSet ? this.formatString : defaultFormatString;

            if (!string.IsNullOrEmpty(str) && string.Compare(str, GridGroupByField.DefaultFormatString) == 0)
            {
                str = (string)null;
            }
            if (!string.IsNullOrEmpty(str))
            {
                stringBuilder.AppendFormat(" format {0}", (object)GridGroupByField.UpdateFormatString(str, true, false));
            }
            return(stringBuilder.ToString());
        }
Esempio n. 4
0
 private bool IsDuplicateEvent(
     NotifyCollectionChangedEventArgs e,
     GridGroupByFieldCollection otherCollection)
 {
     if (e.Action == NotifyCollectionChangedAction.ItemChanged)
     {
         GridGroupByField newItem = e.NewItems[0] as GridGroupByField;
         if (otherCollection.Contains(newItem))
         {
             NotifyCollectionChangedEventArgs changedEventArgs = this.duplicateEventsList.Find((Predicate <NotifyCollectionChangedEventArgs>)(args =>
             {
                 if (args.NewItems[0] == e.NewItems[0])
                 {
                     return(args.PropertyName == e.PropertyName);
                 }
                 return(false);
             }));
             if (changedEventArgs == null)
             {
                 this.duplicateEventsList.Add(e);
                 return(true);
             }
             this.duplicateEventsList.Remove(changedEventArgs);
         }
     }
     return(false);
 }
Esempio n. 5
0
 public virtual string UpdateFormatString(bool doubleQuote, bool forceChange)
 {
     if (this.IsFormatStringSet)
     {
         this.formatString = GridGroupByField.UpdateFormatString(this.formatString, doubleQuote, forceChange);
     }
     return(this.formatString);
 }
Esempio n. 6
0
 public void CopyFrom(GridGroupByField field)
 {
     this.fieldName    = field.fieldName;
     this.fieldAlias   = field.fieldAlias;
     this.aggregate    = field.aggregate;
     this.formatString = field.formatString;
     this._headerText  = field._headerText;
     this.RelationName = field.RelationName;
     this.SortOrder    = field.SortOrder;
 }
Esempio n. 7
0
        private static void UpdateFieldNameAndAliasReferences(
            GridGroupByFieldCollection list,
            GridGroupByField groupByField)
        {
            GridGroupByExpression.UpdateReference(list, groupByField);
            GridGroupByField byName = list.FindByName(groupByField.FieldName);

            if (byName != null && (byName.IsFieldAliasSet && groupByField.IsFieldAliasSet && byName.Aggregate == groupByField.Aggregate ^ string.Compare(byName.FieldAlias, groupByField.FieldAlias) == 0))
            {
                throw new FormatException("Same aggregates on same field should have same alias.");
            }
        }
Esempio n. 8
0
        private void UpdateGroupByFieldFromColumn(GridViewDataColumn column, GridGroupByField field)
        {
            string defaultFormatString = this.defaultFormatString;

            if (string.IsNullOrEmpty(defaultFormatString) || defaultFormatString.IndexOf("{1") < 0)
            {
                defaultFormatString = this.defaultFormatString;
            }
            if (!field.IsFieldAliasSet && string.IsNullOrEmpty(column.HeaderText))
            {
                field.HeaderText = column.HeaderText;
            }
            field.FormatString = defaultFormatString;
        }
Esempio n. 9
0
 public void CopyFrom(GridGroupByExpression expression)
 {
     this.SelectFields.Clear();
     this.GroupByFields.Clear();
     foreach (GridGroupByField selectField in (Collection <GridGroupByField>)expression.SelectFields)
     {
         GridGroupByField gridGroupByField = new GridGroupByField();
         gridGroupByField.CopyFrom(selectField);
         this.SelectFields.Add(gridGroupByField);
     }
     foreach (GridGroupByField groupByField in (Collection <GridGroupByField>)expression.GroupByFields)
     {
         GridGroupByField gridGroupByField = new GridGroupByField();
         gridGroupByField.CopyFrom(groupByField);
         this.GroupByFields.Add(gridGroupByField);
     }
 }
Esempio n. 10
0
        private static void UpdateGroupByReferences(
            GridGroupByFieldCollection list,
            GridGroupByField groupByField)
        {
            GridGroupByField gridGroupByField = list.Find(groupByField.FieldName);

            if (gridGroupByField == null)
            {
                return;
            }
            groupByField.FieldName = gridGroupByField.FieldName;
            if (!gridGroupByField.IsFieldAliasSet)
            {
                return;
            }
            groupByField.FieldAlias = gridGroupByField.FieldAlias;
        }
Esempio n. 11
0
        private int ParseSelectFieldList(string fieldList, int pos)
        {
            this.clearSelectedFieldsSilently = true;
            this.SelectFields.Clear();
            this.clearSelectedFieldsSilently = false;
            if (string.IsNullOrEmpty(fieldList))
            {
                return(-1);
            }
            Match match;

            do
            {
                match = GridGroupByExpression.selectFieldParser.Match(fieldList.Substring(pos));
                if (!match.Success)
                {
                    throw new FormatException(string.Format("Cannot parse \"{0}\". Verify the correctness of the string.", (object)fieldList));
                }
                GridGroupByField groupByField = new GridGroupByField();
                if (match.Groups["fieldAlias"].Success)
                {
                    groupByField.FieldAlias = match.Groups["fieldAlias"].ToString();
                }
                if (match.Groups["aggregate"].Success)
                {
                    groupByField.SetAggregate(match.Groups["aggregate"].ToString());
                }
                groupByField.FormatString = match.Groups["formatString"].Success ? match.Groups["formatString"].ToString() : (string)null;
                if (!match.Groups["fieldName"].Success)
                {
                    throw new FormatException("Could not parse field name. Please contact Telerik support");
                }
                groupByField.FieldName = match.Groups["fieldName"].ToString();
                GridGroupByExpression.UpdateFieldNameAndAliasReferences(this.selectFields, groupByField);
                this.selectFields.Add(groupByField);
                pos += match.Length;
                if (!match.Groups["delimiter"].Success)
                {
                    throw new Exception("Delimiter (,) or Group By clause expected");
                }
            }while (match.Groups["delimiter"].Length == 1);
            return(pos);
        }
Esempio n. 12
0
        private static void UpdateReference(GridGroupByFieldCollection list, GridGroupByField ggbf)
        {
            GridGroupByField byAlias = list.FindByAlias(ggbf.FieldName);

            if (byAlias == null)
            {
                return;
            }
            if (byAlias.IsAggregate && ggbf.IsAggregate)
            {
                throw new FormatException(string.Format("Cannot create aggregate of aggregate: {0}({1}({2}))", (object)byAlias.Aggregate, (object)ggbf.Aggregate, (object)byAlias.FieldName));
            }
            ggbf.FieldName = byAlias.FieldName;
            if (!byAlias.IsAggregate)
            {
                return;
            }
            ggbf.Aggregate = byAlias.Aggregate;
        }
Esempio n. 13
0
        public GridGroupByExpression(GridViewDataColumn column)
            : this()
        {
            if (!column.AllowGroup || !column.IsDataBound)
            {
                throw new FormatException("Cannot group by this column.");
            }
            GridGroupByField   field   = new GridGroupByField();
            GridViewDataColumn column1 = column;

            if (column1 == null)
            {
                throw new FormatException("Invalid column type. Should be GridViewDataColumn or inheritor.");
            }
            field.FieldName  = column1.Name;
            field.FieldAlias = column1.HeaderText;
            this.UpdateGroupByFieldFromColumn(column1, field);
            this.SelectFields.Add(field);
            this.GroupByFields.Add(field);
        }
Esempio n. 14
0
 public virtual int ValidateFormatString()
 {
     return(GridGroupByField.ValidateFormatString(this.formatString));
 }