Exemple #1
0
        /// <summary>
        /// Handles <see cref="INotifyCollectionChanged.CollectionChanged"/> event of the parent collection.
        /// </summary>
        /// <param name="groupRecord">The group.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The event arguments.</param>
        private static void OnParentCollectionChanged(GroupRecord groupRecord, object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Add)
            {
                if (groupRecord.ParentGroup == null)
                    return;

                var newValue = args.NewItems[0] as GroupRecord;
                if (newValue != null)
                {
                    var parentGroup = ((IGroup) groupRecord._groupInfo.Target).ParentGroup;
                    if (ReferenceEquals(parentGroup, newValue._groupInfo.Target))
                        groupRecord.ParentRecord = newValue;
                }
            }
            else if (args.Action == NotifyCollectionChangedAction.Remove)
            {
                var oldValue = args.OldItems[0] as GroupRecord;
                if (oldValue != null && ReferenceEquals(oldValue, groupRecord))
                    groupRecord.DetachParentCollection();
            }
            else if (args.Action == NotifyCollectionChangedAction.Reset)
            {
                groupRecord.DetachParentCollection();
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates aggregate result collection of the group on
        /// <see cref="INotifyCollectionChanged.CollectionChanged"/> event.
        /// </summary>
        /// <param name="groupRecord">The group.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The event arguments.</param>
        private static void OnAggregateResultsCollectionChanged(GroupRecord groupRecord, object sender, NotifyCollectionChangedEventArgs args)
        {
            if (!groupRecord.IsAttached || 
                (!groupRecord.IsExpanded && !groupRecord.IsPopulated))
                return;

            var group = groupRecord._groupInfo.Target as QueryableCollectionViewGroup;
            if (group == null)
                return;

            if (args.Action == NotifyCollectionChangedAction.Remove)
            {
                var oldItem = (AggregateResult)args.OldItems[0];
                var aggregateResult = group.AggregateResults.FirstOrDefault(x => x.FunctionName == oldItem.FunctionName);
                if (aggregateResult != null)
                    group.AggregateResults.Remove(aggregateResult);
            }
            else if (args.Action == NotifyCollectionChangedAction.Reset)
            {
                var collection = sender as Telerik.Windows.Data.AggregateResultCollection;
                var gridAggregates = collection.Select(x => x.FunctionName).ToList();
                var groupAggregates = group.AggregateResults.Select(x => x.FunctionName).ToList();

                var oddFunctions = new List<string>();
                if (gridAggregates.Count > groupAggregates.Count)
                {
                    oddFunctions = gridAggregates.Except(groupAggregates).ToList();
                }
                else if (groupAggregates.Count > gridAggregates.Count)
                {
                    oddFunctions = groupAggregates.Except(gridAggregates).ToList();
                }

                if (oddFunctions.Any())
                {
                    var aggregateFunctions =
                        ((GridViewColumn)groupRecord._column.Target).DataControl.Columns
                            .SelectMany<GridViewColumn, AggregateFunction>(x => x.AggregateFunctions)
                            .ToDictionary(x => x.FunctionName, x => x);

                    foreach (var functionName in oddFunctions)
                    {
                        var aggregateResult = group.AggregateResults.FirstOrDefault(x => x.FunctionName == functionName);
                        if (aggregateResult != null)
                        {
                            group.AggregateResults.Remove(aggregateResult);
                        }
                        else
                        {
                            var function = aggregateFunctions[functionName];
                            var result = new Veyron.SharedTypes.AggregateResult
                            {
                                ColumnName = AggregateHelper.GetColumnNameByFunctionName(functionName),
                                SummaryType = AggregateHelper.GetAggregationTypeByFunctionName(functionName),
                                Value = Constants.AggregateCalculatingPlaceHolder.ToString()
                            };

                            AddAggregateResult(group, result, function);
                        }
                    }
                }
            }

            groupRecord._aggregateResults = group.AggregateResults.ToList();

            groupRecord.RefreshGroupFooter();
        }
 public static void SetGroupRecordInfo(UIElement element, GroupRecord value)
 {
     if (element != null)
         element.SetValue(GroupRecordInfoProperty, value);
 }
Exemple #4
0
        /// <summary>
        /// Performs transfer of values of some properties from one instance to another.
        /// </summary>
        /// <param name="group">The source group.</param>
        /// <exception cref="ArgumentNullException">
        /// When <paramref name="group"/> is null.</exception>
        public void Merge(GroupRecord group)
        {
            if (group == null)
                throw new ArgumentNullException("group");

            IsPopulated = group.IsPopulated;

            if (IsPopulated)
                _containsGroupItems = false;

            if (!_containsGroupItems)
            {
                TotalItemsCount = group.TotalItemsCount;
                TotalDataItemsCount = group.TotalDataItemsCount;
                IsBlocked = group.IsBlocked;
            }

            CurrentPageNumber = group.CurrentPageNumber;
            IsExpanded = group.IsExpanded;

            if (IsPopulated && group._aggregateResults != null)
            {
                _aggregateResults = group._aggregateResults;

                var groupAggregateResults = ((QueryableCollectionViewGroup)_groupInfo.Target).AggregateResults;
                groupAggregateResults.Clear();

                group._aggregateResults.ForEach(
                    r => groupAggregateResults.Add(r));

                RefreshGroupFooter();
            }
        }
 public GroupRecordPageChanged(GroupRecord record)
 {
     GroupRecord = record;
 }