예제 #1
0
        private object GetIncrementalModeSummary(XtraReport report)
        {
            if (effectiveOwner == null)
            {
                Reset();
            }

            var dataContext = get_DataContext(report);
            var browser     = (ListBrowser)dataContext.GetDataBrowser(DataSource ?? report.DataSource, DataMember, false);

            if (browser == null)
            {
                return(null);
            }

            SortedListController listController;

            if (OverrideFilter != null)
            {
                if (unfilteredListController == null || unfilteredListControllerList != browser.List)
                {
                    unfilteredListControllerList = browser.List;
                    unfilteredListController     = new CustomSortedListController();
                    unfilteredListController.SetList(browser.List);
                    unfilteredListController.SetBrowser(browser);
                    unfilteredListController.Initialize(
                        ((SortedListController)browser.ListController).GetOriginalGroupFields(),
                        ((SortedListController)browser.ListController).GetSortingSummary(),
                        GetFilterCriteria(report, OverrideFilter));
                }
                listController = unfilteredListController;
            }
            else
            {
                listController = (SortedListController)browser.ListController;
            }


            if (effectiveOwner == null)
            {
                effectiveOwner              = Running ?? report;
                effectiveOwner.BeforePrint += effectiveOwner_BeforePrint;

                report.BeforePrint -= Report_BeforePrint;
                report.BeforePrint += Report_BeforePrint;
            }

            var currentListSource = listController.GetDataController().ListSource;

            if (lastCollection != currentListSource)
            {
                lastPosition   = -1;
                lastCollection = currentListSource;
            }

            int currentPosition;

            if (listController == browser.ListController)
            {
                currentPosition = browser.Position;
                if (currentPosition < lastPosition) // Charting doubles back
                {
                    lastPosition = -1;
                    Reset();
                }
            }
            else
            {
                currentPosition = -1;
                for (var i = 0; i < listController.Count; i++)
                {
                    if (listController.GetItem(i) == browser.Current)
                    {
                        currentPosition = i;
                        break;
                    }
                }
            }

            while (lastPosition < currentPosition)
            {
                lastPosition++;
                if (expressionEvaluator == null)
                {
                    expressionEvaluator = new ExpressionEvaluator(new CalculatedEvaluatorContextDescriptor(report.Parameters, this, dataContext), CriteriaOperator.TryParse(Expression));
                }
                AddSummaryValue(expressionEvaluator.Evaluate(listController.GetItem(lastPosition)), lastPosition);
            }

            return(GetCurrentSummaryResult());
        }
예제 #2
0
 private void Reset()
 {
     unfilteredListController     = null;
     unfilteredListControllerList = null;
     reset(summary);
 }
예제 #3
0
        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.Parse(Expression));
            }

            var isOverridingFilter = !string.IsNullOrWhiteSpace(OverrideFilter);

            if (isOverridingFilter && overrideFilterEvaluator == null)
            {
                isImmediateSummaryValid = false;
                overrideFilterEvaluator = new ExpressionEvaluator(new CalculatedEvaluatorContextDescriptor(report.Parameters, this, dataContext), GetFilterCriteria(report, 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))
                {
                    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(originalBrowser.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)))
                        {
                            AddSummaryValue(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)))
                            {
                                AddSummaryValue(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        = GetCurrentSummaryResult();
            isImmediateSummaryValid = true;
            return(immediateSummary);
        }