internal Context GetChildContext( Rdl.Engine.DataSet dataSet, Rdl.Engine.Filters filters, Rdl.Engine.Grouping grouping, List <Rdl.Engine.SortBy> sorting ) { //return new Context(this, dataSet, filters, grouping, sorting); if (_groups[_currentGroup].ChildContext == null || _groups[_currentGroup].Grouping != grouping || _groups[_currentGroup].Sorting != sorting) { Context ctxt = new Context(this, dataSet, filters, grouping, sorting); _groups[_currentGroup].ChildContext = ctxt; _groups[_currentGroup].Grouping = grouping; _groups[_currentGroup].Sorting = sorting; } _groups[_currentGroup].ChildContext.Reset(); return(_groups[_currentGroup].ChildContext); }
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; } }