Пример #1
0
        private int CompareForGroupSort(GroupEntry ge1, GroupEntry ge2)
        {
            foreach (Rdl.Engine.SortBy sortBy in _sorting)
            {
                _rows       = ge1.Rows;
                _currentRow = _rows[0];
                object obj1 = sortBy.Expression.Exec(this);
                _rows       = ge2.Rows;
                _currentRow = _rows[0];
                object obj2 = sortBy.Expression.Exec(this);

                int ret = Compare.CompareTo(obj1, obj2);
                if (ret != 0)
                {
                    if (sortBy.Direction == Rdl.Engine.SortBy.SortDirection.Descending)
                    {
                        ret = 0 - ret;
                    }
                    return(ret);
                }
            }
            return(0);
        }
Пример #2
0
        public Context Intersect(Context ctxt)
        {
            Context newCtxt = new Context();

            newCtxt._parentContext   = this;
            newCtxt._currentPosition = 0;
            newCtxt._dataSet         = _dataSet;

            newCtxt._rows = new List <System.Data.DataRow>();

            foreach (System.Data.DataRow row in _rows)
            {
                if (ctxt._rows.Contains(row))
                {
                    newCtxt._rows.Add(row);
                }
            }

            GroupEntry ge = new GroupEntry();

            ge.Rows = newCtxt._rows;
            newCtxt._groups.Add(ge);

            newCtxt._currentGroup    = 0;
            newCtxt._rows            = newCtxt._groups[0].Rows;
            newCtxt._currentPosition = 0;
            if (newCtxt._rows.Count > 0)
            {
                newCtxt._currentRow = newCtxt._rows[0];
            }
            else
            {
                newCtxt._currentRow = null;
            }

            return(newCtxt);
        }
Пример #3
0
        internal Context(Context parentContext,
                         Rdl.Engine.DataSet dataSet,
                         Rdl.Engine.Filters filters,
                         Rdl.Engine.Grouping grouping,
                         List <Rdl.Engine.SortBy> sorting
                         )
        {
            _parentContext   = parentContext;
            _filters         = filters;
            _grouping        = grouping;
            _sorting         = sorting;
            _currentPosition = 0;

            _rows = new List <System.Data.DataRow>();

            // Load the datarows into the context
            if (dataSet != null)
            {
                _dataSet = dataSet;
                if (parentContext == null)
                {
                    foreach (System.Data.DataRow row in dataSet.GetTable(this).Rows)
                    {
                        TestAddRow(row);
                    }
                }
                else
                {
                    foreach (System.Data.DataRow row in parentContext.Rows)
                    {
                        TestAddRow(row);
                    }
                }
            }
            else if (parentContext != null)
            {
                _dataSet = parentContext._dataSet;
                foreach (System.Data.DataRow row in parentContext._rows)
                {
                    TestAddRow(row);
                }
            }

            if (_grouping != null && _rows.Count > 0)
            {
                // Sort the row list by the group expression
                _rows.Sort(CompareForGroup);

                // Build a list of group members for each group instance
                _groups.Add(new GroupEntry());
                _currentGroup = 0;
                System.Data.DataRow lastRow = null;
                foreach (System.Data.DataRow row in _rows)
                {
                    if (lastRow != null)
                    {
                        if (CompareForGroup(lastRow, row) != 0)
                        {
                            _currentGroup++;
                            _groups.Add(new GroupEntry());
                        }
                    }
                    _groups[_currentGroup].Rows.Add(row);
                    lastRow = row;
                }

                if (_grouping.Filters != null)
                {
                    _groupFilter = _grouping.Filters.GroupFilter;
                }
            }
            else if (_rows.Count > 0)
            {
                GroupEntry ge = new GroupEntry();
                ge.Rows = _rows;
                _groups.Add(ge);
            }

            // Remove rows not matching the group filter operator.
            if (_groupFilter != null)
            {
                foreach (GroupEntry ge in _groups)
                {
                    List <System.Data.DataRow> rows = ge.Rows;

                    // Sort the list or rows based on the count expression.
                    rows.Sort(CompareForGroupFilter);
                    Int32 ct = 0;
                    float v  = 0;
                    if (_groupFilter.Operator == Rdl.Engine.Filter.FilterOperator.TopN ||
                        _groupFilter.Operator == Rdl.Engine.Filter.FilterOperator.BottomN)
                    {
                        Int32.TryParse(_groupFilter.GroupValue.ToString(), out ct);
                    }

                    if (_groupFilter.Operator == Rdl.Engine.Filter.FilterOperator.TopPercent ||
                        _groupFilter.Operator == Rdl.Engine.Filter.FilterOperator.BottomPercent)
                    {
                        float.TryParse(_groupFilter.GroupValue.ToString(), out v);
                        ct = (Int32)((float)rows.Count * v / 100F);
                    }
                    if (ct < rows.Count)
                    {
                        rows.RemoveRange(0, ct);
                    }
                }
            }

            // Sort the resulting lists according to the sort expressions.
            if (_sorting != null && _sorting.Count > 0)
            {
                _groups.Sort(CompareForGroupSort);
                for (_currentGroup = 0; _currentGroup < _groups.Count; _currentGroup++)
                {
                    _groups[_currentGroup].Rows.Sort(CompareForSort);
                }
            }

            _currentGroup = 0;
            if (_groups.Count > 0)
            {
                _rows = _groups[0].Rows;
            }
            else
            {
                _rows = new List <System.Data.DataRow>();
            }
            _currentPosition = 0;
            if (_rows.Count > 0)
            {
                _currentRow = _rows[0];
            }
            else
            {
                _currentRow = null;
            }
        }