示例#1
0
 private object GetCurrentSummaryResult()
 {
     return(get_ValuesInfo(summary).Cast <Pair <object, int> >().All(p => p.First == null) ? null :
            ConvertToType(summary.GetResult(), FieldTypeConverter.ToType(FieldType)));
 }
        private object GetImmediateModeSummary(XtraReport report)
        {
            report.AfterPrint -= report_AfterPrint;
            report.AfterPrint += report_AfterPrint;

            var dataContext = get_DataContext(report);

            if (expressionEvaluator == null)
            {
                isImmediateSummaryValid = false;
                expressionEvaluator     = new ExpressionEvaluator(new CalculatedEvaluatorContextDescriptor(report.Parameters, this, dataContext), CriteriaOperator.TryParse(Expression));
            }

            var isOverridingFilter = !string.IsNullOrWhiteSpace(OverrideFilter);

            if (isOverridingFilter && overrideFilterEvaluator == null)
            {
                isImmediateSummaryValid = false;
                overrideFilterEvaluator = new ExpressionEvaluator(new CalculatedEvaluatorContextDescriptor(report.Parameters, this, dataContext), CriteriaOperator.TryParse(OverrideFilter));
            }


            reset(summary);

            var dg = GetCurrentDataGroup(dataContext, Running ?? report);

            if (isImmediateSummaryValid && !dg.Equals(lastDataGroupInfo))
            {
                isImmediateSummaryValid = false;
            }
            lastDataGroupInfo = dg;

            if (isImmediateSummaryValid)
            {
                return(immediateSummary);
            }

            if (dg != null)
            {
                if (dg.Value.DataSource != (DataSource ?? report.DataSource))
                {
                    throw new EndUserConfigurationException($"The running band on summary field {Name} does not have the same data Source as the summary field. Otherwise, it is not able to be correlated with the summary field.");
                }
                if (!DataMemberUtils.AreEqual(DataMember, dg.Value.DataMember) && (!DataMemberUtils.IsAncestor(dg.Value.DataMember, DataMember) || string.IsNullOrEmpty(dg.Value.DataMember)))
                {
                    throw new EndUserConfigurationException($"The running band on summary field {Name} must have the same data member or must be a parent data member. Otherwise, it is not able to be correlated with the summary field.");
                }

                var groupListBrowser = dg.Value.ListBrowser;
                var childBrowsers    = DataMemberUtils.GetChildBrowsers(dataContext, dg.Value.DataSource, dg.Value.DataMember, DataMember);

                var groupStart    = dg.Value.GroupRowInfo == null ? 0 : dg.Value.GroupRowInfo.ChildControllerRow;
                var groupRowCount = dg.Value.GroupRowInfo == null ? groupListBrowser.Count : dg.Value.GroupRowInfo.ChildControllerRowCount;

                if (isOverridingFilter)
                {
                    var originalBrowser        = childBrowsers.Length == 0 ? groupListBrowser : childBrowsers[childBrowsers.Length - 1];
                    var originalBrowserAsChild = originalBrowser as IRelatedDataBrowser;

                    var newListController = new CustomSortedListController();
                    newListController.SetList(originalBrowser.List);
                    var newBrowser = originalBrowserAsChild != null
                        ? (ListBrowser) new CustomRelatedListBrowser((DataBrowser)originalBrowserAsChild.Parent, originalBrowserAsChild.RelatedProperty, newListController, false)
                        : new CustomListBrowser(originalBrowser.DataSource, newListController, false);
                    ((IPropertiesContainer)newBrowser).SetCustomProperties(originalBrowser.GetItemProperties().OfType <CalculatedPropertyDescriptorBase>().Cast <PropertyDescriptor>().ToArray());
                    newListController.SetBrowser(newBrowser);

                    // Filter outside the list controller so that we can ascertain grouping for rows the override filter excludes
                    newListController.Initialize(
                        ((SortedListController)originalBrowser.ListController).GetOriginalGroupFields(),
                        ((SortedListController)originalBrowser.ListController).GetSortingSummary(),
                        null);

                    if (childBrowsers.Length == 0)
                    {
                        groupListBrowser = newBrowser;
                        if (dg.Value.GroupRowInfo != null)
                        {
                            var currentListSourceIndex    = ((SortedListController)originalBrowser.ListController).GetDataController().GetListSourceRowIndex(originalBrowser.Position);
                            var currentPositionNewBrowser = newListController.GetDataController().GetControllerRow(currentListSourceIndex);
                            var newGroupInfo = DataGroupingUtils.GetGroupInfo(newBrowser, dg.Value.GroupRowInfo.Level, currentPositionNewBrowser);
                            groupStart    = newGroupInfo.ChildControllerRow;
                            groupRowCount = newGroupInfo.ChildControllerRowCount;
                        }
                        else
                        {
                            groupStart    = 0;
                            groupRowCount = newBrowser.Count;
                        }
                    }
                    else
                    {
                        childBrowsers[childBrowsers.Length - 1] = (RelatedListBrowser)newBrowser;
                    }
                }

                if (childBrowsers.Length == 0)
                {
                    for (var i = 0; i < groupRowCount; i++)
                    {
                        var currentRow = groupListBrowser.GetRow(i + groupStart);
                        if (!isOverridingFilter || ConvertOverrideFilterResult(overrideFilterEvaluator.Evaluate(currentRow)))
                        {
                            addValue(summary, expressionEvaluator.Evaluate(currentRow), i);
                        }
                    }
                }
                else
                {
                    var state = dataContext.SaveState();
                    try
                    {
                        groupListBrowser.Position = groupStart;
                        var sampleIndex = 0;
                        foreach (var childBrowser in childBrowsers)
                        {
                            childBrowser.Position = 0;
                        }

                        while (true)
                        {
                            var currentIndex   = childBrowsers.Length - 1;
                            var currentBrowser = childBrowsers[currentIndex];
                            if (!isOverridingFilter || ConvertOverrideFilterResult(overrideFilterEvaluator.Evaluate(currentBrowser.Current)))
                            {
                                addValue(summary, expressionEvaluator.Evaluate(currentBrowser.Current), sampleIndex);
                            }
                            sampleIndex++;

                            while (currentIndex > 0 && currentBrowser.Position == currentBrowser.Count - 1)
                            {
                                currentBrowser.Position = 0;
                                currentIndex--;
                                currentBrowser = childBrowsers[currentIndex];
                            }

                            if (currentBrowser.Position == currentBrowser.Count - 1)
                            {
                                if (groupListBrowser.Position == groupStart + groupRowCount - 1)
                                {
                                    break;
                                }
                                groupListBrowser.Position++;
                            }
                            else
                            {
                                currentBrowser.Position++;
                            }
                        }
                    }
                    finally
                    {
                        dataContext.LoadState(state);
                    }
                }
            }

            immediateSummary        = get_ValuesInfo(summary).Cast <Pair <object, int> >().All(p => p.First == null) ? null : summary.GetResult();
            isImmediateSummaryValid = true;
            return(immediateSummary);
        }