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

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

@ -21,9 +21,9 @@ namespace ICSharpCode.Reporting.Expressions
// //
readonly Collection<ExportPage> pages; readonly Collection<ExportPage> pages;
readonly ReportSettings reportSettings; 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.pages = pages;
this.dataSource = dataSource; 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
#region DataSource #region DataSource
public static void AddDataSource (this ReportingExpressionEvaluator app,CollectionSource dataSource){ public static void AddDataSource (this ReportingExpressionEvaluator app,CollectionDataSource dataSource){
if (dataSource == null) if (dataSource == null)
throw new ArgumentNullException("dataSource"); throw new ArgumentNullException("dataSource");
if (!app.Globals.ContainsKey("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
/// </summary> /// </summary>
public static class ImportExtensions public static class ImportExtensions
{ {
public static CollectionSource GetDataSource (this ScriptThread thread){ public static CollectionDataSource GetDataSource (this ScriptThread thread){
return (CollectionSource)thread.App.Globals["DataSource"]; return (CollectionDataSource)thread.App.Globals["DataSource"];
} }
} }
@ -32,9 +32,9 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
var fieldName = childNodes[0].Evaluate(thread).ToString(); var fieldName = childNodes[0].Evaluate(thread).ToString();
var dataSource = thread.GetDataSource(); var dataSource = thread.GetDataSource();
var curpos = dataSource.CurrentPosition; // var curpos = dataSource.CurrentPosition;
dataSource.CurrentPosition = 0; // dataSource.CurrentPosition = 0;
if (FieldExist(dataSource.Current,fieldName)) { if (FieldExist(dataSource.Current,fieldName)) {
do { do {
@ -47,7 +47,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
while (dataSource.MoveNext()); while (dataSource.MoveNext());
} }
dataSource.CurrentPosition = curpos; // dataSource.CurrentPosition = curpos;
return sum; return sum;
} }

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

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

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

@ -103,7 +103,7 @@ namespace ICSharpCode.Reporting.PageBuilder
void CreateDataSource() void CreateDataSource()
{ {
DataSource = new CollectionSource(List, ElementType, ReportModel.ReportSettings); DataSource = new CollectionDataSource(List, ElementType, ReportModel.ReportSettings);
if (DataSourceContainsData()) { if (DataSourceContainsData()) {
DataSource.Bind(); DataSource.Bind();
} }
@ -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;} 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
} }
[Test] [Test]
public void GroupbyOneColumn () { public void GroupbyOneColumn () {
var rs = new ReportSettings(); var rs = new ReportSettings();
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs); var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
collectionSource.Bind(); collectionSource.Bind();
} }
[Test] [Test]
public void SortOneColumnAscending() { public void SortOneColumnAscending() {
var ric = new System.Collections.Generic.List<IPrintableObject>(){ 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
{ {
Collection<ExportText> collection; Collection<ExportText> collection;
AggregateCollection agc; AggregateCollection aggregateCollection;
AggregateFuctionHelper helper; AggregateFuctionHelper helper;
CollectionSource dataSource; CollectionDataSource dataSource;
[Test] [Test]
@ -56,8 +56,8 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
}); });
helper = new AggregateFuctionHelper(); helper = new AggregateFuctionHelper();
agc = helper.AggregateCollection; aggregateCollection = helper.AggregateCollection;
dataSource = new CollectionSource(agc,typeof(Aggregate),new ReportSettings()); dataSource = new CollectionDataSource(aggregateCollection,typeof(Aggregate),new ReportSettings());
dataSource.Bind(); dataSource.Bind();
} }

Loading…
Cancel
Save