Browse Source

Make the sorting more generic

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1743 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Peter Forstmeier 19 years ago
parent
commit
14bbe1194a
  1. 70
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataNavigator.cs
  2. 93
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs
  3. 22
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs
  4. 53
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs
  5. 76
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs

70
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataNavigator.cs

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
using System;
using System.ComponentModel;
//using System.Collections;
using System.Collections;
namespace SharpReportCore
{
@ -17,7 +17,8 @@ namespace SharpReportCore @@ -17,7 +17,8 @@ namespace SharpReportCore
/// Description of DataNavigator.
/// </summary>
public class DataNavigator :IDataNavigator{
public class DataNavigator :IDataNavigator,IEnumerable{
IDataViewStrategy store;
GroupSeperator groupSeperator;
@ -110,6 +111,71 @@ namespace SharpReportCore @@ -110,6 +111,71 @@ namespace SharpReportCore
}
}
#endregion
/*
public delegate void TestDelegate(string s);
public delegate bool TestBoolDelegate(string s,string ss);
public SharpIndexCollection PlainDelegate (TestDelegate t) {
SharpIndexCollection cl = new SharpIndexCollection("Filtered");
System.Collections.IEnumerable e = (this as System.Collections.IEnumerable);
System.Collections.IEnumerator en = e.GetEnumerator();
while(en.MoveNext()){
System.Console.WriteLine("\twhile");
t("x");
}
return cl;
}
public SharpIndexCollection BoolDelegate (TestBoolDelegate t) {
SharpIndexCollection cl = new SharpIndexCollection("Filtered");
System.Collections.IEnumerable e = (this as System.Collections.IEnumerable);
System.Collections.IEnumerator en = e.GetEnumerator();
while(en.MoveNext()){
System.Console.WriteLine("\t{0}",en.Current);
if (t("x","y")) {
System.Console.WriteLine("added");
}
}
return cl;
}
*/
/*
public void Scroll() {
System.Console.WriteLine("");
System.Console.WriteLine("----Scroll did we need this -----");
System.Collections.IEnumerable e = (store as System.Collections.IEnumerable);
System.Collections.IEnumerator en = e.GetEnumerator();
while (en.MoveNext()){
System.Console.WriteLine("{0} ",en.Current);
}
System.Console.WriteLine("----");
}
*/
#region IEnumarable
public System.Collections.IEnumerable RangeTester(int start, int end)
{
System.Console.WriteLine("RangeIterator Range form {0} to {1}",start,end);
for (int i = start; i <= end; i++)
{
IDataViewStrategy d = this.store as IDataViewStrategy;
d.CurrentRow = i;
yield return this.Current;
}
}
IEnumerator IEnumerable.GetEnumerator(){
System.Console.WriteLine("Navi:IEnumerable.GetEnumerator() {0}",this.Count);
for (int i =0;i < this.Count;i++){
this.store.MoveNext();
yield return this.Current;
}
}
#endregion
}
}

93
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs

