7 changed files with 25 additions and 732 deletions
@ -1,499 +0,0 @@ |
|||||||
/* |
|
||||||
* Created by SharpDevelop. |
|
||||||
* User: Peter Forstmeier |
|
||||||
* Date: 21.05.2013 |
|
||||||
* Time: 20:09 |
|
||||||
* |
|
||||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
|
||||||
*/ |
|
||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Collections.ObjectModel; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Globalization; |
|
||||||
using System.Linq; |
|
||||||
|
|
||||||
using ICSharpCode.Reporting.BaseClasses; |
|
||||||
using ICSharpCode.Reporting.DataSource; |
|
||||||
using ICSharpCode.Reporting.DataSource.Comparer; |
|
||||||
using ICSharpCode.Reporting.Interfaces; |
|
||||||
using ICSharpCode.Reporting.Interfaces.Data; |
|
||||||
using ICSharpCode.Reporting.Items; |
|
||||||
|
|
||||||
namespace ICSharpCode.Reporting.DataManager.Listhandling |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Description of CollectionHandling.
|
|
||||||
/// </summary>
|
|
||||||
public class CollectionSource:IDataViewHandling |
|
||||||
{ |
|
||||||
|
|
||||||
readonly PropertyDescriptorCollection listProperties; |
|
||||||
readonly DataCollection<object> baseList; |
|
||||||
readonly ReportSettings reportSettings; |
|
||||||
readonly Type elementType; |
|
||||||
|
|
||||||
public CollectionSource(IEnumerable list, Type elementType, ReportSettings reportSettings) |
|
||||||
{ |
|
||||||
this.elementType = elementType; |
|
||||||
|
|
||||||
baseList = CreateBaseList(list, elementType); |
|
||||||
// elementType = baseList[0].GetType();
|
|
||||||
|
|
||||||
this.reportSettings = reportSettings; |
|
||||||
this.listProperties = this.baseList.GetItemProperties(null); |
|
||||||
IndexList = new IndexList(); |
|
||||||
} |
|
||||||
|
|
||||||
#region IDataViewHandling
|
|
||||||
|
|
||||||
public int Count |
|
||||||
{ |
|
||||||
get { |
|
||||||
return this.baseList.Count; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public Collection<AbstractColumn> AvailableFields { |
|
||||||
get { |
|
||||||
var availableFields = new Collection<AbstractColumn>(); |
|
||||||
foreach (PropertyDescriptor p in this.listProperties){ |
|
||||||
availableFields.Add (new AbstractColumn(p.Name,p.PropertyType)); |
|
||||||
} |
|
||||||
return availableFields; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
protected object Current_test {get;private set;} |
|
||||||
|
|
||||||
public object Current { |
|
||||||
get { |
|
||||||
return baseList[((BaseComparer)IndexList[CurrentPosition]).ListIndex]; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public int CurrentPosition { |
|
||||||
|
|
||||||
get { |
|
||||||
return IndexList.CurrentPosition; |
|
||||||
} |
|
||||||
set { |
|
||||||
if ((value > -1)|| (value > this.IndexList.Count)){ |
|
||||||
this.IndexList.CurrentPosition = value; |
|
||||||
} |
|
||||||
|
|
||||||
// BaseComparer bc = GetComparer(value);
|
|
||||||
// Current = baseList[bc.ListIndex];
|
|
||||||
|
|
||||||
// current = this.baseList[((BaseComparer)IndexList[value]).ListIndex];
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public bool MoveNext() |
|
||||||
{ |
|
||||||
this.IndexList.CurrentPosition ++; |
|
||||||
return this.IndexList.CurrentPosition<this.IndexList.Count; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void Bind() |
|
||||||
{ |
|
||||||
if (reportSettings.GroupColumnCollection.Any()) { |
|
||||||
this.Group(); |
|
||||||
} else { |
|
||||||
this.Sort (); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public IndexList IndexList {get; private set;} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region Fill
|
|
||||||
|
|
||||||
public void Fill(List<IPrintableObject> collection) |
|
||||||
{ |
|
||||||
foreach (IPrintableObject item in collection) |
|
||||||
{ |
|
||||||
if (item is IDataItem) { |
|
||||||
FillInternal(item as IDataItem); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void FillInternal (IDataItem item) { |
|
||||||
item.DBValue = String.Empty; |
|
||||||
var p = listProperties.Find(item.ColumnName,true); |
|
||||||
item.DBValue = p.GetValue(Current).ToString(); |
|
||||||
if (String.IsNullOrEmpty(item.DataType)) { |
|
||||||
item.DataType = p.PropertyType.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Fill_Test
|
|
||||||
private IEnumerable<IGrouping<object, BaseComparer>> newList; |
|
||||||
private IEnumerator<IGrouping<object, BaseComparer>> groupEnumerator; |
|
||||||
private IEnumerator<BaseComparer> listEnumerator; |
|
||||||
|
|
||||||
public void Fill_Test (List<IPrintableObject> collection) { |
|
||||||
|
|
||||||
var currentKey = groupEnumerator.Current; |
|
||||||
Console.WriteLine("{0}",currentKey.Key); |
|
||||||
var z = listEnumerator.Current; |
|
||||||
Console.WriteLine("\t...{0} - {1}",((BaseComparer)z).ListIndex.ToString(), |
|
||||||
((BaseComparer)z).ObjectArray[0].ToString()); |
|
||||||
foreach (IPrintableObject item in collection) |
|
||||||
{ |
|
||||||
var dbItem = item as IDataItem; |
|
||||||
if (dbItem != null) { |
|
||||||
|
|
||||||
dbItem.DBValue = String.Empty; |
|
||||||
var p = listProperties.Find(dbItem.ColumnName,true); |
|
||||||
dbItem.DBValue = p.GetValue(Current_test).ToString(); |
|
||||||
if (String.IsNullOrEmpty(dbItem.DataType)) { |
|
||||||
dbItem.DataType = p.PropertyType.ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public bool MoveNext_Test_List() { |
|
||||||
var canMove = listEnumerator.MoveNext(); |
|
||||||
if (! canMove) { |
|
||||||
var groupCanMove = groupEnumerator.MoveNext(); |
|
||||||
if (groupCanMove) { |
|
||||||
listEnumerator = groupEnumerator.Current.GetEnumerator(); |
|
||||||
canMove = listEnumerator.MoveNext(); |
|
||||||
// Current_test = listEnumerator.Current;
|
|
||||||
Current_test = baseList[listEnumerator.Current.ListIndex]; |
|
||||||
} else { |
|
||||||
Console.WriteLine("end"); |
|
||||||
} |
|
||||||
} else { |
|
||||||
Current_test = baseList[listEnumerator.Current.ListIndex]; |
|
||||||
} |
|
||||||
return canMove; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Grouping
|
|
||||||
public void Group() |
|
||||||
{ |
|
||||||
var sortedList = BuildSortIndex(baseList,reportSettings.GroupColumnCollection); |
|
||||||
var unsortedList = this.BuildIndexInternal(baseList,reportSettings.GroupColumnCollection); |
|
||||||
|
|
||||||
ShowIndexList(unsortedList); |
|
||||||
|
|
||||||
// newList = GroupTestOne(unsortedList);
|
|
||||||
newList = GroupTestLinq(sortedList); |
|
||||||
ShowGrouping(newList); |
|
||||||
groupEnumerator = newList.GetEnumerator(); |
|
||||||
groupEnumerator.MoveNext(); |
|
||||||
listEnumerator = groupEnumerator.Current.GetEnumerator(); |
|
||||||
listEnumerator.MoveNext(); |
|
||||||
// Current_test = listEnumerator.Current;
|
|
||||||
// return baseList[((BaseComparer)IndexList[CurrentPosition]).ListIndex];
|
|
||||||
Current_test = baseList[listEnumerator.Current.ListIndex]; |
|
||||||
Console.WriteLine("--------Display output-----"); |
|
||||||
} |
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/5013710/linq-order-by-group-by-and-order-by-each-group?rq=1
|
|
||||||
|
|
||||||
IEnumerable<IGrouping<object, BaseComparer>> GroupOrderByRandomInt (IndexList list) { |
|
||||||
SortColumnCollection sc = new SortColumnCollection(); |
|
||||||
sc.Add(new SortColumn("RandomInt", ListSortDirection.Ascending)); |
|
||||||
|
|
||||||
return list.GroupBy(a => a.ObjectArray[0]); |
|
||||||
} |
|
||||||
|
|
||||||
IEnumerable<IGrouping<object, BaseComparer>> GroupTestLinq (IndexList list) { |
|
||||||
return (from car in list |
|
||||||
group car by car.ObjectArray[0]); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/* |
|
||||||
void Group_test(IndexList unsortedList) |
|
||||||
{ |
|
||||||
Console.WriteLine("-------New group --------\t"); |
|
||||||
|
|
||||||
var dictionary = BuildGroup_1(unsortedList, reportSettings.GroupColumnCollection); |
|
||||||
|
|
||||||
// foreach (var element in dictionary) {
|
|
||||||
// Console.WriteLine("{0} - {1}", element.Key, element.Value.Count);
|
|
||||||
// }
|
|
||||||
var list = dictionary.Keys.ToList(); |
|
||||||
list.Sort(); |
|
||||||
|
|
||||||
Console.WriteLine("-------Sorted keys --------"); |
|
||||||
foreach (var key in list) { |
|
||||||
Console.WriteLine("{0}: {1}", key, dictionary[key].Count); |
|
||||||
foreach (var element in dictionary[key]) { |
|
||||||
Console.WriteLine("\t{0} ", ((BaseComparer)element).ObjectArray[0].ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
Console.WriteLine("-------Sort list by RandomInt --------"); |
|
||||||
|
|
||||||
SortColumnCollection sc = new SortColumnCollection(); |
|
||||||
sc.Add(new SortColumn("RandomInt", ListSortDirection.Ascending)); |
|
||||||
|
|
||||||
foreach (var key in list) { |
|
||||||
Console.WriteLine("{0}: {1}", key, dictionary[key].Count); |
|
||||||
|
|
||||||
DataCollection<object> newSource = new DataCollection<object>(elementType); |
|
||||||
IndexList myList = new IndexList(); |
|
||||||
foreach (var element in dictionary[key]) { |
|
||||||
newSource.Add(baseList[element.ListIndex]); |
|
||||||
myList = BuildSortIndex(newSource,sc); |
|
||||||
Console.WriteLine("\t{0} ", ((BaseComparer)element).ObjectArray[0].ToString()); |
|
||||||
} |
|
||||||
dictionary[key] = myList; |
|
||||||
// dictionary[key] = myList.OrderBy(a => a.ObjectArray[0]).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
Console.WriteLine("Result"); |
|
||||||
foreach (var key in list) { |
|
||||||
Console.WriteLine("{0}: {1}", key, dictionary[key].Count); |
|
||||||
foreach (var element in dictionary[key]) { |
|
||||||
Console.WriteLine("\t{0} ", ((BaseComparer)element).ObjectArray[0].ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/* |
|
||||||
private IndexList BuildGroup (IndexList source,GroupColumnCollection groups) |
|
||||||
{ |
|
||||||
string compareValue = String.Empty; |
|
||||||
var idlist = new IndexList(); |
|
||||||
|
|
||||||
PropertyDescriptor[] groupProperties = BuildSortProperties (groups); |
|
||||||
|
|
||||||
GroupComparer groupComparer = null; |
|
||||||
|
|
||||||
foreach (BaseComparer element in source) { |
|
||||||
var groupValue = ExtractValue(element,groupProperties); |
|
||||||
var query2 = idlist.FirstOrDefault( s => ((GroupComparer)s).ObjectArray[0] == groupValue) as GroupComparer; |
|
||||||
if (query2 == null) { |
|
||||||
groupComparer = CreateGroupHeader(element); |
|
||||||
idlist.Add(groupComparer); |
|
||||||
} else { |
|
||||||
Console.WriteLine("xx"); |
|
||||||
} |
|
||||||
if (compareValue != groupValue) { |
|
||||||
groupComparer = CreateGroupHeader(element); |
|
||||||
idlist.Add(groupComparer); |
|
||||||
} |
|
||||||
groupComparer.IndexList.Add(element); |
|
||||||
|
|
||||||
compareValue = groupValue; |
|
||||||
} |
|
||||||
ShowGrouping(ref idlist); |
|
||||||
return idlist; |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
/* |
|
||||||
void ShowGrouping(ref IndexList idlist) |
|
||||||
{ |
|
||||||
Console.WriteLine("----ShowGrouping---"); |
|
||||||
foreach (GroupComparer el in idlist) { |
|
||||||
Console.WriteLine("{0}", el.ToString()); |
|
||||||
if (el.IndexList.Any()) { |
|
||||||
foreach (var element in el.IndexList) { |
|
||||||
Console.WriteLine("--{0}", element.ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
string ExtractValue(BaseComparer element,PropertyDescriptor[] groupProperties) |
|
||||||
{ |
|
||||||
var rowItem = baseList[element.ListIndex]; |
|
||||||
var values = FillComparer(groupProperties, rowItem); |
|
||||||
// return element.ObjectArray[0].ToString();
|
|
||||||
return values[0].ToString(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
static GroupComparer CreateGroupHeader (BaseComparer sc) |
|
||||||
{ |
|
||||||
var gc = new GroupComparer(sc.ColumnCollection,sc.ListIndex,sc.ObjectArray); |
|
||||||
gc.IndexList = new IndexList(); |
|
||||||
return gc; |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region BuildIndexList
|
|
||||||
|
|
||||||
DataCollection<object> CreateBaseList(IEnumerable source, Type elementType) |
|
||||||
{ |
|
||||||
var list = new DataCollection<object>(elementType); |
|
||||||
list.AddRange(source); |
|
||||||
return list; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
IndexList BuildSortIndex(DataCollection<object> listToSort,Collection<AbstractColumn> sortColumnsCollection) |
|
||||||
{ |
|
||||||
|
|
||||||
IndexList indexList = BuildIndexInternal(listToSort,sortColumnsCollection); |
|
||||||
|
|
||||||
if (indexList[0].ObjectArray.GetLength(0) == 1) { |
|
||||||
|
|
||||||
IEnumerable<BaseComparer> sortedList = GenericSorter (indexList); |
|
||||||
indexList.Clear(); |
|
||||||
indexList.AddRange(sortedList); |
|
||||||
} |
|
||||||
else { |
|
||||||
indexList.Sort(); |
|
||||||
} |
|
||||||
return indexList; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IndexList BuildIndexInternal(DataCollection<object> listToSort,Collection<AbstractColumn> sortColumnsCollection) |
|
||||||
{ |
|
||||||
var indexList = new IndexList(); |
|
||||||
PropertyDescriptor[] sortProperties = BuildSortProperties(sortColumnsCollection); |
|
||||||
for (int rowIndex = 0; rowIndex < listToSort.Count; rowIndex++) { |
|
||||||
var rowItem = listToSort[rowIndex]; |
|
||||||
var values = FillComparer(sortProperties, rowItem); |
|
||||||
indexList.Add(new SortComparer(sortColumnsCollection, rowIndex, values)); |
|
||||||
} |
|
||||||
return indexList; |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region Sorting delegates
|
|
||||||
|
|
||||||
public void Sort() |
|
||||||
{ |
|
||||||
if ((this.reportSettings.SortColumnsCollection != null)) { |
|
||||||
if (this.reportSettings.SortColumnsCollection.Count > 0) { |
|
||||||
IndexList = this.BuildSortIndex (baseList,reportSettings.SortColumnsCollection); |
|
||||||
} else { |
|
||||||
IndexList = this.BuildIndexInternal(baseList,reportSettings.SortColumnsCollection); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static IEnumerable<BaseComparer> GenericSorter (List<BaseComparer> list) |
|
||||||
{ |
|
||||||
|
|
||||||
List<BaseComparer> sortedList = null; |
|
||||||
ListSortDirection sortDirection = GetSortDirection(list); |
|
||||||
|
|
||||||
sortedList = sortDirection == ListSortDirection.Ascending ? list.AsQueryable().AscendingOrder().ToList() : list.AsQueryable().DescendingOrder().ToList(); |
|
||||||
return sortedList; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
static ListSortDirection GetSortDirection(List<BaseComparer> list) |
|
||||||
{ |
|
||||||
BaseComparer bc = list[0]; |
|
||||||
var sortColumn = bc.ColumnCollection[0] as SortColumn; |
|
||||||
ListSortDirection sd = sortColumn.SortDirection; |
|
||||||
return sd; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
Object[] FillComparer(PropertyDescriptor[] sortProperties, object rowItem) |
|
||||||
{ |
|
||||||
object[] values = new object[sortProperties.Length]; |
|
||||||
for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++) { |
|
||||||
object value = sortProperties[criteriaIndex].GetValue(rowItem); |
|
||||||
if (value != null && value != DBNull.Value) { |
|
||||||
if (!(value is IComparable)) { |
|
||||||
throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString()); |
|
||||||
} |
|
||||||
values[criteriaIndex] = value; |
|
||||||
} |
|
||||||
} |
|
||||||
return values; |
|
||||||
} |
|
||||||
|
|
||||||
private PropertyDescriptor[] BuildSortProperties (Collection<AbstractColumn> sortColumnCollection) |
|
||||||
{ |
|
||||||
var sortProperties = new PropertyDescriptor[sortColumnCollection.Count]; |
|
||||||
var descriptorCollection = this.baseList.GetItemProperties(null); |
|
||||||
|
|
||||||
for (var criteriaIndex = 0; criteriaIndex < sortColumnCollection.Count; criteriaIndex++){ |
|
||||||
var descriptor = descriptorCollection.Find (sortColumnCollection[criteriaIndex].ColumnName,true); |
|
||||||
|
|
||||||
if (descriptor == null){ |
|
||||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, |
|
||||||
"Die Liste enthält keine Spalte [{0}].", |
|
||||||
sortColumnCollection[criteriaIndex].ColumnName)); |
|
||||||
} |
|
||||||
sortProperties[criteriaIndex] = descriptor; |
|
||||||
} |
|
||||||
return sortProperties; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
// BaseComparer GetComparer(int position)
|
|
||||||
// {
|
|
||||||
// var bc = (BaseComparer)IndexList[position];
|
|
||||||
// return bc;
|
|
||||||
// }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region Debug Code
|
|
||||||
|
|
||||||
private static void ShowIndexList (IndexList list) |
|
||||||
{ |
|
||||||
Console.WriteLine("ShowIndexList"); |
|
||||||
foreach (BaseComparer element in list) { |
|
||||||
Console.WriteLine("\t...{0} - {1}",((BaseComparer)element).ListIndex.ToString(), |
|
||||||
((BaseComparer)element).ObjectArray[0].ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
static void ShowGrouping(IEnumerable<IGrouping<object, BaseComparer>> grouping) |
|
||||||
{ |
|
||||||
Console.WriteLine("----------ShowGrouping-----------"); |
|
||||||
foreach (var element in grouping) { |
|
||||||
Console.WriteLine("{0} - {1} ", element.Key.ToString(), element.Key is BaseComparer); |
|
||||||
foreach (var xx in element) { |
|
||||||
Console.WriteLine("...{0}", ((BaseComparer)xx).ObjectArray[0].ToString()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// static string WrongColumnName(string propertyName)
|
|
||||||
// {
|
|
||||||
// return String.Format(CultureInfo.InvariantCulture, "Error : <{0}> missing!", propertyName);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
public void Reset() |
|
||||||
{ |
|
||||||
throw new NotImplementedException(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,226 +0,0 @@ |
|||||||
/* |
|
||||||
* Created by SharpDevelop. |
|
||||||
* User: Peter Forstmeier |
|
||||||
* Date: 20.05.2013 |
|
||||||
* Time: 18:15 |
|
||||||
* |
|
||||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
|
||||||
*/ |
|
||||||
using System; |
|
||||||
using System.ComponentModel; |
|
||||||
using System.Linq; |
|
||||||
|
|
||||||
using ICSharpCode.Reporting.BaseClasses; |
|
||||||
using ICSharpCode.Reporting.DataManager.Listhandling; |
|
||||||
using ICSharpCode.Reporting.Interfaces; |
|
||||||
using ICSharpCode.Reporting.Items; |
|
||||||
using NUnit.Framework; |
|
||||||
|
|
||||||
namespace ICSharpCode.Reporting.Test.DataSource |
|
||||||
{ |
|
||||||
[TestFixture] |
|
||||||
public class CollectionHandlingFixture |
|
||||||
{ |
|
||||||
|
|
||||||
private ContributorCollection list; |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CanInitDataCollection() |
|
||||||
{ |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
Assert.That(collectionSource,Is.Not.Null); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CurrentpositionShouldZeroAfterBind () { |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
collectionSource.Bind(); |
|
||||||
Assert.That(collectionSource.CurrentPosition,Is.EqualTo(0)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CurrentPositionIsTwo () { |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
collectionSource.Bind(); |
|
||||||
collectionSource.MoveNext(); |
|
||||||
collectionSource.MoveNext(); |
|
||||||
Assert.That(collectionSource.CurrentPosition,Is.EqualTo(2)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CollectionCountIsEqualToListCount() { |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
Assert.That(collectionSource.Count,Is.EqualTo(list.Count)); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void AvailableFieldsEqualContibutorsPropertyCount() { |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
Assert.That(collectionSource.AvailableFields.Count,Is.EqualTo(6)); |
|
||||||
} |
|
||||||
|
|
||||||
#region Fill
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void TypeOfReportItemIsString () { |
|
||||||
var ric = new System.Collections.Generic.List<IPrintableObject>(){ |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Lastname" |
|
||||||
|
|
||||||
}, |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Firstname" |
|
||||||
} |
|
||||||
}; |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
collectionSource.Bind(); |
|
||||||
collectionSource.Fill(ric); |
|
||||||
foreach (BaseDataItem element in ric) { |
|
||||||
Assert.That(element.DataType,Is.EqualTo("System.String")); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void FillReportItemCollection () { |
|
||||||
var ric = new System.Collections.Generic.List<IPrintableObject>(){ |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Lastname" |
|
||||||
|
|
||||||
}, |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Firstname" |
|
||||||
} |
|
||||||
}; |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
collectionSource.Bind(); |
|
||||||
collectionSource.Fill(ric); |
|
||||||
foreach (BaseDataItem element in ric) { |
|
||||||
Assert.That(element.DBValue,Is.Not.EqualTo(String.Empty)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region Grouping
|
|
||||||
/* |
|
||||||
[Test] |
|
||||||
public void GroupbyOneColumn () { |
|
||||||
var rs = new ReportSettings(); |
|
||||||
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),rs); |
|
||||||
collectionSource.Bind(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void GroupbyOneColumnAndFill () { |
|
||||||
|
|
||||||
var ric = new System.Collections.Generic.List<IPrintableObject>(){ |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Lastname" |
|
||||||
|
|
||||||
}, |
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "Firstname" |
|
||||||
}, |
|
||||||
|
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "GroupItem" |
|
||||||
}, |
|
||||||
|
|
||||||
new BaseDataItem(){ |
|
||||||
ColumnName = "RandomInt" |
|
||||||
} |
|
||||||
}; |
|
||||||
var rs = new ReportSettings(); |
|
||||||
rs.GroupColumnCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); |
|
||||||
rs.GroupColumnCollection.Add( new GroupColumn("RandomInt",1,ListSortDirection.Ascending)); |
|
||||||
|
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),rs); |
|
||||||
|
|
||||||
collectionSource.Bind(); |
|
||||||
int i = 0; |
|
||||||
do { |
|
||||||
collectionSource.Fill(ric); |
|
||||||
Console.WriteLine("first : <{0}> Last <{1}> Group <{2}> Randomint <{3}>",((BaseDataItem)ric[0]).DBValue, |
|
||||||
((BaseDataItem)ric[1]).DBValue, |
|
||||||
((BaseDataItem)ric[2]).DBValue, |
|
||||||
((BaseDataItem)ric[3]).DBValue); |
|
||||||
i ++; |
|
||||||
}while (collectionSource.MoveNext()); |
|
||||||
|
|
||||||
Assert.That(i,Is.EqualTo(collectionSource.Count)); |
|
||||||
} |
|
||||||
*/ |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Sort
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CreateUnsortedIndex() { |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),new ReportSettings()); |
|
||||||
collectionSource.Bind(); |
|
||||||
Assert.That(collectionSource.IndexList.Count,Is.EqualTo(collectionSource.Count)); |
|
||||||
Assert.That(collectionSource.IndexList.CurrentPosition,Is.EqualTo(0)); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
[ExpectedException(typeof(InvalidOperationException))] |
|
||||||
public void SortColumnNotExist() { |
|
||||||
var rs = new ReportSettings(); |
|
||||||
rs.SortColumnsCollection.Add(new SortColumn("aa",ListSortDirection.Ascending)); |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),rs); |
|
||||||
collectionSource.Bind(); |
|
||||||
Assert.That(collectionSource.IndexList,Is.Not.Null); |
|
||||||
Assert.That(collectionSource.IndexList.Count,Is.EqualTo(0)); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void SortOneColumnAscending() { |
|
||||||
var rs = new ReportSettings(); |
|
||||||
rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending)); |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),rs); |
|
||||||
collectionSource.Bind(); |
|
||||||
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]); |
|
||||||
// Coole.WriteLine(result);
|
|
||||||
Assert.That(compare,Is.LessThanOrEqualTo(element.ObjectArray[0].ToString())); |
|
||||||
compare = element.ObjectArray[0].ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
[Test] |
|
||||||
public void SortTwoColumnsAscending() { |
|
||||||
var rs = new ReportSettings(); |
|
||||||
rs.SortColumnsCollection.Add(new SortColumn("Lastname",ListSortDirection.Ascending)); |
|
||||||
rs.SortColumnsCollection.Add(new SortColumn("RandomInt",ListSortDirection.Ascending)); |
|
||||||
var collectionSource = new CollectionSource (list,typeof(Contributor),rs); |
|
||||||
collectionSource.Bind(); |
|
||||||
string compare = collectionSource.IndexList[0].ObjectArray[0].ToString(); |
|
||||||
foreach (var element in collectionSource.IndexList) { |
|
||||||
string result = String.Format("{0} - {1} - {2}",element.ListIndex,element.ObjectArray[0],element.ObjectArray[1].ToString()); |
|
||||||
Console.WriteLine(result); |
|
||||||
Assert.That(compare,Is.LessThanOrEqualTo(element.ObjectArray[0].ToString())); |
|
||||||
compare = element.ObjectArray[0].ToString(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
[SetUp] |
|
||||||
public void CreateList() { |
|
||||||
var contributorList = new ContributorsList(); |
|
||||||
list = contributorList.ContributorCollection; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue