Browse Source

Sort by One Column

reports
Peter Forstmeier 12 years ago
parent
commit
84b08f54da
  1. 103
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs
  2. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj
  3. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/CollectionHandlingFixture.cs
  4. 33
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs

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

@ -21,19 +21,28 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -21,19 +21,28 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
/// <summary>
/// Description of DataSource.
/// </summary>
enum OrderGroup {
AsIs,
Sorted,
Grouped
}
public class CollectionDataSource:IDataViewHandling
{
readonly DataCollection<object> baseList;
readonly ReportSettings reportSettings;
readonly Type elementType;
readonly PropertyDescriptorCollection listProperties;
OrderGroup orderGroup;
public CollectionDataSource(IEnumerable list, Type elementType, ReportSettings reportSettings)
{
this.elementType = elementType;
this.reportSettings = reportSettings;
baseList = CreateBaseList(list, elementType);
this.listProperties = this.baseList.GetItemProperties(null);
orderGroup = OrderGroup.AsIs;
}
@ -45,7 +54,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -45,7 +54,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
}
public System.Collections.ObjectModel.Collection<ICSharpCode.Reporting.BaseClasses.AbstractColumn> AvailableFields {
public Collection<AbstractColumn> AvailableFields {
get {
var availableFields = new Collection<AbstractColumn>();
foreach (PropertyDescriptor p in this.listProperties){
@ -73,17 +82,40 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -73,17 +82,40 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
public object Current {get; private set;}
#region Sort
public void Sort()
{
throw new NotImplementedException();
if ((reportSettings.SortColumnsCollection != null)) {
if (reportSettings.SortColumnsCollection.Count > 0) {
var s = SortInternal();
orderGroup = OrderGroup.Sorted;
listEnumerator = s.GetEnumerator();
listEnumerator.MoveNext();
Current = listEnumerator.Current;
}
}
}
IEnumerable<object> SortInternal (){
IEnumerable<object> sortedList = null;
var sortProperty = listProperties.Find(reportSettings.SortColumnsCollection[0].ColumnName,true);
if(reportSettings.SortColumnsCollection.Count == 1) {
sortedList = baseList.OrderBy(o => o.GetType().GetProperty(sortProperty.Name).GetValue(o, null) );
}
return sortedList;
}
#endregion
#region Grouping
public void Group()
{
orderGroup = OrderGroup.Grouped;
groupedList = GroupInternal();
groupEnumerator = groupedList.GetEnumerator();
groupEnumerator.MoveNext();
@ -94,10 +126,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -94,10 +126,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
IEnumerable<IGrouping<object, object>> GroupInternal () {
var properties = listProperties.Find(reportSettings.GroupColumnCollection[0].ColumnName,true);
var property = listProperties.Find("Randomint",true);
var groupedList = baseList.OrderBy(o => o.GetType().GetProperty(property.Name).GetValue(o, null) )
.GroupBy(a => a.GetType().GetProperty(properties.Name).GetValue(a, null)).OrderBy(c => c.Key);
var property = listProperties.Find(reportSettings.GroupColumnCollection[0].ColumnName,true);
var sortProperty = listProperties.Find("Randomint",true);
var groupedList = baseList.OrderBy(o => o.GetType().GetProperty(sortProperty.Name).GetValue(o, null) )
.GroupBy(a => a.GetType().GetProperty(property.Name).GetValue(a, null)).OrderBy(c => c.Key);
return groupedList;
}
@ -106,9 +139,9 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -106,9 +139,9 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
public void Bind()
{
if (reportSettings.GroupColumnCollection.Any()) {
this.Group();
Group();
} else {
this.Sort ();
Sort();
}
}
@ -118,7 +151,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -118,7 +151,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
private IEnumerator<IGrouping<object, object>> groupEnumerator;
private IEnumerator<object> listEnumerator;
public void Fill(System.Collections.Generic.List<ICSharpCode.Reporting.Interfaces.IPrintableObject> collection)
public void Fill(List<IPrintableObject> collection)
{
foreach (IPrintableObject item in collection)
{
@ -146,24 +179,52 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling @@ -146,24 +179,52 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling
return p.PropertyType;
}
/*
public bool MoveNext()
{
var canMove = listEnumerator.MoveNext();
if (! canMove) {
var groupCanMove = groupEnumerator.MoveNext();
if (groupCanMove) {
listEnumerator = groupEnumerator.Current.GetEnumerator();
canMove = listEnumerator.MoveNext();
Current = listEnumerator.Current;
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 {
Console.WriteLine("end");
Current = listEnumerator.Current;
}
return canMove;
} else {
var b = listEnumerator.MoveNext();
Current = listEnumerator.Current;
return b;
}
return canMove;
}
*/
public bool MoveNext()
{
var canMove = listEnumerator.MoveNext();
if (orderGroup == OrderGroup.Grouped) {
if (! canMove) {
var groupCanMove = groupEnumerator.MoveNext();
if (groupCanMove) {
listEnumerator = groupEnumerator.Current.GetEnumerator();
canMove = listEnumerator.MoveNext();
Current = listEnumerator.Current;
}
} else {
Current = listEnumerator.Current;
}
return canMove;
}
Current = listEnumerator.Current;
return canMove;
}
#endregion

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/ICSharpCode.Reporting.Test.csproj

@ -66,7 +66,7 @@ @@ -66,7 +66,7 @@
<ItemGroup>
<Compile Include="src\DataSource\ContributorsList.cs" />
<Compile Include="src\DataSource\CollectionHandlingFixture.cs" />
<Compile Include="src\DataSource\DataSourceGroupingFixture.cs" />
<Compile Include="src\DataSource\DataSourceFixture.cs" />
<Compile Include="src\Expressions\Aggregates\AggregateFuctionHelper.cs" />
<Compile Include="src\Expressions\Aggregates\SumAggregate.cs" />
<Compile Include="src\Expressions\IntegrationTests\FieldsFixture.cs" />

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/CollectionHandlingFixture.cs

@ -191,7 +191,7 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -191,7 +191,7 @@ namespace ICSharpCode.Reporting.Test.DataSource
string compare = collectionSource.IndexList[0].ObjectArray[0].ToString();
foreach (var element in collectionSource.IndexList) {
string result = String.Format("{0} - {1}",element.ListIndex,element.ObjectArray[0]);
Console.WriteLine(result);
// Coole.WriteLine(result);
Assert.That(compare,Is.LessThanOrEqualTo(element.ObjectArray[0].ToString()));
compare = element.ObjectArray[0].ToString();
}

33
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceGroupingFixture.cs → src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs

@ -38,6 +38,39 @@ namespace ICSharpCode.Reporting.Test.DataSource @@ -38,6 +38,39 @@ namespace ICSharpCode.Reporting.Test.DataSource
}
[Test]
public void SortOneColumnAscending() {
var ric = new System.Collections.Generic.List<IPrintableObject>(){
new BaseDataItem(){
ColumnName = "Lastname"
},
new BaseDataItem(){
ColumnName = "Firstname"
}
};
var rs = new ReportSettings();
rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending));
var collectionSource = new CollectionDataSource (list,typeof(Contributor),rs);
collectionSource.Bind();
string compare = String.Empty;
int i = 0;
do {
collectionSource.Fill(ric);
Console.WriteLine("first : <{0}> Last <{1}> ",((BaseDataItem)ric[0]).DBValue,
((BaseDataItem)ric[1]).DBValue);
Assert.That(((BaseDataItem)ric[0]).DBValue,Is.GreaterThanOrEqualTo(compare));
compare = ((BaseDataItem)ric[0]).DBValue;
i ++;
}while (collectionSource.MoveNext());
Assert.That(i,Is.EqualTo(collectionSource.Count));
}
[Test]
public void GroupbyOneColumnAndFill () {
Loading…
Cancel
Save