@ -1,34 +1,50 @@ @@ -1,34 +1,50 @@
using System;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
namespace SharpReportCore
{
/// <summary>
/// This class act'S as a IndexList to
/// This class act's as a IndexList to
/// <see cref="SharpBaseList"></see>
/// </summary>
public class SharpIndexCollection :List<BaseComparer> {
public class SharpIndexCollection :List<BaseComparer> ,IEnumerable<BaseComparer>{
string name;
int currentPosition;
public SharpIndexCollection():this ("SharpIndexList"){
public SharpIndexCollection():this ("IndexList"){
}
public SharpIndexCollection(string name){
this.name = name;
}
#region IEnumerable implementation
IEnumerator<BaseComparer> IEnumerable<BaseComparer>.GetEnumerator()
{
System.Console.WriteLine("IndexList IEnumerable<BaseComparer>.GetEnumerator()" );
//return new MyEnumerator(this);
for (int i =0;i < this.Count;i++){
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator(){
System.Console.WriteLine("IndexList IEnumerable.GetEnumerator()" );
return ((IEnumerable<BaseComparer>)this).GetEnumerator();
}
#endregion
#region properties
public int CurrentPosition {
get {
return currentPosition;
@ -43,9 +59,56 @@ namespace SharpReportCore @@ -43,9 +59,56 @@ namespace SharpReportCore
return name;
}
}
#endregion
/*
class MyEnumerator : IEnumerator<BaseComparer>{
SharpIndexCollection index;
int current;
public MyEnumerator(SharpIndexCollection index)
{
System.Console.WriteLine("Constr:MyEnumerator");
this.index = index;
this.current = -1;
}
public BaseComparer Current {
get {
System.Console.WriteLine("\tBaseComparer Current");
if (this.current == -1) {
throw new InvalidOperationException("SharpArrayList:Current");
}
return this.index[this.current];
}
}
object IEnumerator.Current {
get {
System.Console.WriteLine("IEnumerator.Current");
IEnumerator<BaseComparer> enumerator = this;
return enumerator.Current;
}
}
public void Dispose()
{
throw new NotImplementedException();
}
public bool MoveNext()
{
System.Console.WriteLine("IndexList:MoveNext");
this.current++;
return(this.current < this.index.Count);
}
public void Reset()
{
this.current = -1;
}
}
*/
}
/// <summary>
@ -114,7 +177,7 @@ namespace SharpReportCore @@ -114,7 +177,7 @@ namespace SharpReportCore
Add(t);
}
}
public void Clear(){
list = new Collection<T>();
@ -139,7 +202,7 @@ namespace SharpReportCore @@ -139,7 +202,7 @@ namespace SharpReportCore
}
#region ITypedList Member
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){
if (listAccessors != null && listAccessors.Length > 0){
Type t = this.elementType;
@ -157,7 +220,7 @@ namespace SharpReportCore @@ -157,7 +220,7 @@ namespace SharpReportCore
}
public static Type GetElementType(IList list, Type parentType, string propertyName)
{
{
SharpDataCollection<T> al = null;
object element = null;
al = CheckForArrayList(list);

22
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs

@ -21,6 +21,9 @@ using System.ComponentModel; @@ -21,6 +21,9 @@ using System.ComponentModel;
/// </remarks>
namespace SharpReportCore {
public delegate BaseComparer IndexerDelegate(ColumnCollection col,int i,object[] values);
public abstract class BaseListStrategy :IDataViewStrategy,IEnumerator {
private bool isSorted;
private bool isFiltered;
@ -71,6 +74,9 @@ namespace SharpReportCore { @@ -71,6 +74,9 @@ namespace SharpReportCore {
get {
return indexList;
}
set {
this.indexList = value;
}
}
@ -150,6 +156,17 @@ namespace SharpReportCore { @@ -150,6 +156,17 @@ namespace SharpReportCore {
#endregion
#region Sorting delegates
protected static BaseComparer PlainIndexBuilder (ColumnCollection columns,int row,object[] values) {
// We insert only the RowNr as a dummy value
values[0] = row;
return new BaseComparer(columns, row, values);
}
#endregion
protected static void CheckSortArray (SharpIndexCollection arr,string text){
System.Console.WriteLine("{0}",text);
@ -258,15 +275,10 @@ namespace SharpReportCore { @@ -258,15 +275,10 @@ namespace SharpReportCore {
}
public virtual void Sort() {
this.indexList.Clear();
}
public virtual void Bind() {
}

53
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs

@ -14,7 +14,7 @@ using System.Globalization; @@ -14,7 +14,7 @@ using System.Globalization;
/// <summary>
/// This Class handles all List's with IList
/// Access to Data is allway#s done by using the 'IndexList'
/// Access to Data is allway's done by using the 'IndexList'
/// </summary>
namespace SharpReportCore {
@ -29,7 +29,8 @@ namespace SharpReportCore { @@ -29,7 +29,8 @@ namespace SharpReportCore {
private SharpDataCollection<object> baseList;
#region Constructor
public CollectionStrategy(IList list,string dataMember,ReportSettings reportSettings):base(reportSettings) {
if (list.Count > 0) {
@ -43,7 +44,10 @@ namespace SharpReportCore { @@ -43,7 +44,10 @@ namespace SharpReportCore {
this.listProperties = this.baseList.GetItemProperties(null);
}
#endregion
#region build grouping
private void BuildGroup(){
try {
@ -51,7 +55,7 @@ namespace SharpReportCore { @@ -51,7 +55,7 @@ namespace SharpReportCore {
if (base.ReportSettings.GroupColumnsCollection != null) {
if (base.ReportSettings.GroupColumnsCollection.Count > 0) {
this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection);
groupedArray = this.BuildSortIndex (base.ReportSettings.GroupColumnsCollection);
}
}
@ -83,6 +87,10 @@ namespace SharpReportCore { @@ -83,6 +87,10 @@ namespace SharpReportCore {
}
}
#endregion
#region build sorting
private PropertyDescriptor[] BuildSortProperties (ColumnCollection col){
PropertyDescriptor[] sortProperties = new PropertyDescriptor[col.Count];
PropertyDescriptorCollection c = this.baseList.GetItemProperties(null);
@ -100,8 +108,9 @@ namespace SharpReportCore { @@ -100,8 +108,9 @@ namespace SharpReportCore {
return sortProperties;
}
#region Index Building
private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) {
private SharpIndexCollection BuildSortIndex(ColumnCollection col) {
SharpIndexCollection arrayList = new SharpIndexCollection();
PropertyDescriptor[] sortProperties = BuildSortProperties (col);
for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){
object rowItem = this.baseList[rowIndex];
@ -125,31 +134,21 @@ namespace SharpReportCore { @@ -125,31 +134,21 @@ namespace SharpReportCore {
arrayList.Add(new SortComparer(col, rowIndex, values));
}
arrayList.Sort();
return arrayList;
}
// if we have no sorting, we build the indexlist as well, so we don't need to
//check each time we reasd data if we have to go directly or by IndexList
private void BuildPlainIndex(SharpIndexCollection arrayList,ColumnCollection col) {
PropertyDescriptor[] sortProperties = new PropertyDescriptor[1];
PropertyDescriptorCollection c = this.baseList.GetItemProperties(null);
PropertyDescriptor descriptor = c[0];
sortProperties[0] = descriptor;
private SharpIndexCollection IndexBuilder(IndexerDelegate indexer,ColumnCollection col) {
SharpIndexCollection arrayList = new SharpIndexCollection();
for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){
object[] values = new object[1];
// We insert only the RowNr as a dummy value
values[0] = rowIndex;
arrayList.Add(new BaseComparer(col, rowIndex, values));
BaseComparer bc = indexer(col,rowIndex,values);
arrayList.Add(bc);
}
return arrayList;
}
#endregion
#region SharpReportCore.IDataViewStrategy interface implementation
@ -193,15 +192,13 @@ namespace SharpReportCore { @@ -193,15 +192,13 @@ namespace SharpReportCore {
base.Sort();
if ((base.ReportSettings.SortColumnCollection != null)) {
if (base.ReportSettings.SortColumnCollection.Count > 0) {
this.BuildSortIndex (base.IndexList,
base.ReportSettings.SortColumnCollection);
base.IndexList = this.BuildSortIndex (base.ReportSettings.SortColumnCollection);
base.IsSorted = true;
// BaseListStrategy.CheckSortArray (base.IndexList,"TableStrategy - CheckSortArray");
} else {
this.BuildPlainIndex(base.IndexList,
base.ReportSettings.SortColumnCollection);
SharpReportCore.IndexerDelegate t = new SharpReportCore.IndexerDelegate(BaseListStrategy.PlainIndexBuilder);
base.IndexList = this.IndexBuilder(t,base.ReportSettings.SortColumnCollection);
base.IsSorted = false;
}
}

76
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
/// <summary>
@ -19,12 +21,14 @@ using System.Data; @@ -19,12 +21,14 @@ using System.Data;
///</remarks>
namespace SharpReportCore {
public class TableStrategy : BaseListStrategy {
// public delegate void IndexerDelegate(int i,object[] values);
public class TableStrategy : BaseListStrategy,IEnumerable<BaseComparer> {
DataTable table;
DataView view = new DataView();
DataRowView row;
#region Constructor
public TableStrategy(DataTable table,ReportSettings reportSettings):base(reportSettings) {
if (table == null) {
@ -34,12 +38,12 @@ namespace SharpReportCore { @@ -34,12 +38,12 @@ namespace SharpReportCore {
view = this.table.DefaultView;
}
#endregion
#region Building the Index list
private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) {
#region Building Index list
private SharpIndexCollection BuildSortIndex(ColumnCollection col) {
SharpIndexCollection arrayList = new SharpIndexCollection();
try {
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
DataRowView rowItem = this.view[rowIndex];
@ -65,25 +69,22 @@ namespace SharpReportCore { @@ -65,25 +69,22 @@ namespace SharpReportCore {
}
arrayList.Sort();
return arrayList;
}
// if we have no sorting, we build the indexlist as well, so we don't need to
//check each time we reasd data if we have to go directly or by IndexList
private void BuildPlainIndex(SharpIndexCollection arrayList,ColumnCollection col) {
try {
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
object[] values = new object[1];
// We insert only the RowNr as a dummy value
values[0] = rowIndex;
arrayList.Add(new BaseComparer(col, rowIndex, values));
}
} catch (Exception) {
throw ;
// if we have no sorting, we build the indexlist as well
private SharpIndexCollection IndexBuilder(IndexerDelegate indexer,ColumnCollection col) {
SharpIndexCollection arrayList = new SharpIndexCollection();
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
object[] values = new object[1];
BaseComparer bc = indexer(col,rowIndex,values);
arrayList.Add(bc);
}
return arrayList;
}
#endregion
#region Grouping
@ -94,7 +95,10 @@ namespace SharpReportCore { @@ -94,7 +95,10 @@ namespace SharpReportCore {
if (base.ReportSettings.GroupColumnsCollection != null) {
if (base.ReportSettings.GroupColumnsCollection.Count > 0) {
this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection);
groupedArray = this.BuildSortIndex (base.ReportSettings.GroupColumnsCollection);
//
// SharpReportCore.IndexerDelegate sort = new SharpReportCore.IndexerDelegate(BaseListStrategy.SortedIndexBuilder);
// groupedArray = this.IndexBuilder(sort,base.ReportSettings.GroupColumnsCollection);
}
}
@ -131,6 +135,22 @@ namespace SharpReportCore { @@ -131,6 +135,22 @@ namespace SharpReportCore {
#endregion
#region IEnumerable
IEnumerator IEnumerable.GetEnumerator(){
System.Console.WriteLine("TableStrategy:IEnumerable.GetEnumerator()");
return((IEnumerable<BaseComparer>)this).GetEnumerator();
}
IEnumerator<BaseComparer> IEnumerable<BaseComparer>.GetEnumerator()
{
System.Console.WriteLine("\tTableStrategy:IEnumerable<BaseComparer>.GetEnumerator()");
IEnumerable<BaseComparer> e = (IEnumerable<BaseComparer>)base.IndexList;
return e.GetEnumerator();
}
#endregion
#region IEnumerator
public override bool MoveNext(){
@ -177,13 +197,14 @@ namespace SharpReportCore { @@ -177,13 +197,14 @@ namespace SharpReportCore {
base.Sort();
if ((base.ReportSettings.SortColumnCollection != null)) {
if (base.ReportSettings.SortColumnCollection.Count > 0) {
this.BuildSortIndex (base.IndexList,
base.ReportSettings.SortColumnCollection);
base.IndexList = this.BuildSortIndex (base.ReportSettings.SortColumnCollection);
// SharpReportCore.IndexerDelegate sort = new SharpReportCore.IndexerDelegate(BaseListStrategy.SortedIndexBuilder);
// base.IndexList = this.IndexBuilder(sort,base.ReportSettings.SortColumnCollection);
base.IsSorted = true;
} else {
this.BuildPlainIndex(base.IndexList,
base.ReportSettings.SortColumnCollection);
SharpReportCore.IndexerDelegate unsort = new SharpReportCore.IndexerDelegate(BaseListStrategy.PlainIndexBuilder);
base.IndexList = this.IndexBuilder(unsort,base.ReportSettings.SortColumnCollection);
base.IsSorted = false;
}
}
@ -209,7 +230,6 @@ namespace SharpReportCore { @@ -209,7 +230,6 @@ namespace SharpReportCore {
baseDataItem.DbValue = row[baseDataItem.ColumnName].ToString();
}
}
} catch (Exception) {
throw;
}

Loading…
Cancel
Save