Browse Source

Aggregate 'Sum' with CollectionDataSource.cs

reports
Peter Forstmeier 12 years ago
parent
commit
70199ad947
  1. 89
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs
  2. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs
  3. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs
  4. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs
  5. 10
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs
  6. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs
  7. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs
  8. 3
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs
  9. 8
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs

89
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs

@ -36,11 +36,19 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -36,11 +36,19 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
readonly PropertyDescriptorCollection listProperties;
OrderGroup orderGroup;
public CollectionDataSource(IEnumerable list, Type elementType, ReportSettings reportSettings)
{
if (list == null)
throw new ArgumentNullException("list");
if (reportSettings == null)
throw new ArgumentNullException("reportSettings");
baseList = CreateBaseList(list, elementType);
this.elementType = elementType;
this.reportSettings = reportSettings;
baseList = CreateBaseList(list, elementType);
this.listProperties = this.baseList.GetItemProperties(null);
orderGroup = OrderGroup.AsIs;
}
@ -71,31 +79,35 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -71,31 +79,35 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
}
}
public int CurrentPosition {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public int CurrentPosition {get;set;}
public object Current {get; set;}
public object Current {get; private set;}
#region Sort
public void Sort()
{
if ((reportSettings.SortColumnsCollection != null)) {
if (reportSettings.SortColumnsCollection.Count > 0) {
var s = SortInternal();
orderGroup = OrderGroup.Sorted;
listEnumerator = s.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
}
// if ((reportSettings.SortColumnsCollection != null)) {
if (reportSettings.SortColumnsCollection.Count > 0) {
var sorted = SortInternal();
orderGroup = OrderGroup.Sorted;
listEnumerator = sorted.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("sort CurrentPosition {0}",CurrentPosition);
} else {
orderGroup = OrderGroup.AsIs;
listEnumerator = baseList.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("asis CurrentPosition {0}",CurrentPosition);
}
// }
}
IEnumerable<object> SortInternal (){
@ -109,7 +121,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -109,7 +121,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
}
#endregion
#region Grouping
@ -122,6 +134,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -122,6 +134,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = groupEnumerator.Current.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("group CurrentPosition {0}",CurrentPosition);
}
@ -155,14 +169,19 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -155,14 +169,19 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
{
foreach (IPrintableObject item in collection)
{
var dbItem = item as IDataItem;
if (dbItem != null) {
dbItem.DBValue = String.Empty;
dbItem.DBValue = ReadValueFromProperty(dbItem.ColumnName);
if (String.IsNullOrEmpty(dbItem.DataType)) {
dbItem.DataType = SetTypeFromProperty(dbItem.ColumnName).ToString();
}
FillInternal(item);
}
}
void FillInternal(IPrintableObject item)
{
var dbItem = item as IDataItem;
if (dbItem != null) {
dbItem.DBValue = String.Empty;
dbItem.DBValue = ReadValueFromProperty(dbItem.ColumnName);
if (String.IsNullOrEmpty(dbItem.DataType)) {
dbItem.DataType = SetTypeFromProperty(dbItem.ColumnName).ToString();
}
}
}
@ -204,12 +223,13 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -204,12 +223,13 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return b;
}
}
*/
*/
public bool MoveNext()
{
var canMove = listEnumerator.MoveNext();
if (orderGroup == OrderGroup.Grouped) {
if (! canMove) {
var groupCanMove = groupEnumerator.MoveNext();
@ -217,13 +237,16 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -217,13 +237,16 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
listEnumerator = groupEnumerator.Current.GetEnumerator();
canMove = listEnumerator.MoveNext();
Current = listEnumerator.Current;
}
}
} else {
Current = listEnumerator.Current;
}
return canMove;
}
Current = listEnumerator.Current;
CurrentPosition = baseList.IndexOf(Current);
Console.WriteLine("CurrentPosition {0}",CurrentPosition);
return canMove;
}
@ -246,10 +269,10 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -246,10 +269,10 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
if (listAccessors != null && listAccessors.Length > 0){
var t = this.elementType;
t = listAccessors.Aggregate(t,
(current, pd) => (Type) PropertyTypeHash.Instance[current, pd.Name]);
t = listAccessors.Aggregate(t,
(current, pd) => (Type) PropertyTypeHash.Instance[current, pd.Name]);
// if t is null an empty list will be generated
// if t is null an empty list will be generated
return ExtendedTypeDescriptor.GetProperties(t);
}
return ExtendedTypeDescriptor.GetProperties(elementType);

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors @@ -21,7 +21,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
public ExpressionVisitor(ReportSettings reportSettings,CollectionSource dataSource) {
public ExpressionVisitor(ReportSettings reportSettings,CollectionDataSource dataSource) {
grammar = new ReportingLanguageGrammer();
evaluator = new ReportingExpressionEvaluator(grammar);
evaluator.AddReportSettings(reportSettings);

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs

@ -21,9 +21,9 @@ namespace ICSharpCode.Reporting.Expressions @@ -21,9 +21,9 @@ namespace ICSharpCode.Reporting.Expressions
//
readonly Collection<ExportPage> pages;
readonly ReportSettings reportSettings;
readonly CollectionSource dataSource;
readonly CollectionDataSource dataSource;
public ExpressionRunner(Collection<ExportPage> pages,ReportSettings reportSettings,CollectionSource dataSource)
public ExpressionRunner(Collection<ExportPage> pages,ReportSettings reportSettings,CollectionDataSource dataSource)
{
this.pages = pages;
this.dataSource = dataSource;

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs

@ -69,7 +69,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast @@ -69,7 +69,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
#region DataSource
public static void AddDataSource (this ReportingExpressionEvaluator app,CollectionSource dataSource){
public static void AddDataSource (this ReportingExpressionEvaluator app,CollectionDataSource dataSource){
if (dataSource == null)
throw new ArgumentNullException("dataSource");
if (!app.Globals.ContainsKey("DataSource")) {

10
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs

@ -20,8 +20,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports @@ -20,8 +20,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
/// </summary>
public static class ImportExtensions
{
public static CollectionSource GetDataSource (this ScriptThread thread){
return (CollectionSource)thread.App.Globals["DataSource"];
public static CollectionDataSource GetDataSource (this ScriptThread thread){
return (CollectionDataSource)thread.App.Globals["DataSource"];
}
}
@ -32,9 +32,9 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports @@ -32,9 +32,9 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
var fieldName = childNodes[0].Evaluate(thread).ToString();
var dataSource = thread.GetDataSource();
var curpos = dataSource.CurrentPosition;
// var curpos = dataSource.CurrentPosition;
dataSource.CurrentPosition = 0;
// dataSource.CurrentPosition = 0;
if (FieldExist(dataSource.Current,fieldName)) {
do {
@ -47,7 +47,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports @@ -47,7 +47,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
while (dataSource.MoveNext());
}
dataSource.CurrentPosition = curpos;
// dataSource.CurrentPosition = curpos;
return sum;
}

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs

@ -192,7 +192,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -192,7 +192,7 @@ namespace ICSharpCode.Reporting.PageBuilder
#region Visitors
protected void RunExpressions(ReportSettings reportsettings,CollectionSource dataSource)
protected void RunExpressions(ReportSettings reportsettings,CollectionDataSource dataSource)
{
var expressionRunner = new ExpressionRunner(Pages,reportsettings,dataSource);
expressionRunner.Run();

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs

@ -103,7 +103,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -103,7 +103,7 @@ namespace ICSharpCode.Reporting.PageBuilder
void CreateDataSource()
{
DataSource = new CollectionSource(List, ElementType, ReportModel.ReportSettings);
DataSource = new CollectionDataSource(List, ElementType, ReportModel.ReportSettings);
if (DataSourceContainsData()) {
DataSource.Bind();
}
@ -148,7 +148,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -148,7 +148,7 @@ namespace ICSharpCode.Reporting.PageBuilder
}
internal CollectionSource DataSource {get; private set;}
internal CollectionDataSource DataSource {get; private set;}
internal IEnumerable List {get; private set;}

3
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs

@ -29,15 +29,16 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -29,15 +29,16 @@ namespace ICSharpCode.Reporting.Test.DataSource
}
[Test]
public void GroupbyOneColumn () {
var rs = new ReportSettings();
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
collectionSource.Bind();
}
[Test]
public void SortOneColumnAscending() {
var ric = new System.Collections.Generic.List<IPrintableObject>(){

8
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs

@ -15,9 +15,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates @@ -15,9 +15,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
{
Collection<ExportText> collection;
AggregateCollection agc;
AggregateCollection aggregateCollection;
AggregateFuctionHelper helper;
CollectionSource dataSource;
CollectionDataSource dataSource;
[Test]
@ -56,8 +56,8 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates @@ -56,8 +56,8 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
});
helper = new AggregateFuctionHelper();
agc = helper.AggregateCollection;
dataSource = new CollectionSource(agc,typeof(Aggregate),new ReportSettings());
aggregateCollection = helper.AggregateCollection;
dataSource = new CollectionDataSource(aggregateCollection,typeof(Aggregate),new ReportSettings());
dataSource.Bind();
}

Loading…
Cancel
Save