diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj index 042bd54059..80c6d95cdd 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj @@ -132,7 +132,7 @@ - + diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs index 5f4ab7c6d7..3819e3c3bb 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling Sorted, Grouped } - public class CollectionDataSource:IDataViewHandling + public class CollectionDataSource:IDataSource { @@ -36,7 +36,22 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling readonly PropertyDescriptorCollection listProperties; OrderGroup orderGroup; + public CollectionDataSource(IEnumerable list, ReportSettings reportSettings) + { + if (list == null) + throw new ArgumentNullException("list"); + if (reportSettings == null) + throw new ArgumentNullException("reportSettings"); + baseList = CreateBaseList(list); + CurrentList = baseList; + + this.reportSettings = reportSettings; + this.listProperties = this.baseList.GetItemProperties(null); + orderGroup = OrderGroup.AsIs; + } + + [Obsolete("use public CollectionDataSource(IEnumerable list, ReportSettings reportSettings")] public CollectionDataSource(IEnumerable list, Type elementType, ReportSettings reportSettings) { if (list == null) @@ -44,8 +59,8 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling if (reportSettings == null) throw new ArgumentNullException("reportSettings"); - baseList = CreateBaseList(list, elementType); - //test + baseList = CreateBaseList(list); + CurrentList = baseList; this.elementType = elementType; @@ -57,13 +72,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling - public IndexList IndexList { - get { - throw new NotImplementedException(); - } - } - - public Collection AvailableFields { get { var availableFields = new Collection(); @@ -73,23 +81,23 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling return availableFields; } } - //test + public IList CurrentList {get;private set;} + public int Count { get { return baseList.Count; } } - public int CurrentPosition {get;set;} + public object Current {get; private set;} - public object Current {get; set;} #region Sort - public void Sort() + void Sort() { if (reportSettings.SortColumnsCollection.Count > 0) { var sorted = SortInternal(); @@ -97,15 +105,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling 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); } } @@ -125,7 +129,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling #region Grouping - public void Group() + void Group() { orderGroup = OrderGroup.Grouped; groupedList = GroupInternal(); @@ -134,8 +138,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling listEnumerator = groupEnumerator.Current.GetEnumerator(); listEnumerator.MoveNext(); Current = listEnumerator.Current; - CurrentPosition = baseList.IndexOf(Current); - Console.WriteLine("group CurrentPosition {0}",CurrentPosition); } @@ -198,32 +200,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling return p.PropertyType; } - /* - public bool MoveNext() - { - - if (orderGroup == OrderGroup.Grouped) { - var canMove = listEnumerator.MoveNext(); - if (! canMove) { - var groupCanMove = groupEnumerator.MoveNext(); - if (groupCanMove) { - listEnumerator = groupEnumerator.Current.GetEnumerator(); - canMove = listEnumerator.MoveNext(); - Current = listEnumerator.Current; - } else { - Console.WriteLine("end"); - } - } else { - Current = listEnumerator.Current; - } - return canMove; - } else { - var b = listEnumerator.MoveNext(); - Current = listEnumerator.Current; - return b; - } - } - */ public bool MoveNext() { @@ -245,38 +221,18 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling } Current = listEnumerator.Current; - CurrentPosition = baseList.IndexOf(Current); - Console.WriteLine("CurrentPosition {0}",CurrentPosition); return canMove; } #endregion - public void Reset() - { - throw new NotImplementedException(); - } - static DataCollection CreateBaseList(IEnumerable source, Type elementType) + static DataCollection CreateBaseList(IEnumerable source) { - var list = new DataCollection(elementType); + Type et = source.AsQueryable().ElementType; + var list = new DataCollection(et); list.AddRange(source); return list; } - - /* - PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){ - if (listAccessors != null && listAccessors.Length > 0){ - var t = this.elementType; - - t = listAccessors.Aggregate(t, - (current, pd) => (Type) PropertyTypeHash.Instance[current, pd.Name]); - - // if t is null an empty list will be generated - return ExtendedTypeDescriptor.GetProperties(t); - } - return ExtendedTypeDescriptor.GetProperties(elementType); - } - */ } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs index f270230466..9d50e189d7 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.DataSource; +using ICSharpCode.Reporting.Interfaces.Data; using Irony.Interpreter; using Irony.Interpreter.Ast; @@ -14,8 +15,8 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports /// public static class ImportExtensions { - public static CollectionDataSource GetDataSource (this ScriptThread thread){ - return (CollectionDataSource)thread.App.Globals["DataSource"]; + public static IDataSource GetDataSource (this ScriptThread thread){ + return (IDataSource)thread.App.Globals["DataSource"]; } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataViewHandling.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs similarity index 54% rename from src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataViewHandling.cs rename to src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs index acc5ce5fc0..a8047dfb8b 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataViewHandling.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs @@ -19,35 +19,16 @@ namespace ICSharpCode.Reporting.Interfaces.Data /// /// Description of IDataViewHandling. /// - public interface IDataViewHandling:IEnumerator{ - - void Sort (); - - void Group(); + public interface IDataSource{ void Bind(); -// void Fill (int position,ReportItemCollection collection); - - //rausnehmen -// void Fill (List items); void Fill(List collection); -// void Fill(ReportItemCollection collection); - - IndexList IndexList {get;} - -// object CurrentFromPosition(int pos); - -// CurrentItemsCollection FillDataRow(); -// CurrentItemsCollection FillDataRow(int pos); - // Collection AvailableFields {get;} - + IList CurrentList {get;} int Count {get;} - - int CurrentPosition {get;set;} - -// IExpressionEvaluatorFacade ExpressionEvaluator {get;} + + object Current {get;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs index 91331c10e1..d3907ec83c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs @@ -27,10 +27,9 @@ namespace ICSharpCode.Reporting.PageBuilder public class DataPageBuilder:BasePageBuilder { - public DataPageBuilder(IReportModel reportModel, Type elementType,IEnumerable list):base(reportModel) + public DataPageBuilder(IReportModel reportModel,IEnumerable list):base(reportModel) { List = list; - ElementType = elementType; } @@ -101,14 +100,16 @@ namespace ICSharpCode.Reporting.PageBuilder } } + void CreateDataSource() { - DataSource = new CollectionDataSource(List, ElementType, ReportModel.ReportSettings); + DataSource = new CollectionDataSource(List, ReportModel.ReportSettings); if (DataSourceContainsData()) { DataSource.Bind(); } } + bool DataSourceContainsData () { if (DataSource.Count > 0) { return true; @@ -154,6 +155,5 @@ namespace ICSharpCode.Reporting.PageBuilder protected IReportContainer CurrentSection { get; private set; } - protected Type ElementType {get;private set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs index 3082f850e0..2a4eecde70 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs @@ -24,12 +24,20 @@ namespace ICSharpCode.Reporting public class ReportingFactory { + public IReportCreator ReportCreator (Stream stream,IEnumerable list) + { + ReportModel = LoadReportModel (stream); + IReportCreator builder = null; + builder = new DataPageBuilder(ReportModel,list ); + return builder; + } + [Obsolete("Use public IReportCreator ReportCreator (Stream stream,IEnumerable list")] public IReportCreator ReportCreator (Stream stream,Type listType,IEnumerable list) { ReportModel = LoadReportModel (stream); IReportCreator builder = null; - builder = new DataPageBuilder(ReportModel,listType,list ); + builder = new DataPageBuilder(ReportModel,list ); return builder; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs index cf6da058b8..fa8a3ab43c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs @@ -17,14 +17,14 @@ namespace ICSharpCode.Reporting.Test.DataSource [Test] public void CollectionCountIsEqualToListCount() { - var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings()); + var collectionSource = new CollectionDataSource (list,new ReportSettings()); Assert.That(collectionSource.Count,Is.EqualTo(list.Count)); } [Test] public void AvailableFieldsEqualContibutorsPropertyCount() { - var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings()); + var collectionSource = new CollectionDataSource (list,new ReportSettings()); Assert.That(collectionSource.AvailableFields.Count,Is.EqualTo(6)); } @@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Test.DataSource public void GroupbyOneColumn () { var rs = new ReportSettings(); rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); - var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs); + var collectionSource = new CollectionDataSource (list,rs); collectionSource.Bind(); } @@ -50,7 +50,7 @@ namespace ICSharpCode.Reporting.Test.DataSource ColumnName = "Firstname" } }; - var collectionSource = new CollectionDataSource (list,typeof(Contributor),new ReportSettings()); + var collectionSource = new CollectionDataSource (list,new ReportSettings()); collectionSource.Bind(); collectionSource.Fill(ric); foreach (BaseDataItem element in ric) { @@ -75,7 +75,7 @@ namespace ICSharpCode.Reporting.Test.DataSource var rs = new ReportSettings(); rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending)); - var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs); + var collectionSource = new CollectionDataSource (list,rs); collectionSource.Bind(); string compare = String.Empty; int i = 0; @@ -117,7 +117,7 @@ namespace ICSharpCode.Reporting.Test.DataSource rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); rs.GroupColumnCollection.Add( new GroupColumn("RandomInt",1,ListSortDirection.Ascending)); - var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs); + var collectionSource = new CollectionDataSource (list,rs); collectionSource.Bind(); int i = 0; do { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs index 5d239dca0b..c3c5d89983 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs @@ -57,7 +57,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates helper = new AggregateFuctionHelper(); aggregateCollection = helper.AggregateCollection; - dataSource = new CollectionDataSource(aggregateCollection,typeof(Aggregate),new ReportSettings()); + dataSource = new CollectionDataSource(aggregateCollection,new ReportSettings()); dataSource.Bind(); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs index 31db3abb8a..77e857bf32 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/PushModelFixture.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory [Test] public void DataSourceIsSet() { - var dataPageBuilder = new DataPageBuilder (new ReportModel(),typeof(string),new System.Collections.Generic.List()); + var dataPageBuilder = new DataPageBuilder (new ReportModel(),new System.Collections.Generic.List()); Assert.That(dataPageBuilder.List,Is.Not.Null); } @@ -41,7 +41,6 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory public void CanInitDataPageBuilder() { var dpb = new DataPageBuilder (new ReportModel(), - typeof(string), new System.Collections.Generic.List()); Assert.That(dpb,Is.Not.Null); } @@ -158,7 +157,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory var reportingFactory = new ReportingFactory(); var model = reportingFactory.LoadReportModel (stream); - reportCreator = new DataPageBuilder(model,typeof(string),new List()); + reportCreator = new DataPageBuilder(model,new List()); reportCreator.BuildExportList(); Assert.That(reportCreator.Pages[0].ExportedItems.Count,Is.EqualTo(4)); } @@ -175,7 +174,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory var reportingFactory = new ReportingFactory(); var model = reportingFactory.LoadReportModel (stream); - reportCreator = new DataPageBuilder(model,typeof(Contributor),list); + reportCreator = new DataPageBuilder(model,list); } } }