Browse Source

Add Grouping (only one Column)to SharpReport, made some fixes from FxCOp

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1193 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Peter Forstmeier 20 years ago
parent
commit
1a5c72995e
  1. 14
      src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs
  2. 52
      src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs
  3. 1
      src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs
  4. 6
      src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs
  5. 38
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs
  6. 21
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs
  7. 48
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs
  8. 8
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs
  9. 16
      src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs
  10. 28
      src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs
  11. 4
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs
  12. 103
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs
  13. 97
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs
  14. 4
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs
  15. 250
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs
  16. 56
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs
  17. 45
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs
  18. 41
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs
  19. 8
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs
  20. 383
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/SharpArrayList.cs
  21. 263
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/BaseListStrategy.cs
  22. 228
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/CollectionStrategy.cs
  23. 296
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListStrategy/TableStrategy.cs
  24. 4
      src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs
  25. 4
      src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs
  26. 15
      src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs
  27. 6
      src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs
  28. 7
      src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs
  29. 27
      src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs
  30. 15
      src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs
  31. 6
      src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs
  32. 15
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs
  33. 2
      src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs
  34. 26
      src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs
  35. 66
      src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs
  36. 9
      src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj
  37. 61
      src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs
  38. 30
      src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs

14
src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs

@ -57,13 +57,10 @@ namespace SharpReport.Designer
#region overrides #region overrides
protected override void Dispose(bool disposing ) { protected override void Dispose(bool disposing ) {
if( disposing ) if( disposing ){
{ this.reportControl = null;
// if( components != null ) this.ctrlRuler1 = null;
// components.Dispose();
} }
this.reportControl = null;
this.ctrlRuler1 = null;
base.Dispose( disposing ); base.Dispose( disposing );
} }
@ -110,7 +107,10 @@ namespace SharpReport.Designer
public ReportModel ReportModel { public ReportModel ReportModel {
get { get {
reportModel.ReportSettings = reportControl.ReportSettings; reportModel.ReportSettings = reportControl.ReportSettings;
reportModel.SectionCollection = reportControl.SectionCollection; reportModel.SectionCollection.Clear();
foreach (ReportSection section in reportControl.SectionCollection) {
reportModel.SectionCollection.Add (section);
}
return this.reportModel; return this.reportModel;
} }

52
src/AddIns/Misc/SharpReport/SharpReport/SharpReportManager.cs

@ -73,7 +73,6 @@ namespace SharpReport{
/// <returns><see cref="ColumnCollection"</returns> /// <returns><see cref="ColumnCollection"</returns>
private ColumnCollection ReadColumnCollection() { private ColumnCollection ReadColumnCollection() {
ColumnCollection columnCollecion = new ColumnCollection(); ColumnCollection columnCollecion = new ColumnCollection();
switch (baseDesignerControl.ReportModel.DataModel) { switch (baseDesignerControl.ReportModel.DataModel) {
case GlobalEnums.enmPushPullModel.FormSheet: case GlobalEnums.enmPushPullModel.FormSheet:
@ -88,13 +87,20 @@ namespace SharpReport{
if (base.ConnectionObject == null) { if (base.ConnectionObject == null) {
base.ConnectionObject = this.BuildConnectionObject(baseDesignerControl.ReportModel.ReportSettings); base.ConnectionObject = this.BuildConnectionObject(baseDesignerControl.ReportModel.ReportSettings);
} }
if (this.baseDesignerControl.ReportModel.DataModel.Equals(GlobalEnums.enmPushPullModel.PullData)){ if (this.baseDesignerControl.ReportModel.DataModel.Equals(GlobalEnums.enmPushPullModel.PullData)){
try {
using (DataManager dataManager = new DataManager(base.ConnectionObject, using (DataManager dataManager = new DataManager(base.ConnectionObject,
baseDesignerControl.ReportModel.ReportSettings)) { baseDesignerControl.ReportModel.ReportSettings)) {
dataManager.DataBind();
columnCollecion = dataManager.AvailableFields; dataManager.DataBind();
columnCollecion = dataManager.AvailableFields;
}
} catch (Exception e) {
throw e;
} finally {
System.Console.WriteLine("ReportManager:ReadColumnCollection in finally");
} }
} }
break; break;
@ -104,10 +110,7 @@ namespace SharpReport{
return columnCollecion; return columnCollecion;
} }
private void AddItemsToSection (BaseSection section,ReportItemCollection collection) { private void AddItemsToSection (BaseSection section,ReportItemCollection collection) {
if ((section == null)|| (collection == null) ) { if ((section == null)|| (collection == null) ) {
@ -324,6 +327,7 @@ namespace SharpReport{
if (base.ConnectionObject == null) { if (base.ConnectionObject == null) {
base.ConnectionObject = this.BuildConnectionObject(model.ReportSettings); base.ConnectionObject = this.BuildConnectionObject(model.ReportSettings);
} }
return base.AbstractRenderer(model); return base.AbstractRenderer(model);
} }
@ -478,20 +482,22 @@ namespace SharpReport{
} }
protected new void Dispose(bool disposing){ protected new void Dispose(bool disposing){
if (disposing) { try {
// Free other state (managed objects). if (disposing) {
if (this.baseDesignerControl != null) { // Free other state (managed objects).
this.baseDesignerControl.Dispose(); if (this.baseDesignerControl != null) {
} this.baseDesignerControl.Dispose();
if (this.reportModel != null) { }
this.reportModel.Dispose(); if (this.reportModel != null) {
this.reportModel.Dispose();
}
} }
} finally {
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
base.Dispose();
} }
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
base.Dispose();
} }
#endregion #endregion
} }

1
src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs

@ -70,7 +70,6 @@ namespace SharpReportAddin {
return GlobalValues.IsValidPrinter(); return GlobalValues.IsValidPrinter();
} }
public virtual ICSharpCode.SharpDevelop.Gui.IViewContent CreateContentForFile(string fileName) { public virtual ICSharpCode.SharpDevelop.Gui.IViewContent CreateContentForFile(string fileName) {
if (GlobalValues.IsValidPrinter() == true) { if (GlobalValues.IsValidPrinter() == true) {
SharpReportView view = new SharpReportView(); SharpReportView view = new SharpReportView();

6
src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs

@ -502,7 +502,6 @@ namespace SharpReportAddin{
public override void Load(string fileName){ public override void Load(string fileName){
try { try {
designerControl.ReportControl.ObjectSelected -= new EventHandler <EventArgs>(OnObjectSelected); designerControl.ReportControl.ObjectSelected -= new EventHandler <EventArgs>(OnObjectSelected);
reportManager.LoadFromFile (fileName); reportManager.LoadFromFile (fileName);
base.FileName = fileName; base.FileName = fileName;
designerControl.ReportModel.ReportSettings.FileName = fileName; designerControl.ReportModel.ReportSettings.FileName = fileName;
@ -511,10 +510,9 @@ namespace SharpReportAddin{
PropertyPad.Grid.SelectedObject = designerControl.ReportModel.ReportSettings; PropertyPad.Grid.SelectedObject = designerControl.ReportModel.ReportSettings;
PropertyPad.Grid.Refresh(); PropertyPad.Grid.Refresh();
} }
this.designerControl.ReportModel.ReportSettings.AvailableFieldsCollection = reportManager.AvailableFieldsCollection; this.designerControl.ReportModel.ReportSettings.AvailableFieldsCollection = reportManager.AvailableFieldsCollection;
} catch (Exception e) {
} catch (Exception ) { MessageService.ShowError(e,"SharpReportView:Load");
throw ; throw ;
} }
} }

38
src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs

@ -98,15 +98,7 @@ namespace SharpReportCore {
#endregion #endregion
#region System.IDisposable interface implementation
public virtual void Dispose() {
if(Disposed != null){
Disposed(this,EventArgs.Empty);
}
}
#endregion
#region Properties #region Properties
@ -169,5 +161,33 @@ namespace SharpReportCore {
#endregion #endregion
#region IDisposeable
public override void Dispose () {
Dispose(true);
GC.SuppressFinalize(this);
}
~BaseReportItem(){
Dispose(false);
}
protected override void Dispose(bool disposing) {
try {
if (disposing){
if (this.font != null){
this.font = null;
this.font.Dispose();
}
}
} finally {
if (this.Disposed != null) {
this.Disposed (this,EventArgs.Empty);
}
base.Dispose(disposing);
}
}
#endregion
} }
} }

21
src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs

@ -25,7 +25,8 @@ using System.Drawing;
/// </remarks> /// </remarks>
namespace SharpReportCore { namespace SharpReportCore {
public class BaseReportObject : IBaseRenderer,INotifyPropertyChanged { public class BaseReportObject : IBaseRenderer,INotifyPropertyChanged,
IDisposable{
private string name; private string name;
private object parent; private object parent;
@ -212,5 +213,23 @@ namespace SharpReportCore {
} }
#endregion #endregion
#region IDisposable
public virtual void Dispose () {
Dispose(true);
GC.SuppressFinalize(this);
}
~BaseReportObject(){
Dispose(false);
}
protected virtual void Dispose(bool disposing) {
if (disposing){
}
}
#endregion
} }
} }

48
src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs

@ -3,7 +3,7 @@
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version: 1.1.4322.2032 // Runtime Version: 1.1.4322.2032
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
// </autogenerated> // </autogenerated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -16,32 +16,56 @@ using System.ComponentModel;
/// created by - Forstmeier Helmut /// created by - Forstmeier Helmut
/// created on - 01.09.2005 13:12:32 /// created on - 01.09.2005 13:12:32
/// </remarks> /// </remarks>
namespace SharpReportCore { namespace SharpReportCore {
public class BaseSection : SharpReportCore.BaseReportObject { public class BaseSection : SharpReportCore.BaseReportObject {
private ReportItemCollection items; private ReportItemCollection items;
public BaseSection(): this("") { #region Constructors
public BaseSection(): base() {
this.Name = String.Empty;
} }
public BaseSection (string sectionName) :base(){
this.Name = sectionName;
}
#endregion
#region System.IDisposable interface implementation #region System.IDisposable interface implementation
public void Dispose() { public override void Dispose () {
for (int i = 0;i < items.Count ;i ++ ){ Dispose(true);
((BaseReportItem)items[i]).Dispose(); GC.SuppressFinalize(this);
} }
~BaseSection(){
Dispose(false);
} }
protected override void Dispose(bool disposing) {
try {
if (disposing){
if (this.items != null) {
this.items.Clear();
this.items = null;
}
}
} finally {
base.Dispose(disposing);
}
}
#endregion #endregion
#region properties #region properties
public BaseSection (string sectionName) :base(){
this.Name = sectionName;
items = new ReportItemCollection();
}
[Browsable(false)] [Browsable(false)]
public ReportItemCollection Items{ public ReportItemCollection Items{
get { get {
if (this.items == null) {
items = new ReportItemCollection();
}
return items; return items;
} }
} }

8
src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs

@ -75,10 +75,10 @@ namespace SharpReportCore {
} }
} }
public override void Dispose() { // public override void Dispose() {
base.Dispose(); // base.Dispose();
this.image = null; // this.image = null;
} // }
public override string ToString() { public override string ToString() {
return "BaseImageItem"; return "BaseImageItem";

16
src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseRectangleItem.cs

@ -76,14 +76,14 @@ namespace SharpReportCore {
#region System.IDisposable interface implementation #region System.IDisposable interface implementation
public override void Dispose() { // public override void Dispose() {
base.Dispose(); // base.Dispose();
for (int i = 0; i < arrayList.Count;i ++ ) { // for (int i = 0; i < arrayList.Count;i ++ ) {
IComponent curObj = (IComponent)arrayList[i]; // IComponent curObj = (IComponent)arrayList[i];
curObj.Dispose(); // curObj.Dispose();
} // }
arrayList = null; // arrayList = null;
} // }
#endregion #endregion

28
src/AddIns/Misc/SharpReport/SharpReportCore/ConnectionObject.cs

@ -55,15 +55,33 @@ namespace SharpReportCore {
} }
} }
#region IDisposeable
public void Dispose () {
Dispose(true);
GC.SuppressFinalize(this);
}
~ConnectionObject(){
Dispose(false);
}
public void Dispose(){ protected virtual void Dispose(bool disposing) {
if (this.connection != null) { try{
if (this.connection.State == ConnectionState.Open) { if (disposing){
this.connection.Close(); if (this.connection != null){
if (this.connection.State == ConnectionState.Open) {
this.connection.Close();
}
this.connection.Dispose();
}
} }
this.connection.Dispose(); }
finally{
connection = null;
} }
} }
#endregion
} }
} }

4
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/BaseComparer.cs

@ -33,13 +33,13 @@ namespace SharpReportCore {
} }
/// <summary> /// <summary>
/// TODO - add method description /// Interface method from IComparable
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Interface method from IComparable /// Interface method from IComparable
/// ///
/// </remarks> /// </remarks>
/// <param name='obj'>TODO - add parameter description</param> /// <param name='obj'>a <see cref="BaseComparer"></see></param>
public virtual int CompareTo(object obj) { public virtual int CompareTo(object obj) {
return 0; return 0;
} }

103
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupComparer.cs

@ -1,103 +0,0 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Text;
using System.ComponentModel;
using SharpReportCore;
/// <summary>
/// TODO - Add class summary
/// </summary>
/// <remarks>
/// created by - Forstmeier Helmut
/// created on - 27.11.2005 14:59:28
/// </remarks>
namespace SharpReportCore {
public class GroupComparer : SharpReportCore.BaseComparer{
public GroupComparer(ColumnCollection owner, int listIndex, object[] values):
base(owner,listIndex,values) {
}
internal int CompareTo(GroupComparer value)
{
// we shouldn't get to this point
if (value == null)
throw new ArgumentNullException("value");
if (value.ObjectArray.Length != base.ObjectArray.Length)
throw new InvalidOperationException("Differnet size of compare data");
int compare = 0;
for (int index = 0; index < base.ObjectArray.Length; index++)
{
object leftValue = base.ObjectArray[index];
object rightValue = value.ObjectArray[index];
// Indizes sind hier deckungsgleich
GroupColumn groupColumn = (GroupColumn)base.ColumnCollection[index];
bool descending = (groupColumn.SortDirection == ListSortDirection.Descending);
// null means equl
if (leftValue == null || leftValue == System.DBNull.Value)
{
if (rightValue != null && rightValue != System.DBNull.Value)
{
return (descending) ? 1 : -1;
}
// Beide Null
continue;
}
if (rightValue == null || rightValue == System.DBNull.Value)
{
return (descending) ? -1 : 1;
}
if (leftValue.GetType() != rightValue.GetType())
throw new InvalidOperationException("Compare of different types is not supported");
if (leftValue.GetType() == typeof(string))
{
compare = String.Compare((string)leftValue, (string)rightValue,
!groupColumn.CaseSensitive, base.ColumnCollection.Culture);
}
else
{
compare = ((IComparable)leftValue).CompareTo(rightValue);
}
// Sind ungleich, tauschen je nach Richtung
if (compare != 0)
{
return (descending) ? -compare : compare;
}
}
// Gleich Werte, dann Index bercksichtigen
return this.ListIndex.CompareTo(value.ListIndex);
}
public override int CompareTo(object obj) {
base.CompareTo(obj);
return this.CompareTo((GroupComparer)obj);
}
}
}

97
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/GroupSeperator.cs

@ -22,11 +22,11 @@ using SharpReportCore;
/// </remarks> /// </remarks>
namespace SharpReportCore { namespace SharpReportCore {
public class GroupSeperator : SharpReportCore.GroupComparer,IHierarchyData { public class GroupSeperator : SharpReportCore.BaseComparer,IHierarchyData {
private string typeName = "GroupSeperator"; private string typeName = "GroupSeperator";
int groupLevel; int groupLevel;
IHierarchicalArray childs ; SharpIndexCollection childs ;
public GroupSeperator(ColumnCollection owner, int listIndex, object[] values,int groupLevel): public GroupSeperator(ColumnCollection owner, int listIndex, object[] values,int groupLevel):
base(owner,listIndex,values) { base(owner,listIndex,values) {
@ -40,16 +40,89 @@ namespace SharpReportCore {
} }
} }
public IHierarchicalArray Childs { public SharpIndexCollection GetChildren {
get { get {
if (this.childs == null) {
this.childs = new SharpIndexCollection("ChildList");
}
return childs; return childs;
} }
set { }
childs = value;
#region Comparer
internal int CompareTo(BaseComparer value)
{
// we shouldn't get to this point
if (value == null)
throw new ArgumentNullException("value");
if (value.ObjectArray.Length != base.ObjectArray.Length)
throw new InvalidOperationException("Differnet size of compare data");
int compare = 0;
for (int index = 0; index < base.ObjectArray.Length; index++)
{
object leftValue = base.ObjectArray[index];
object rightValue = value.ObjectArray[index];
// Indizes sind hier deckungsgleich
GroupColumn groupColumn = (GroupColumn)base.ColumnCollection[index];
bool descending = (groupColumn.SortDirection == ListSortDirection.Descending);
// null means equl
if (leftValue == null || leftValue == System.DBNull.Value)
{
if (rightValue != null && rightValue != System.DBNull.Value)
{
return (descending) ? 1 : -1;
}
// Beide Null
continue;
}
if (rightValue == null || rightValue == System.DBNull.Value)
{
return (descending) ? -1 : 1;
}
if (leftValue.GetType() != rightValue.GetType())
throw new InvalidOperationException("Compare of different types is not supported");
if (leftValue.GetType() == typeof(string))
{
compare = String.Compare((string)leftValue, (string)rightValue,
!groupColumn.CaseSensitive, base.ColumnCollection.Culture);
}
else
{
compare = ((IComparable)leftValue).CompareTo(rightValue);
}
// Sind ungleich, tauschen je nach Richtung
if (compare != 0)
{
return (descending) ? -compare : compare;
}
} }
// Gleich Werte, dann Index bercksichtigen
return this.ListIndex.CompareTo(value.ListIndex);
}
public override int CompareTo(object obj) {
base.CompareTo(obj);
return this.CompareTo((BaseComparer)obj);
} }
#endregion
#region SharpReportCore.IHierarchyData interface implementation #region SharpReportCore.IHierarchyData interface implementation
@ -85,13 +158,13 @@ namespace SharpReportCore {
} }
} }
public IHierarchicalEnumerable GetChildren() { // public IHierarchicalEnumerable GetChildren() {
return this.childs; // return this.childs;
} // }
//
public IHierarchyData GetParent() { // public IHierarchyData GetParent() {
return null; // return null;
} // }
#endregion #endregion

4
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/Comparer/SortComparer.cs

@ -28,7 +28,7 @@ namespace SharpReportCore {
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
if (value.ObjectArray.Length != base.ObjectArray.Length) if (value.ObjectArray.Length != base.ObjectArray.Length)
throw new InvalidOperationException("Differnet size of compare data"); throw new InvalidOperationException();
int compare = 0; int compare = 0;
@ -61,7 +61,7 @@ namespace SharpReportCore {
if (leftValue.GetType() != rightValue.GetType()) if (leftValue.GetType() != rightValue.GetType())
throw new InvalidOperationException("COmpare of different types is not supported"); throw new InvalidOperationException("Compare of different types is not supported");
if (leftValue.GetType() == typeof(string)) if (leftValue.GetType() == typeof(string))
{ {

250
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/DataManager.cs

@ -45,12 +45,11 @@ namespace SharpReportCore {
ConnectionObject connectionObject; ConnectionObject connectionObject;
IDbConnection connection; IDbConnection connection;
IDataViewStrategy dataViewStrategy; IDataViewStrategy dataViewStrategy;
GroupSeperator groupSeperator;
// private ListChangedEventArgs resetList = new ListChangedEventArgs(ListChangedType.Reset,-1,-1);
public event EventHandler <ListChangedEventArgs> ListChanged; public event EventHandler <ListChangedEventArgs> ListChanged;
public event EventHandler <GroupChangedEventArgs> GroupChanged; public event EventHandler <GroupChangedEventArgs> GroupChanged;
public event EventHandler <EventArgs> GroupChanging;
/// <summary> /// <summary>
/// use this Constructor for PullDataReports /// use this Constructor for PullDataReports
@ -60,34 +59,32 @@ namespace SharpReportCore {
#region Constructores #region Constructores
public DataManager(ConnectionObject connectionObject, ReportSettings reportSettings){ public DataManager(ConnectionObject connectionObject, ReportSettings reportSettings){
CheckAndSetReportSettings(reportSettings);
if (connectionObject == null) { if (connectionObject == null) {
throw new ArgumentNullException("DataManager:ConnectionObject"); throw new ArgumentNullException("DataManager:ConnectionObject");
} }
this.connectionObject = connectionObject;
try { if (reportSettings == null) {
CheckConnection (this.connectionObject); throw new ArgumentNullException("reportSettings");
CheckAndSetSource(this.FillDataSet().Tables[0]);
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
} catch (Exception) {
throw;
} }
this.connectionObject = connectionObject;
CheckConnection (this.connectionObject);
CheckReportSettings(reportSettings);
CheckDataSource(this.FillDataSet().Tables[0]);
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
this.dataViewStrategy.GroupChanged += new EventHandler<GroupChangedEventArgs> (OnGroupChange);
} }
public DataManager(DataTable dataSource, ReportSettings reportSettings){ public DataManager(DataTable dataSource, ReportSettings reportSettings){
try {
CheckAndSetReportSettings(reportSettings); this.InitDataManager(reportSettings,dataSource);
CheckAndSetSource(dataSource); this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, reportSettings);
reportSettings); this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
} catch (Exception) {
throw ;
}
} }
public DataManager(DataSet dataSource, ReportSettings reportSettings) public DataManager(DataSet dataSource, ReportSettings reportSettings)
@ -97,54 +94,49 @@ namespace SharpReportCore {
public DataManager(DataSet dataSource,string dataMember, ReportSettings reportSettings){ public DataManager(DataSet dataSource,string dataMember, ReportSettings reportSettings){
try { this.dataMember = dataMember;
this.dataMember = dataMember; this.InitDataManager(reportSettings,dataSource);
CheckAndSetReportSettings(reportSettings); this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource,
CheckAndSetSource(dataSource); reportSettings);
this.dataViewStrategy = new TableStrategy((DataTable)this.dataSource, this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
} catch (Exception ) {
throw ;
}
} }
public DataManager(IList dataSource, ReportSettings reportSettings){ public DataManager(IList dataSource, ReportSettings reportSettings){
this.InitDataManager(reportSettings,dataSource);
this.dataViewStrategy = new CollectionStrategy ((IList)this.dataSource,
this.dataMember,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
}
#endregion
void InitDataManager (ReportSettings reportSettings,object dataSource) {
try { try {
CheckAndSetReportSettings(reportSettings); CheckReportSettings(reportSettings);
CheckAndSetSource(dataSource); CheckDataSource(dataSource);
this.dataViewStrategy = new CollectionStrategy ((IList)this.dataSource,
this.dataMember,
reportSettings);
this.dataViewStrategy.ListChanged += new EventHandler <ListChangedEventArgs> (NotifyListChanged);
} catch (Exception) { } catch (Exception) {
throw; throw;
} }
} }
#endregion void CheckReportSettings(ReportSettings settings) {
void CheckAndSetReportSettings(ReportSettings settings) {
if (settings == null) {
throw new ArgumentNullException("settings");
}
try { try {
if (settings.DataModel != GlobalEnums.enmPushPullModel.PushData) { if (settings.DataModel != GlobalEnums.enmPushPullModel.PushData) {
SqlQueryCkecker check = new SqlQueryCkecker(); SqlQueryChecker checker = new SqlQueryChecker();
check.Check(settings.CommandText); checker.Check(settings.CommandText);
} }
} catch (Exception) { } catch (Exception) {
throw; throw;
} }
this.reportSettings = settings; this.reportSettings = settings;
} }
void CheckAndSetSource(object source) { void CheckDataSource(object source) {
if (source == null) { if (source == null) {
throw new MissingDataSourceException(); throw new MissingDataSourceException();
} }
@ -175,7 +167,7 @@ namespace SharpReportCore {
} }
} }
}else { }else {
throw new ArgumentException("DataManager:No Tables in DataSet"); throw new MissingDataSourceException();
} }
return; return;
} }
@ -186,24 +178,13 @@ namespace SharpReportCore {
this.dataSource = list; this.dataSource = list;
this.dataMember = source.ToString(); this.dataMember = source.ToString();
if (list.Count == 0) { if (list.Count == 0) {
//System.Console.WriteLine("List mit {0} Rows",list.Count); throw new MissingDataSourceException();
throw new ArgumentException("No empty IList allowed");
} }
return; return;
} }
// if (source is IList) {
// IList list = source as IList;
// this.dataSource = list;
// this.dataMember = source.ToString();
// if (list.Count == 0) {
// //System.Console.WriteLine("List mit {0} Rows",list.Count);
// throw new ArgumentException("No empty IList allowed");
// }
// return;
// }
} else { } else {
throw new ArgumentException ("DataManager:Wrong DataSource"); throw new MissingDataSourceException();
} }
} }
@ -215,7 +196,7 @@ namespace SharpReportCore {
} }
connection.Open(); connection.Open();
connection.Close(); connection.Close();
} catch (Exception ) { } catch (Exception) {
throw; throw;
} }
} }
@ -296,14 +277,25 @@ namespace SharpReportCore {
this.ListChanged (this,e); this.ListChanged (this,e);
} }
} }
private void NotifyGroupChanging () {
if (this.GroupChanging!= null) {
this.GroupChanging (this,EventArgs.Empty);
}
}
private void NotifyGroupChange (object sender,GroupChangedEventArgs e) { private void NotifyGroupChanged() {
if (this.IsGrouped) {
if (this.GroupChanged != null) { if (this.GroupChanged != null) {
this.GroupChanged (this,e); this.GroupChanged (this,new GroupChangedEventArgs(this.groupSeperator));
}
} }
} }
private void OnGroupChange (object sender,GroupChangedEventArgs e) {
this.groupSeperator = e.GroupSeperator;
this.NotifyGroupChanging();
}
#endregion #endregion
public string DataMember { public string DataMember {
@ -319,59 +311,13 @@ namespace SharpReportCore {
} }
public IHierarchicalArray IHierarchicalArray {
get {
return (IHierarchicalArray)this.dataViewStrategy.IHierarchicalEnumerable;
}
}
/*
public void PerformHierarchy (IHierarchicalEnumerable list) {
IEnumerator iter = list.GetEnumerator();
System.Console.WriteLine("PerformHierarchy");
if (iter != null) {
while (iter.MoveNext()){
GroupSeperator g = (GroupSeperator)iter.Current;
System.Console.WriteLine("list {0} {1}",g.Path,g.ListIndex);
CheckGroups (g);
}
} else {
throw new SystemException("PerformHierarchy: No valid IEnumerator");
}
}
private void CheckGroups(GroupSeperator sep) {
System.Console.WriteLine("CheckGroups");
IEnumerator children = ((IHierarchicalEnumerable)sep.GetChildren()).GetEnumerator();
while (children.MoveNext()) {
System.Console.WriteLine("children");
}
}
public IHierarchicalEnumerable HierarchicalList {
get {
return hierarchicalList;
}
}
*/
#region SharpReportCore.IDataContainer interface implementation #region SharpReportCore.IDataContainer interface implementation
public object DataSource { public object DataSource {
get { get {
return this.dataSource; return this.dataSource;
} }
set {
this.dataSource = value;
Reset();
}
} }
public int CurrentRow { public int CurrentRow {
@ -399,9 +345,8 @@ namespace SharpReportCore {
public bool DataBind() { public bool DataBind() {
this.dataViewStrategy.Bind();
this.dataViewStrategy.GroupChanged += new EventHandler <GroupChangedEventArgs>(NotifyGroupChange);
CheckReportColumns(); CheckReportColumns();
this.dataViewStrategy.Bind();
return true; return true;
} }
@ -411,11 +356,30 @@ namespace SharpReportCore {
public void FetchData(ReportItemCollection collection) { public void FetchData(ReportItemCollection collection) {
try { foreach (IItemRenderer item in collection) {
foreach (IItemRenderer item in collection) { this.dataViewStrategy.Fill(item);
this.dataViewStrategy.Fill(item); }
} this.NotifyGroupChanged();
} catch (Exception) { }
/// <summary>
/// Indicate's if the current <see cref="GroupSeperator"></see> has ChildRows
/// </summary>
public bool HasChilds {
get {
return this.dataViewStrategy.HasChilds;
}
}
/// <summary>
/// Returns a <see cref="SharpArrayList"></see>, be carefull, this list is only a Indexlist
/// to the actuall data
/// </summary>
public SharpIndexCollection ChildRows {
get {
return this.dataViewStrategy.ChildRows;
} }
} }
@ -436,7 +400,7 @@ namespace SharpReportCore {
public object Current { public object Current {
get { get {
throw new NotImplementedException("DataManager.Current"); throw new NotImplementedException();
} }
} }
@ -463,10 +427,40 @@ namespace SharpReportCore {
} }
} }
public bool IsSorted {
get {
return this.dataViewStrategy.IsSorted;
}
}
public bool IsFiltered {
get {
return this.dataViewStrategy.IsFiltered;
}
}
#region System.IDisposable interface implementation #region System.IDisposable interface implementation
public void Dispose() { public void Dispose() {
this.connectionObject = null; this.Dispose(true);
this.dataViewStrategy = null; GC.SuppressFinalize(this);
}
~DataManager(){
Dispose(false);
}
protected virtual void Dispose(bool disposing){
try {
if (disposing) {
// Free other state (managed objects).
if (this.dataViewStrategy != null) {
this.dataViewStrategy.Dispose();
}
}
} finally {
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
}
} }
#endregion #endregion

56
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/ExtendedPropertyDescriptor.cs

@ -8,7 +8,7 @@ namespace SharpReportCore {
/// This class supports data binding /// This class supports data binding
/// </summary> /// </summary>
public class SharpPropertyDescriptor : PropertyDescriptor{ public class SharpPropertyDescriptor : PropertyDescriptor{
bool readOnly;
Type componentType; Type componentType;
Type propertyType; Type propertyType;
PropertyInfo prop; PropertyInfo prop;
@ -18,65 +18,59 @@ namespace SharpReportCore {
{ {
this.componentType = componentType; this.componentType = componentType;
this.propertyType = propertyType; this.propertyType = propertyType;
this.readOnly= false;
} }
public override object GetValue (object component) public override object GetValue (object component){
{ if (!componentType.IsAssignableFrom(component.GetType())){
if (!componentType.IsAssignableFrom(component.GetType()))
{
return null; return null;
} }
if (prop == null) if (prop == null) {
prop = componentType.GetProperty (Name); prop = componentType.GetProperty (Name);
object o = prop.GetValue (component, null);
if (o is IList)
{
PropertyTypeHash.Instance[componentType, Name] = SharpArrayList.GetElementType((IList)o, componentType, Name);
} }
return o;
object obj = prop.GetValue (component, null);
if (obj != null) {
if (obj is IList){
PropertyTypeHash.Instance[componentType, Name] = SharpDataCollection<object>.GetElementType((IList)obj, componentType, Name);
}
}
return obj;
} }
public override void SetValue(object component, object value)
{ public override void SetValue(object component, object value) {
if (IsReadOnly) if (IsReadOnly){
return; return;
}
if (prop == null) if (prop == null){
prop = componentType.GetProperty (Name); prop = componentType.GetProperty (Name);
}
prop.SetValue (component, value, null); prop.SetValue (component, value, null);
} }
public override void ResetValue(object component) public override void ResetValue(object component) {
{
return; return;
} }
public override bool CanResetValue(object component) public override bool CanResetValue(object component) {
{
return false; return false;
} }
public override bool ShouldSerializeValue(object component) public override bool ShouldSerializeValue(object component) {
{
return false; return false;
} }
public override Type ComponentType public override Type ComponentType{
{
get { return componentType; } get { return componentType; }
} }
public override bool IsReadOnly public override bool IsReadOnly{
{ get { return false; }
get { return readOnly; }
} }
public override Type PropertyType public override Type PropertyType{
{
get { return propertyType; } get { return propertyType; }
} }
} }

45
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IExtendedList.cs

@ -1,45 +0,0 @@
/*
* Created by SharpDevelop.
* User: Forstmeier Helmut
* Date: 04.08.2005
* Time: 09:06
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
namespace SharpReportCore {
public interface IExtendedList{
///<summary>
/// Build the Hash/IndexList we need for indexing the DataSource
/// </summary>
void BuildHashList (IList list);
/// <summary>
/// This List is used as an Index to the DataSource
/// ListItems are added by derived Classes
/// </summary>
IList IndexList{
get;
}
/// <summary>
/// returns the Name of the <see cref="ExtendedListArray"></see>
/// </summary>
string Name {
get;
}
///<summary>
/// CurrentPosition in <see cref="SharpArrayList"></see>
/// </summary>
int CurrentPosition {
get;set;
}
}
}

41
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/IHierarchicalArray.cs

@ -1,41 +0,0 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace SharpReportCore {
using System;
using SharpReportCore;
using System.Collections;
/// <summary>
///
/// </summary>
/// <remarks>
/// created by - Forstmeier peter
/// created on - 02.12.2005 13:42:08
/// </remarks>
public class IHierarchicalArray : ArrayList,IHierarchicalEnumerable {
/// <summary>
/// Default constructor - initializes all fields to default values
/// </summary>
public IHierarchicalArray(){
}
#region SharpReportCore.IHierarchicalEnumerable interface implementation
public IHierarchyData GetHierarchyData(Object enumeratedItem) {
return enumeratedItem as IHierarchyData;
}
#endregion
}
}

8
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/ListHandling/PropertyTypeHash.cs

@ -12,22 +12,22 @@ namespace SharpReportCore{
Hashtable types = new Hashtable(); Hashtable types = new Hashtable();
private string MakeIndex(Type t, string name) private static string MakeIndex(Type t, string name)
{ {
return t.FullName + '.' + name; return t.FullName + '.' + name;
} }
public object this[Type t, string fieldName] public object this[Type type, string fieldName]
{ {
get get
{ {
return types[MakeIndex(t, fieldName)]; return types[MakeIndex(type, fieldName)];
} }
set set
{ {
if (value == null) if (value == null)
return; return;
string key = MakeIndex(t, fieldName); string key = MakeIndex(type, fieldName);
if (!types.Contains(key)) if (!types.Contains(key))
types.Add(key, value); types.Add(key, value);
} }

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

@ -1,306 +1,229 @@
using System; using System;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace SharpReportCore namespace SharpReportCore
{ {
/// <summary>
/// This class act'S as a IndexList to
/// <see cref="SharpBaseList"></see>
/// </summary> /// </summary>
public class SharpArrayList : ArrayList, IBindingList ,ITypedList,IExtendedList public class SharpIndexCollection :List<BaseComparer> {
{
Type elementType;
string name; string name;
int currentPosition; int currentPosition;
bool allowNew = true; public SharpIndexCollection():this ("SharpIndexList"){
bool allowEdit = true;
bool allowRemove = true;
bool supportsSearching ;
bool supportsSorting ;
bool isSorted;
private ListChangedEventArgs resetEvent = new ListChangedEventArgs(ListChangedType.Reset, -1);
public event ListChangedEventHandler ListChanged;
public SharpArrayList(Type elementType,string name){
this.Clear();
this.elementType = elementType;
this.name = name;
Reset();
} }
#region ITypedList Member public SharpIndexCollection(string name){
this.name = name;
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){
if (listAccessors != null && listAccessors.Length > 0){
Type t = this.elementType;
for(int i = 0; i < listAccessors.Length; i++){
PropertyDescriptor pd = listAccessors[i];
// System.Diagnostics.Debug.WriteLine("*** " + t.FullName + ": " + pd.Name);
t = (Type) PropertyTypeHash.Instance[t, pd.Name];
}
// System.Diagnostics.Debug.WriteLine("*** New Collection for " + t.FullName);
// if t is null an empty list will be generated
return SharpTypeDescriptor.GetProperties(t);
}
return SharpTypeDescriptor.GetProperties(elementType);
}
public static Type GetElementType(IList list,
Type parentType,
string propertyName){
SharpArrayList al = list as SharpArrayList;
if (al == null)
return null;
return al.elementType;
}
#if longVersion
public static Type GetElementType(IList list,
Type parentType,
string propertyName){
SharpArrayList al = null;
object element = null;
al = CheckForArrayList(list);
if (al == null){
if (list.Count > 0){
element = list[0];
}
}
if (al == null && element == null){
PropertyInfo pi = parentType.GetProperty(propertyName);
if (pi != null){
object parentObject = null;
try{
parentObject = Activator.CreateInstance(parentType);
}
catch(Exception ex) {}
if (parentObject != null){
list = pi.GetValue(parentObject, null) as IList;
al = CheckForArrayList(list);
}
}
}
if (al != null){
return al.elementType;
}
else if (element != null){
return element.GetType();
}
return null;
}
private static SharpArrayList CheckForArrayList(object l){
IList list = l as IList;
if (list == null)
return null;
if (list.GetType().FullName == "System.Collections.ArrayList+ReadOnlyArrayList"){
FieldInfo fi = list.GetType().GetField("_list", BindingFlags.NonPublic | BindingFlags.Instance);
if (fi != null){
list = (IList) fi.GetValue(list);
}
}
return list as SharpArrayList;
}
#endif
public string GetListName(PropertyDescriptor[] listAccessors){
return elementType.Name;
}
#endregion
protected void Reset(){
this.currentPosition = 0;
this.OnListChange (resetEvent);
}
private void OnListChange (ListChangedEventArgs handler) {
if (this.ListChanged != null) {
this.ListChanged (this,handler);
}
} }
#region System.ComponentModel.IBindingList interface implementation #region properties
public bool AllowNew {
public int CurrentPosition {
get { get {
return this.allowNew; return currentPosition;
} }
} set {
currentPosition = value;
public bool AllowEdit {
get {
return this.allowEdit;
} }
} }
public bool AllowRemove { public string Name {
get { get {
return this.allowRemove; return name;
} }
} }
public bool SupportsChangeNotification {
get {
return true;
}
}
public bool SupportsSearching { #endregion
get { }
return this.supportsSearching;
} /// <summary>
set { /// This class act's as a store of the original Data
this.supportsSearching = value; /// </summary>
}
} public class SharpDataCollection<T> : IList<T>,ITypedList{
Collection<T> list = new Collection<T>();
Type elementType;
public bool SupportsSorting { public SharpDataCollection(Type elementType)
get { {
return this.supportsSorting; this.elementType = elementType;
}
set {
this.supportsSorting = value;
}
} }
public bool IsSorted { public T this[int index] {
get { get {
return this.isSorted; return list[index];
} }
set { set {
this.isSorted = value; T oldValue = list[index];
if (!object.Equals(oldValue, value)) {
list[index] = value;
}
} }
} }
public System.ComponentModel.PropertyDescriptor SortProperty { public int Count {
[DebuggerStepThrough]
get { get {
return null; return list.Count;
} }
} }
public System.ComponentModel.ListSortDirection SortDirection { public bool IsReadOnly {
get { get {
return ListSortDirection.Ascending; return false;
} }
} }
public void RemoveSort() { public int IndexOf(T item)
throw new NotImplementedException("RemoveSort"); {
} return list.IndexOf(item);
//TODO Test fehlt
public void RemoveIndex(System.ComponentModel.PropertyDescriptor property) {
throw new NotImplementedException("RemoveIndex");
} }
//TODO Test fehlt public void Insert(int index, T item)
public int Find(System.ComponentModel.PropertyDescriptor property, object key) { {
// return 0; list.Insert(index, item);
throw new NotImplementedException("Find");
} }
//TODO Test fehlt
public void ApplySort(System.ComponentModel.PropertyDescriptor property, System.ComponentModel.ListSortDirection direction) { public void RemoveAt(int index)
throw new NotImplementedException("ApplySort"); {
} // T item = list[index];
//TODO Test fehlt list.RemoveAt(index);
public void AddIndex(System.ComponentModel.PropertyDescriptor property) {
throw new NotImplementedException("AddIndex");
} }
public object AddNew() { public void Add(T item)
throw new NotImplementedException("AddNew"); {
list.Add(item);
} }
#endregion public void AddRange(IList range)
{
#region overrides foreach(T t in range) {
public override int Add(object value) { Add(t);
if (this.elementType.GetType().IsAssignableFrom (value.GetType())) {
System.Console.WriteLine("type ok");
}
if ((value.GetType().IsSubclassOf(this.elementType))||( value.GetType() == this.elementType)){
if (this.allowNew) {
int i = base.Add(value);
this.OnListChange (new ListChangedEventArgs(ListChangedType.ItemAdded,i));
return i;
} else {
throw new NotSupportedException("SharpArrayList:Add(object)");
}
} else {
string str = String.Format("Add:Wrong Type {0} {1}",this.elementType,value.GetType());
throw new ArgumentException(str);
} }
} }
public override void AddRange(System.Collections.ICollection c) { public void Clear(){
foreach (object o in c) { list = new Collection<T>();
this.Add (o);
}
} }
public bool Contains(T item)
public override void RemoveAt(int index) { {
if (this.allowRemove) { return list.Contains(item);
if (index > -1) {
base.RemoveAt(index);
this.OnListChange (new ListChangedEventArgs(ListChangedType.ItemDeleted,index));
}
} else {
throw new NotSupportedException("SharpArrayList:RemoveAt (index)");
}
} }
public void CopyTo(T[] array, int arrayIndex)
#endregion {
list.CopyTo(array, arrayIndex);
#region SharpReport.Data.IExtendedList interface implementation
public string Name {
get {
return this.name;
}
} }
public int CurrentPosition { public bool Remove(T item)
get { {
return currentPosition; if (list.Remove(item)) {
return true;
} }
set { return false;
currentPosition = value; }
#region ITypedList Member
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors){
if (listAccessors != null && listAccessors.Length > 0){
Type t = this.elementType;
for(int i = 0; i < listAccessors.Length; i++){
PropertyDescriptor pd = listAccessors[i];
t = (Type) PropertyTypeHash.Instance[t, pd.Name];
}
// if t is null an empty list will be generated
return SharpTypeDescriptor.GetProperties(t);
} }
return SharpTypeDescriptor.GetProperties(elementType);
}
public string GetListName(PropertyDescriptor[] listAccessors){
return elementType.Name;
} }
public static Type GetElementType(IList list, Type parentType, string propertyName)
public IList IndexList { {
get { SharpDataCollection<T> al = null;
return(IList)this; object element = null;
al = CheckForArrayList(list);
if (al == null)
{
if (list.Count > 0)
{
element = list[0];
}
} }
if (al == null && element == null)
{
PropertyInfo pi = parentType.GetProperty(propertyName);
if (pi != null)
{
object parentObject = null;
try
{
parentObject = Activator.CreateInstance(parentType);
}
catch(Exception) {}
if (parentObject != null)
{
list = pi.GetValue(parentObject, null) as IList;
al = CheckForArrayList(list);
}
}
}
if (al != null)
{
return al.elementType;
}
else if (element != null)
{
return element.GetType();
}
return null;
} }
public void BuildHashList(IList list) { private static SharpDataCollection<T> CheckForArrayList(object l)
throw new NotImplementedException("SharpArrayList:BuildHashList"); {
/* IList list = l as IList;
this.Clear(); if (list == null)
for (int i = 0;i < list.Count ;i++ ) { return null;
// this.Add (new PlainIndexItem(i,"satz " + i.ToString())); if (list.GetType().FullName == "System.Collections.ArrayList+ReadOnlyArrayList")
{
FieldInfo fi = list.GetType().GetField("_list", BindingFlags.NonPublic | BindingFlags.Instance);
if (fi != null)
{
list = (IList) fi.GetValue(list);
}
} }
this.OnListChange (new ListChangedEventArgs(ListChangedType.Reset,-1,-1)); return list as SharpDataCollection<T>;
*/
} }
#endregion #endregion
[DebuggerStepThrough]
public IEnumerator<T> GetEnumerator()
{
return list.GetEnumerator();
}
[DebuggerStepThrough]
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return list.GetEnumerator();
}
} }
} }

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

@ -16,7 +16,7 @@ using System.Collections.Generic;
using SharpReportCore; using SharpReportCore;
/// <summary> /// <summary>
/// BaseClass for all datahandling Strategies /// BaseClass for all Datahandling Strategies
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// created by - Forstmeier Peter /// created by - Forstmeier Peter
@ -30,10 +30,9 @@ namespace SharpReportCore {
private bool isGrouped; private bool isGrouped;
//Index to plain Datat //Index to plain Datat
private SharpArrayList indexList; private SharpIndexCollection indexList;
private ReportSettings reportSettings; private ReportSettings reportSettings;
private IHierarchicalArray hierarchicalList;
private ListChangedEventArgs resetList = new ListChangedEventArgs(ListChangedType.Reset,-1,-1); private ListChangedEventArgs resetList = new ListChangedEventArgs(ListChangedType.Reset,-1,-1);
@ -43,20 +42,16 @@ namespace SharpReportCore {
#region Constructor #region Constructor
protected BaseListStrategy(ReportSettings reportSettings) { protected BaseListStrategy(ReportSettings reportSettings) {
if (reportSettings == null) {
throw new ArgumentNullException("reportSettings");
}
this.reportSettings = reportSettings; this.reportSettings = reportSettings;
this.indexList = new SharpArrayList(typeof(BaseComparer),"IndexList"); this.indexList = new SharpIndexCollection("IndexList");
} }
#endregion #endregion
#region Event's #region Event's
protected void NotifyGroupChange (object source,GroupSeperator groupSeperator) {
if (this.GroupChanged != null) {
this.GroupChanged (source,new GroupChangedEventArgs(groupSeperator));
}
}
protected void NotifyResetList(){ protected void NotifyResetList(){
if (this.ListChanged != null) { if (this.ListChanged != null) {
@ -64,10 +59,18 @@ namespace SharpReportCore {
} }
} }
protected void NotifyGroupChanging (object source,GroupSeperator groupSeperator) {
if (this.GroupChanged != null) {
this.GroupChanged (source,new GroupChangedEventArgs(groupSeperator));
}
}
#endregion #endregion
public SharpArrayList IndexList { public SharpIndexCollection IndexList {
get { get {
return indexList; return indexList;
} }
@ -79,21 +82,87 @@ namespace SharpReportCore {
return reportSettings; return reportSettings;
} }
} }
#region Building Groups
private static void WriteToIndexFile (SharpIndexCollection destination,BaseComparer comparer) {
SortComparer sc = comparer as SortComparer;
// if (sc != null) {
// System.Console.WriteLine("\t {0} - <{1}>",comparer.ListIndex, comparer.ObjectArray[0].ToString());
// } else {
// System.Console.WriteLine("Wrong comparer");
// }
destination.Add(comparer);
}
protected void CheckSortArray (ArrayList arr,string text){ private static GroupSeperator BuildGroupSeperator (BaseComparer newGroup,int groupLevel) {
// System.Console.WriteLine("");
GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection,
newGroup.ListIndex,
newGroup.ObjectArray,
groupLevel);
// System.Console.WriteLine("Add Parent <{0}>",seperator.ObjectArray[0].ToString());
return seperator;
}
protected void MakeGroupedIndexList (SharpIndexCollection sourceList) {
if (sourceList == null) {
throw new ArgumentNullException("sourceList");
}
int level = 0;
this.indexList.Clear();
SortComparer compareComparer = null;
GroupSeperator parent = null;
// System.Console.WriteLine("MakeGroupedIndexList with {0} rows",sourceList.Count);
for (int i = 0;i < sourceList.Count ;i++ ) {
SortComparer currentComparer = (SortComparer)sourceList[i];
/*
System.Console.WriteLine("\t\t\t performing nr {0}",i);
if (i == 68) {
System.Console.WriteLine("last");
}
*/
if (compareComparer != null) {
string str1,str2;
str1 = currentComparer.ObjectArray[0].ToString();
str2 = compareComparer.ObjectArray[0].ToString();
int compareVal = str1.CompareTo(str2);
if (compareVal != 0) {
BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer);
parent = BaseListStrategy.BuildGroupSeperator (currentComparer,level);
this.indexList.Add(parent);
BaseListStrategy.WriteToIndexFile(parent.GetChildren,currentComparer);
} else {
BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer);
}
}
else {
parent = BaseListStrategy.BuildGroupSeperator (currentComparer,level);
this.indexList.Add(parent);
}
compareComparer = (SortComparer)sourceList[i];
}
BaseListStrategy.WriteToIndexFile(parent.GetChildren,compareComparer);
}
#endregion
protected static void CheckSortArray (SharpIndexCollection arr,string text){
System.Console.WriteLine("{0}",text); System.Console.WriteLine("{0}",text);
// string tabs = String.Empty;
if (arr != null) { if (arr != null) {
int row = 0; int row = 0;
foreach (BaseComparer bc in arr) { foreach (BaseComparer bc in arr) {
GroupSeperator sep = bc as GroupSeperator; GroupSeperator sep = bc as GroupSeperator;
if (sep != null) { if (sep != null) {
// System.Console.WriteLine("\t Group change {0} level {1}",sep.ObjectArray[0].ToString(),
// sep.GroupLevel);
} else { } else {
object [] oarr = bc.ObjectArray; object [] oarr = bc.ObjectArray;
@ -107,12 +176,10 @@ namespace SharpReportCore {
} }
} }
System.Console.WriteLine("----------------"); System.Console.WriteLine("-----End of <CheckSortArray>-----------");
System.Console.WriteLine("");
} }
#region SharpReportCore.IDataViewStrategy interface implementation #region SharpReportCore.IDataViewStrategy interface implementation
public virtual ColumnCollection AvailableFields { public virtual ColumnCollection AvailableFields {
@ -133,8 +200,7 @@ namespace SharpReportCore {
} }
set { set {
if (value > this.indexList.Count){ if (value > this.indexList.Count){
throw new IndexOutOfRangeException ("There is no row at " + throw new IndexOutOfRangeException ();
"currentRow: " + value + ".");
} }
this.indexList.CurrentPosition = value; this.indexList.CurrentPosition = value;
} }
@ -167,15 +233,10 @@ namespace SharpReportCore {
get { get {
return this.isGrouped; return this.isGrouped;
} }
set {
this.isGrouped = true;
}
} }
protected virtual void Group() { protected virtual void Group() {
if (this.indexList != null) { if (this.indexList != null) {
this.BuildHierarchicalList (this.indexList);
this.isGrouped = true; this.isGrouped = true;
this.isSorted = true; this.isSorted = true;
} else { } else {
@ -185,123 +246,77 @@ namespace SharpReportCore {
} }
protected IHierarchicalArray HierarchicalList {
get {
return hierarchicalList;
}
}
public virtual void Sort() {
this.indexList.Clear();
}
public virtual void Reset() {
this.NotifyResetList();
}
private GroupSeperator MakeSeperator (BaseComparer newGroup,int groupLevel) { public virtual void Bind() {
GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection,
newGroup.ListIndex,
newGroup.ObjectArray,
groupLevel);
// System.Console.WriteLine("");
// System.Console.WriteLine("\t Group change {0} level {1}",seperator.ObjectArray[0].ToString(),
// seperator.GroupLevel);
// System.Console.WriteLine("");
return seperator;
} }
public virtual void Fill(IItemRenderer item) {
private IHierarchicalEnumerable BuildHierarchicalList(ArrayList sourceList) { }
IHierarchicalArray destList = new IHierarchicalArray();
IHierarchicalArray childList = new IHierarchicalArray(); public bool HasChilds {
int level = 0; get {
if (this.IsGrouped == true) {
// System.Console.WriteLine(""); GroupSeperator gs = (GroupSeperator)this.indexList[this.CurrentRow] as GroupSeperator;
// System.Console.WriteLine("BuildHierachicalList"); if (gs != null) {
return (gs.GetChildren.Count > 0);
// ColumnCollection grBy =this.reportSettings.GroupColumnsCollection; } else {
// string columnName = grBy[level].ColumnName; return false;
GroupComparer compareComparer = null;
GroupSeperator seperator = null;
destList.Clear();
childList.Clear();
for (int i = 0;i < sourceList.Count ;i++ ) {
GroupComparer currentComparer = (GroupComparer)sourceList[i];
if (compareComparer != null) {
string str1,str2;
str1 = currentComparer.ObjectArray[0].ToString();
str2 = compareComparer.ObjectArray[0].ToString();
int compareVal = str1.CompareTo(str2);
if (compareVal != 0) {
// System.Console.WriteLine("child list with {0} entries",childList.Count);
seperator.Childs = childList;
/*
//testcode
if (childList != null) {
foreach (BaseComparer bc in seperator.Childs) {
System.Console.WriteLine("\t {0} {1}",bc.ListIndex,
bc.ObjectArray[0].ToString());
}
}
// end testCode
*/
childList = new IHierarchicalArray();
seperator = MakeSeperator (currentComparer,level);
childList.Clear();
destList.Add (seperator);
} }
} else {
return false;
} }
else {
// System.Console.WriteLine("\t\t Start of List {0}",currentComparer.ObjectArray[0].ToString());
//
// System.Console.WriteLine("Group change ");
seperator = MakeSeperator (currentComparer,level);
childList.Clear();
destList.Add (seperator);
seperator.Childs = childList;
}
// System.Console.WriteLine("write {0} {1}",currentComparer.ListIndex,currentComparer.ObjectArray[0].ToString());
childList.Add (currentComparer);
compareComparer = (GroupComparer)sourceList[i];
} }
// Add the last list
seperator.Childs = childList;
this.hierarchicalList = destList;
return destList;
} }
public IHierarchicalEnumerable IHierarchicalEnumerable { public SharpIndexCollection ChildRows {
get { get {
return this.hierarchicalList; if (this.IsGrouped == true) {
GroupSeperator gs = (GroupSeperator)this.indexList[this.CurrentRow] as GroupSeperator;
if (gs != null) {
return (gs.GetChildren);
} else {
return null;
}
} else {
return null;
}
} }
} }
public virtual void Sort() { public virtual void Dispose(){
this.Dispose(true);
GC.SuppressFinalize(this);
} }
public virtual void Reset() { ~BaseListStrategy(){
this.NotifyResetList(); Dispose(false);
} }
public virtual void Bind() { protected virtual void Dispose(bool disposing){
if (disposing) {
// Free other state (managed objects).
if (this.indexList != null) {
this.indexList.Clear();
this.indexList = null;
}
}
} // Release unmanaged resources.
// Set large fields to null.
public virtual void Fill(IItemRenderer item) { // Call Dispose on your base class.
} }
#endregion #endregion
} }
} }

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

@ -23,29 +23,67 @@ namespace SharpReportCore {
public class CollectionStrategy : BaseListStrategy { public class CollectionStrategy : BaseListStrategy {
// Holds the plain Data // Holds the plain Data
private SharpArrayList baseList;
private Type itemType; private Type itemType;
private object firstItem; private object firstItem;
private object current; private object current;
private PropertyDescriptorCollection listProperties; private PropertyDescriptorCollection listProperties;
private SharpDataCollection<object> baseList;
public CollectionStrategy(IList list,string dataMember,ReportSettings reportSettings):base(reportSettings) { public CollectionStrategy(IList list,string dataMember,ReportSettings reportSettings):base(reportSettings) {
if (list.Count > 0) { if (list.Count > 0) {
firstItem = list[0]; firstItem = list[0];
itemType = firstItem.GetType(); itemType = firstItem.GetType();
this.baseList = new SharpArrayList(itemType,dataMember);
this.baseList = new SharpDataCollection <object>(itemType);
this.baseList.AddRange(list); this.baseList.AddRange(list);
this.baseList.CurrentPosition = 0;
this.current = this.baseList[0];
} }
this.listProperties = this.baseList.GetItemProperties(null);
} }
private void BuildGroup(){ private void BuildGroup(){
// throw new NotImplementedException("No grouping at the time");
return; try {
SharpIndexCollection groupedArray = new SharpIndexCollection();
if (base.ReportSettings.GroupColumnsCollection != null) {
if (base.ReportSettings.GroupColumnsCollection.Count > 0) {
this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection);
}
}
base.MakeGroupedIndexList (groupedArray);
foreach (BaseComparer bc in this.IndexList) {
GroupSeperator gs = bc as GroupSeperator;
if (gs != null) {
System.Console.WriteLine("Group Header <{0}> with <{1}> Childs ",gs.ObjectArray[0].ToString(),gs.GetChildren.Count);
if (gs.HasChildren) {
foreach (SortComparer sc in gs.GetChildren) {
System.Console.WriteLine("\t {0} {1}",sc.ListIndex,sc.ObjectArray[0].ToString()); }
}
} else {
SortComparer sc = bc as SortComparer;
if (sc != null) {
System.Console.WriteLine("\t Child {0}",sc.ObjectArray[0].ToString());
}
}
}
} catch (Exception e) {
System.Console.WriteLine("BuildGroup {0}",e.Message);
throw;
}
} }
private PropertyDescriptor[] BuildSortProperties (ColumnCollection col){ private PropertyDescriptor[] BuildSortProperties (ColumnCollection col){
@ -66,69 +104,54 @@ namespace SharpReportCore {
} }
#region Index Building #region Index Building
private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) {
//Sorted Indexlist
private ArrayList BuildSortIndex(ColumnCollection col) {
PropertyDescriptor[] sortProperties = BuildSortProperties (col); PropertyDescriptor[] sortProperties = BuildSortProperties (col);
for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){
// Übertragen der zu sortierenden Werte in eine standartComparer Auflistung object rowItem = this.baseList[rowIndex];
ArrayList sortValues = new ArrayList(this.baseList.Count); object[] values = new object[col.Count];
try {
for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ // Hier bereits Wertabruf um dies nicht während des Sortierens tun zu müssen.
object rowItem = this.baseList[rowIndex]; for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++){
object[] values = new object[col.Count]; object value = sortProperties[criteriaIndex].GetValue(rowItem);
// Hier auf Verträglichkeit testen um Vergleiche bei Sortierung zu vereinfachen.
// Muss IComparable und gleicher Typ sein.
// Hier bereits Wertabruf um dies nicht während des Sortierens tun zu müssen. if (value != null && value != DBNull.Value)
for (int criteriaIndex = 0; criteriaIndex < sortProperties.Length; criteriaIndex++){ {
object value = sortProperties[criteriaIndex].GetValue(rowItem); if (!(value is IComparable)){
// Hier auf Verträglichkeit testen um Vergleiche bei Sortierung zu vereinfachen. throw new InvalidOperationException("ReportDataSource:BuildSortArray - > This type doesn't support IComparable." + value.ToString());
// Muss IComparable und gleicher Typ sein.
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;
} }
values[criteriaIndex] = value;
} }
sortValues.Add(new SortComparer(col, rowIndex, values));
} }
} catch (Exception) { arrayList.Add(new SortComparer(col, rowIndex, values));
throw ;
} }
arrayList.Sort();
sortValues.Sort();
return sortValues;
} }
// if we have no sorting, we build the indexlist as well, so we don't need to // 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 //check each time we reasd data if we have to go directly or by IndexList
private void BuildPlainIndex(SharpIndexCollection arrayList,ColumnCollection col) {
private ArrayList BuildPlainIndex(ColumnCollection col) {
PropertyDescriptor[] sortProperties = new PropertyDescriptor[1]; PropertyDescriptor[] sortProperties = new PropertyDescriptor[1];
PropertyDescriptorCollection c = this.baseList.GetItemProperties(null); PropertyDescriptorCollection c = this.baseList.GetItemProperties(null);
PropertyDescriptor descriptor = c[0]; PropertyDescriptor descriptor = c[0];
sortProperties[0] = descriptor; sortProperties[0] = descriptor;
ArrayList sortValues = new ArrayList(this.baseList.Count);
try { for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){
for (int rowIndex = 0; rowIndex < this.baseList.Count; rowIndex++){ object[] values = new object[1];
object[] values = new object[1];
// We insert only the RowNr as a dummy value
// We insert only the RowNr as a dummy value values[0] = rowIndex;
values[0] = rowIndex; arrayList.Add(new BaseComparer(col, rowIndex, values));
sortValues.Add(new BaseComparer(col, rowIndex, values));
}
} catch (Exception) {
throw ;
} }
return sortValues;;
} }
#endregion #endregion
#region SharpReportCore.IDataViewStrategy interface implementation #region SharpReportCore.IDataViewStrategy interface implementation
@ -156,7 +179,6 @@ namespace SharpReportCore {
set { set {
base.CurrentRow = value; base.CurrentRow = value;
current = this.baseList[((BaseComparer)base.IndexList[value]).ListIndex]; current = this.baseList[((BaseComparer)base.IndexList[value]).ListIndex];
} }
} }
@ -164,28 +186,19 @@ namespace SharpReportCore {
public override void Sort() { public override void Sort() {
base.Sort(); base.Sort();
ArrayList sortedArray = new ArrayList(); if ((base.ReportSettings.SortColumnCollection != null)) {
try { if (base.ReportSettings.SortColumnCollection.Count > 0) {
ColumnCollection sortColumnCollection = base.ReportSettings.SortColumnCollection; this.BuildSortIndex (base.IndexList,
if (sortColumnCollection != null) { base.ReportSettings.SortColumnCollection);
if (sortColumnCollection.Count > 0) {
sortedArray = this.BuildSortIndex (sortColumnCollection);
base.IsSorted = true; base.IsSorted = true;
} else { // BaseListStrategy.CheckSortArray (base.IndexList,"TableStrategy - CheckSortArray");
sortedArray = BuildPlainIndex (sortColumnCollection); } else {
base.IsSorted = false; this.BuildPlainIndex(base.IndexList,
} base.ReportSettings.SortColumnCollection);
base.IsSorted = false;
} }
base.IndexList.Clear();
base.IndexList.AddRange (sortedArray);
// base.CheckSortArray (sortedArray,"CollectionStrategy - CheckSortArray");
} catch (Exception) {
throw;
}
if (base.IndexList == null){
throw new NotSupportedException("Sortieren für die Liste nicht unterstützt.");
} }
} }
@ -200,24 +213,23 @@ namespace SharpReportCore {
public override void Bind() { public override void Bind() {
base.Bind(); base.Bind();
if (base.IndexList.Count > 0) {
base.IndexList.Clear();
}
this.listProperties = this.baseList.GetItemProperties(null);
if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) { if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) {
BuildGroup (); this.Group ();
Reset();
return;
} }
this.Sort (); if (base.ReportSettings.SortColumnCollection != null) {
this.Reset(); this.Sort ();
base.NotifyResetList(); }
Reset();
} }
public override void Fill(IItemRenderer item) { public override void Fill(IItemRenderer item) {
base.Fill(item); try {
if (current != null) { base.Fill(item);
try { if (current != null) {
BaseDataItem baseDataItem = item as BaseDataItem; BaseDataItem baseDataItem = item as BaseDataItem;
PropertyDescriptor p = this.listProperties.Find (baseDataItem.ColumnName,true); PropertyDescriptor p = this.listProperties.Find (baseDataItem.ColumnName,true);
@ -225,12 +237,50 @@ namespace SharpReportCore {
baseDataItem.DbValue = ""; baseDataItem.DbValue = "";
baseDataItem.DbValue = p.GetValue(this.current).ToString(); baseDataItem.DbValue = p.GetValue(this.current).ToString();
} }
} catch (Exception) {
} }
} catch (System.NullReferenceException) {
}
}
protected override void Group() {
if (base.ReportSettings.GroupColumnsCollection.Count == 0) {
return;
} }
this.BuildGroup();
base.Group();
} }
#endregion #endregion
#region IDisposable
public override void Dispose(){
this.Dispose(true);
GC.SuppressFinalize(this);
}
~CollectionStrategy(){
Dispose(false);
}
protected override void Dispose(bool disposing){
try {
if (disposing) {
if (this.baseList != null) {
this.baseList.Clear();
this.baseList = null;
}
}
} finally {
base.Dispose(disposing);
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
}
}
#endregion
} }
} }

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

@ -24,7 +24,7 @@ namespace SharpReportCore {
/// created by - Forstmeier Peter /// created by - Forstmeier Peter
/// created on - 23.10.2005 15:12:06 /// created on - 23.10.2005 15:12:06
/// </remarks> /// </remarks>
public class TableStrategy : BaseListStrategy,IDisposable { public class TableStrategy : BaseListStrategy {
DataTable table; DataTable table;
DataView view = new DataView(); DataView view = new DataView();
@ -32,44 +32,19 @@ namespace SharpReportCore {
public TableStrategy(DataTable table,ReportSettings reportSettings):base(reportSettings) { public TableStrategy(DataTable table,ReportSettings reportSettings):base(reportSettings) {
if (table == null) {
throw new ArgumentNullException("table");
}
this.table = table; this.table = table;
// view.ListChanged += new ListChangedEventHandler (OnListChange); view = this.table.DefaultView;
} }
// private void OnListChange (object sender,ListChangedEventArgs e) {
// System.Console.WriteLine("called from view");
// MessageBox.Show ("On List Change");
// }
/*
private string a_BuildSort(ColumnCollection sortCollection){
System.Console.WriteLine("BuildSort");
StringBuilder sb = new StringBuilder();
for (int i = 0;i < sortCollection.Count ;i++ ) {
SortColumn sc = (SortColumn)sortCollection[i];
sb.Append(sc.ColumnName);
if (sc.SortDirection == ListSortDirection.Ascending) {
sb.Append (" ASC");
} else {
sb.Append(" DESC");
}
sb.Append (",");
}
if (sb.ToString().EndsWith (",")) {
sb.Remove(sb.Length -1,1);
}
System.Console.WriteLine("\tsort by {0}",sb.ToString());
return sb.ToString();
}
*/
#region Building the Index list #region Building the Index list
// if we have no sorting, we build the indexlist as well, so we don't need to private void BuildSortIndex(SharpIndexCollection arrayList,ColumnCollection col) {
//check each time we reasd data if we have to go directly or by IndexList
private ArrayList BuildSortIndex(ColumnCollection col) {
ArrayList sortValues = new ArrayList(this.view.Count);
try { try {
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){ for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
DataRowView rowItem = this.view[rowIndex]; DataRowView rowItem = this.view[rowIndex];
@ -88,171 +63,79 @@ namespace SharpReportCore {
values[criteriaIndex] = DBNull.Value; values[criteriaIndex] = DBNull.Value;
} }
} }
sortValues.Add(new SortComparer(col, rowIndex, values)); arrayList.Add(new SortComparer(col, rowIndex, values));
} }
} catch (Exception) { } catch (Exception) {
throw;
} }
sortValues.Sort();
return sortValues;
}
private ArrayList BuildPlainIndex(ColumnCollection col) { arrayList.Sort();
ArrayList sortValues = new ArrayList(this.view.Count); }
// 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 { try {
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){ for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
object[] values = new object[1]; object[] values = new object[1];
// We insert only the RowNr as a dummy value // We insert only the RowNr as a dummy value
values[0] = rowIndex; values[0] = rowIndex;
sortValues.Add(new BaseComparer(col, rowIndex, values)); arrayList.Add(new BaseComparer(col, rowIndex, values));
} }
} catch (Exception) { } catch (Exception) {
throw ; throw ;
} }
return sortValues;;
} }
private ArrayList BuildGroupIndex(ColumnCollection col) {
ArrayList groupValues = new ArrayList(this.view.Count);
System.Console.WriteLine("\tBuildGroupIndex");
try {
for (int rowIndex = 0; rowIndex < this.view.Count; rowIndex++){
DataRowView rowItem = this.view[rowIndex];
object[] values = new object[col.Count];
for (int criteriaIndex = 0; criteriaIndex < col.Count; criteriaIndex++){
AbstractColumn c = (AbstractColumn)col[criteriaIndex];
object value = rowItem[c.ColumnName];
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;
} else {
values[criteriaIndex] = DBNull.Value;
}
}
groupValues.Add(new GroupComparer(col, rowIndex, values));
}
} catch (Exception) {
}
groupValues.Sort();
return groupValues;
}
#endregion #endregion
#region Grouping #region Grouping
private void WriteToIndexFile (ArrayList destination,int index,GroupComparer comparer) {
destination.Add(comparer);
}
private void BuildGroupSeperator (ArrayList destination,BaseComparer newGroup,int groupLevel) {
GroupSeperator seperator = new GroupSeperator (newGroup.ColumnCollection,
newGroup.ListIndex,
newGroup.ObjectArray,
groupLevel);
// System.Console.WriteLine("\t Group change {0} level {1}",seperator.ObjectArray[0].ToString(),
// seperator.GroupLevel);
// System.Console.WriteLine("write group seperator");
destination.Add(seperator);
}
private ArrayList InsertGroupRows (ArrayList sourceList) {
ArrayList destList = new ArrayList();
int level = 0;
// // only for testing
// ColumnCollection grBy = base.ReportSettings.GroupColumnsCollection;
// string columnName = grBy[level].ColumnName;
//// System.Console.WriteLine("");
// System.Console.WriteLine("InsertGroupRows Grouping for {0}",columnName);
GroupComparer compareComparer = null;
for (int i = 0;i < sourceList.Count ;i++ ) {
GroupComparer currentComparer = (GroupComparer)sourceList[i];
if (compareComparer != null) {
string str1,str2;
str1 = currentComparer.ObjectArray[0].ToString();
str2 = compareComparer.ObjectArray[0].ToString();
int compareVal = str1.CompareTo(str2);
if (compareVal != 0) {
this.BuildGroupSeperator (destList,currentComparer,level);
}
}
else {
// System.Console.WriteLine("\t\t Start of List {0}",currentComparer.ObjectArray[0].ToString());
this.BuildGroupSeperator (destList,currentComparer,level);
}
this.WriteToIndexFile (destList,i,currentComparer);
compareComparer = (GroupComparer)sourceList[i];
}
return destList;
}
private void BuildGroup(){ private void BuildGroup(){
try { try {
ArrayList groupedArray = new ArrayList(); SharpIndexCollection groupedArray = new SharpIndexCollection();
if (base.ReportSettings.GroupColumnsCollection != null) { if (base.ReportSettings.GroupColumnsCollection != null) {
if (base.ReportSettings.GroupColumnsCollection.Count > 0) { if (base.ReportSettings.GroupColumnsCollection.Count > 0) {
groupedArray = this.BuildGroupIndex (base.ReportSettings.GroupColumnsCollection); this.BuildSortIndex (groupedArray,base.ReportSettings.GroupColumnsCollection);
System.Console.WriteLine("\t1");
} else {
groupedArray = BuildPlainIndex (base.ReportSettings.GroupColumnsCollection);
} }
} }
base.IndexList.Clear(); base.MakeGroupedIndexList (groupedArray);
base.IndexList.AddRange (InsertGroupRows(groupedArray));
// System.Console.WriteLine("GroupedList with {0} elements",base.IndexList.Count);
if (base.IndexList == null){ /*
throw new NotSupportedException("Sortieren für die Liste nicht unterstützt."); foreach (BaseComparer bc in this.IndexList) {
GroupSeperator gs = bc as GroupSeperator;
if (gs != null) {
// System.Console.WriteLine("Group Header <{0}> with <{1}> Childs ",gs.ObjectArray[0].ToString(),gs.GetChildren.Count);
if (gs.HasChildren) {
foreach (SortComparer sc in gs.GetChildren) {
System.Console.WriteLine("\t {0} {1}",sc.ListIndex,sc.ObjectArray[0].ToString()); }
}
} else {
SortComparer sc = bc as SortComparer;
if (sc != null) {
System.Console.WriteLine("\t Child {0}",sc.ObjectArray[0].ToString());
}
}
} }
*/
} catch (Exception e) { } catch (Exception e) {
System.Console.WriteLine("BuildGroup {0}",e.Message); System.Console.WriteLine("BuildGroup {0}",e.Message);
throw; throw;
} }
} }
protected override void Group() {
if (base.ReportSettings.GroupColumnsCollection.Count == 0) {
return;
}
try {
this.BuildGroup();
base.Group();
if (this.IsGrouped == false) {
throw new SharpReportException("TableStratregy:Group Error in grouping");
}
} catch (Exception e) {
System.Console.WriteLine("Group {0}",e.Message);
base.IsGrouped = false;
base.IsSorted = false;
throw;
}
}
#endregion #endregion
@ -260,12 +143,10 @@ namespace SharpReportCore {
public override void Bind() { public override void Bind() {
base.Bind(); base.Bind();
view = this.table.DefaultView;
if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) { if ((base.ReportSettings.GroupColumnsCollection != null) && (base.ReportSettings.GroupColumnsCollection.Count > 0)) {
this.Group (); this.Group ();
Reset(); Reset();
base.NotifyResetList();
return; return;
} }
@ -273,47 +154,44 @@ namespace SharpReportCore {
this.Sort (); this.Sort ();
} }
Reset(); Reset();
base.NotifyResetList();
} }
public override void Sort () { public override void Sort () {
base.Sort(); base.Sort();
ArrayList sortedArray = new ArrayList(); if ((base.ReportSettings.SortColumnCollection != null)) {
try { if (base.ReportSettings.SortColumnCollection.Count > 0) {
if ((base.ReportSettings.SortColumnCollection != null)) { this.BuildSortIndex (base.IndexList,
if (base.ReportSettings.SortColumnCollection.Count > 0) { base.ReportSettings.SortColumnCollection);
SortColumn sc = (SortColumn)base.ReportSettings.SortColumnCollection[0];
base.IsSorted = true;
sortedArray = this.BuildSortIndex (base.ReportSettings.SortColumnCollection); } else {
base.IsSorted = true; this.BuildPlainIndex(base.IndexList,
} else { base.ReportSettings.SortColumnCollection);
sortedArray = BuildPlainIndex (base.ReportSettings.SortColumnCollection); base.IsSorted = false;
base.IsSorted = false;
}
} }
base.IndexList.Clear();
base.IndexList.AddRange (sortedArray);
// base.CheckSortArray (sortedArray,"TableStrategy - CheckSortArray");
} catch (Exception) {
throw;
} }
}
if (base.IndexList == null){
throw new NotSupportedException("Sortieren für die Liste nicht unterstützt."); protected override void Group() {
if (base.ReportSettings.GroupColumnsCollection.Count == 0) {
return;
} }
this.BuildGroup();
base.Group();
} }
public override void Fill (IItemRenderer item) { public override void Fill (IItemRenderer item) {
try { try {
base.Fill(item); base.Fill(item);
BaseDataItem baseDataItem = item as BaseDataItem; if (this.row != null) {
if (baseDataItem != null) { BaseDataItem baseDataItem = item as BaseDataItem;
baseDataItem.DbValue = row[baseDataItem.ColumnName].ToString(); if (baseDataItem != null) {
baseDataItem.DbValue = row[baseDataItem.ColumnName].ToString();
}
} }
} catch (Exception ) {
} catch (System.NullReferenceException) {
} }
} }
@ -340,7 +218,7 @@ namespace SharpReportCore {
public override int Count { public override int Count {
get { get {
return this.table.Rows.Count; return this.IndexList.Count;
} }
} }
@ -356,31 +234,41 @@ namespace SharpReportCore {
GroupSeperator sep = bc as GroupSeperator; GroupSeperator sep = bc as GroupSeperator;
if (sep != null) { if (sep != null) {
base.NotifyGroupChange(this,sep); base.NotifyGroupChanging(this,sep);
} }
row = this.view[((BaseComparer)base.IndexList[value]).ListIndex]; row = this.view[((BaseComparer)base.IndexList[value]).ListIndex];
} }
} }
} }
#endregion
#region IDisposable
public override void Dispose(){
this.Dispose(true);
public override bool IsSorted { GC.SuppressFinalize(this);
get {
return (this.view.Sort.Length > 0);
}
} }
#endregion ~TableStrategy(){
Dispose(false);
}
#region IDisposable protected override void Dispose(bool disposing){
public void Dispose(){ try {
if (this.view != null) { if (disposing) {
this.view.Dispose(); if (this.view != null) {
this.view.Dispose();
this.view = null;
}
}
} finally {
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
base.Dispose(disposing);
} }
} }
#endregion #endregion
} }

4
src/AddIns/Misc/SharpReport/SharpReportCore/DataManager/SqlQueryChecker.cs

@ -16,14 +16,14 @@ namespace SharpReportCore
/// <summary> /// <summary>
/// This Class checks for invalid SqlStatements /// This Class checks for invalid SqlStatements
/// </summary> /// </summary>
internal class SqlQueryCkecker{ internal class SqlQueryChecker{
internal string UPDATE = "UPDATE"; internal string UPDATE = "UPDATE";
internal string DELETE = "DELETE"; internal string DELETE = "DELETE";
internal string INSERT = "INSERT"; internal string INSERT = "INSERT";
internal string noValidMessage = "is no valid Member of SqlString"; internal string noValidMessage = "is no valid Member of SqlString";
public SqlQueryCkecker(){ public SqlQueryChecker(){
} }
public void Check (string queryString) { public void Check (string queryString) {

4
src/AddIns/Misc/SharpReport/SharpReportCore/Exceptions/MissingDataSourceException.cs

@ -17,9 +17,7 @@ using System.Runtime.Serialization;
/// created by - Forstmeier Peter /// created by - Forstmeier Peter
/// created on - 05.07.2005 22:32:47 /// created on - 05.07.2005 22:32:47
/// </remarks> /// </remarks>
///<remarks>
/// When porting to NET 2.0 use <see cref="Microsoft.Reporting.MissingdatasourceException"></see>
/// </remarks>
namespace SharpReportCore { namespace SharpReportCore {
[Serializable()] [Serializable()]

15
src/AddIns/Misc/SharpReport/SharpReportCore/Globals/FontSingleton.cs

@ -31,7 +31,6 @@ namespace SharpReportCore {
private FontSingleton() { private FontSingleton() {
MessageBox.Show ("Should be commented out","FontSingleton");
hash = new Hashtable(); hash = new Hashtable();
} }
public Hashtable Hash { public Hashtable Hash {
@ -54,14 +53,6 @@ namespace SharpReportCore {
public Font GetFont(string family, float size, FontStyle style){ public Font GetFont(string family, float size, FontStyle style){
try { try {
string s=family+size.ToString()+((int)style).ToString(); string s=family+size.ToString()+((int)style).ToString();
MessageBox.Show (s);
//Remove when tested
if(hash.Contains(s)){
MessageBox.Show ("font from hashtable","GetFont");
} else {
MessageBox.Show ("font created","getFont");
}
if(hash.Contains(s)){ if(hash.Contains(s)){
return (Font)hash[s]; return (Font)hash[s];
@ -75,10 +66,6 @@ MessageBox.Show ("font from hashtable","GetFont");
} }
public override string ToString() {
return base.ToString() + " FontSingleton / ";
}
/// <summary> /// <summary>
/// Clear the Hashtable from all Fonts /// Clear the Hashtable from all Fonts
/// </summary> /// </summary>
@ -87,7 +74,7 @@ MessageBox.Show ("font from hashtable","GetFont");
/// ///
/// </remarks> /// </remarks>
public void Dispose() { public void Dispose() {
MessageBox.Show ("dispose fonts " + hash.Count.ToString());
} }
} }
} }

6
src/AddIns/Misc/SharpReport/SharpReportCore/Globals/GlobalEnums.cs

@ -97,15 +97,15 @@ namespace SharpReportCore {
/// Convert any possible string-Value of a given enumeration /// Convert any possible string-Value of a given enumeration
/// type to its internal representation. /// type to its internal representation.
public static object StringToEnum( Type t, string value ) { public static object StringToEnum( Type type, string value ) {
foreach ( FieldInfo fi in t.GetFields() ) foreach ( FieldInfo fi in type.GetFields() )
if ( fi.Name == value ) if ( fi.Name == value )
return fi.GetValue( null ); // We use null because return fi.GetValue( null ); // We use null because
throw new Exception( string.Format(CultureInfo.CurrentCulture, throw new Exception( string.Format(CultureInfo.CurrentCulture,
"Can't convert {0} to {1}", "Can't convert {0} to {1}",
value, value,
t.ToString()) ); type.ToString()) );
} }
} }
} }

7
src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataContainer.cs

@ -26,12 +26,7 @@ namespace SharpReportCore {
/// Reads one row of data and fill the /// Reads one row of data and fill the
/// <see cref="ReportItemCollection"></see> /// <see cref="ReportItemCollection"></see>
void FetchData (ReportItemCollection collection); void FetchData (ReportItemCollection collection);
// /// <summary>
// /// set,get the SharpReportCore
// /// </summary>
// object SharpReportCore{
// get;set;
// }
int Count { int Count {
get; get;
} }

27
src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IDataViewStrategy.cs

@ -5,7 +5,7 @@ using System.Collections;
using System.ComponentModel; using System.ComponentModel;
namespace SharpReportCore{ namespace SharpReportCore{
public interface IDataViewStrategy { public interface IDataViewStrategy:IDisposable{
/// <summary> /// <summary>
/// Sort the DataSource /// Sort the DataSource
@ -33,15 +33,7 @@ namespace SharpReportCore{
get; get;
} }
/// <summary>
/// Build a Hierarchical List of grouped DataRows
/// </summary>
/// <param name="sourceList"></param>
/// <returns></returns>
IHierarchicalEnumerable IHierarchicalEnumerable{
get;
}
int Count { int Count {
get; get;
@ -78,8 +70,21 @@ namespace SharpReportCore{
bool IsGrouped { bool IsGrouped {
get; get;
} }
// event ListChangedEventHandler ListChanged;
/// <summary>
/// Returns if the current Row has Child's
/// </summary>
bool HasChilds {
get;
}
SharpIndexCollection ChildRows {
get;
}
event EventHandler <ListChangedEventArgs> ListChanged; event EventHandler <ListChangedEventArgs> ListChanged;
/// <summary> /// <summary>
/// Fired each tim the grouping will change, this means theGroupLevel changes up or down /// Fired each tim the grouping will change, this means theGroupLevel changes up or down
/// </summary> /// </summary>

15
src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IHierarchyInterfaces.cs

@ -13,19 +13,12 @@ using System.Collections;
namespace SharpReportCore { namespace SharpReportCore {
public interface IHierarchicalEnumerable :IEnumerable {
IHierarchyData GetHierarchyData (Object enumeratedItem);
}
public interface IHierarchyData{ public interface IHierarchyData{
IHierarchicalEnumerable GetChildren (); SharpIndexCollection GetChildren {
IHierarchyData GetParent(); get;
}
bool HasChildren { bool HasChildren {
get; get;
} }

6
src/AddIns/Misc/SharpReport/SharpReportCore/Interfaces/IOutputStrategy.cs

@ -20,18 +20,18 @@ namespace SharpReportCore
/// <summary> /// <summary>
/// Measure the Size of the currnet Item /// Measure the Size of the currnet Item
/// </summary> /// </summary>
SizeF MeasureItem(System.Drawing.Graphics e); SizeF MeasureItem(System.Drawing.Graphics graphics);
/// <summary> /// <summary>
/// Format the current (TextBased) /// Format the current (TextBased)
/// </summary> /// </summary>
/// <param name="e"></param> /// <param name="e"></param>
/// <returns></returns> /// <returns></returns>
void FormatItem(System.Drawing.Graphics e ); void FormatItem(System.Drawing.Graphics graphics );
/// <summary> /// <summary>
/// Print them out to .... /// Print them out to ....
/// </summary> /// </summary>
/// <param name="e"></param> /// <param name="e"></param>
void OutputItem (System.Drawing.Graphics e); void OutputItem (System.Drawing.Graphics graphics);
} }
} }

15
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs

@ -47,12 +47,23 @@ namespace SharpReportCore {
} }
public RenderDataReport(ReportModel model,DataManager dataManager):base (model){ public RenderDataReport(ReportModel model,DataManager dataManager):base (model){
// System.Console.WriteLine("RenderDataReport".ToUpper());
this.dataManager = dataManager; this.dataManager = dataManager;
System.Console.WriteLine("ReenderDataReport");
System.Console.WriteLine("connect to groupingevents");
this.dataManager.GroupChanged += new EventHandler<GroupChangedEventArgs>(OnGroupChanged);
this.dataManager.GroupChanging += new EventHandler <EventArgs> (OnGroupChanging);
} }
void OnGroupChanged (object sender,GroupChangedEventArgs e) {
System.Console.WriteLine("OnGroupChanged");
}
void OnGroupChanging (object sender, EventArgs e) {
System.Console.WriteLine("OnGroupChanging");
}
#region overrides #region overrides

2
src/AddIns/Misc/SharpReport/SharpReportCore/Printing/ReportDocument.cs

@ -80,7 +80,7 @@ namespace SharpReportCore {
} }
public void ReportDocumentPrintPage (object sender, PrintPageEventArgs e) { public void ReportDocumentPrintPage (object sender, PrintPageEventArgs e) {
// System.Console.WriteLine("\tReportDocument PrintPage"); System.Console.WriteLine("\tReportDocument PrintPage");
pageNr ++; pageNr ++;
ReportPageEventArgs pea = new ReportPageEventArgs (e,pageNr,false,new PointF (0,0)); ReportPageEventArgs pea = new ReportPageEventArgs (e,pageNr,false,new PointF (0,0));

26
src/AddIns/Misc/SharpReport/SharpReportCore/ReportModel.cs

@ -117,9 +117,6 @@ namespace SharpReportCore {
get { get {
return sectionCollection; return sectionCollection;
} }
set {
sectionCollection = value;
}
} }
#endregion #endregion
@ -136,16 +133,23 @@ namespace SharpReportCore {
} }
protected virtual void Dispose(bool disposing){ protected virtual void Dispose(bool disposing){
if (disposing) { try {
// Free other state (managed objects). if (disposing) {
if (this.reportSettings != null) { // Free other state (managed objects).
this.reportSettings.Dispose(); if (this.reportSettings != null) {
this.reportSettings = null; this.reportSettings.Dispose();
this.reportSettings = null;
}
if (this.sectionCollection != null) {
this.sectionCollection.Clear();
this.sectionCollection = null;
}
} }
} } finally {
// Free your own state (unmanaged objects). // Free your own state (unmanaged objects).
// Set large fields to null. // Set large fields to null.
}
} }
#endregion #endregion
} }

66
src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs

@ -100,18 +100,15 @@ namespace SharpReportCore{
XmlElement ctrlElem, XmlElement ctrlElem,
AbstractColumn item) { AbstractColumn item) {
try {
XmlNodeList nodeList = ctrlElem.ChildNodes; XmlNodeList nodeList = ctrlElem.ChildNodes;
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement)node; if (elem != null) {
if (elem.HasAttribute("value")) { if (elem.HasAttribute("value")) {
reader.SetValue (item,elem.Name,elem.GetAttribute("value")); reader.SetValue (item,elem.Name,elem.GetAttribute("value"));
}
} }
} }
} catch (Exception ) {
throw ;
} }
} }
@ -124,18 +121,18 @@ namespace SharpReportCore{
private void BuildReportParameter(XmlFormReader reader, private void BuildReportParameter(XmlFormReader reader,
XmlElement parElement, XmlElement parElement,
SharpReportCore.AbstractParameter item) { SharpReportCore.AbstractParameter item) {
try {
XmlNodeList nodeList = parElement.ChildNodes; XmlNodeList nodeList = parElement.ChildNodes;
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
XmlElement elem = (XmlElement)node; XmlElement elem = node as XmlElement;
if (elem != null) {
if (elem.HasAttribute("value")) { if (elem.HasAttribute("value")) {
reader.SetValue ((SqlParameter)item,elem.Name,elem.GetAttribute("value")); reader.SetValue ((SqlParameter)item,elem.Name,elem.GetAttribute("value"));
} }
} }
} catch (Exception) {
} }
} }
#endregion #endregion
#region RestoreItems #region RestoreItems
@ -152,8 +149,8 @@ namespace SharpReportCore{
XmlNodeList nodeList = xmlCol.ChildNodes; XmlNodeList nodeList = xmlCol.ChildNodes;
this.availableFields.Clear(); this.availableFields.Clear();
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
AbstractColumn abstr = new AbstractColumn(); AbstractColumn abstr = new AbstractColumn();
BuildAbstractColumn (xmlReader,elem,abstr); BuildAbstractColumn (xmlReader,elem,abstr);
this.availableFields.Add(abstr); this.availableFields.Add(abstr);
@ -167,8 +164,8 @@ namespace SharpReportCore{
XmlNodeList nodeList = xmlCol.ChildNodes; XmlNodeList nodeList = xmlCol.ChildNodes;
this.sortingCollection.Clear(); this.sortingCollection.Clear();
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
SortColumn sc = new SortColumn(); SortColumn sc = new SortColumn();
BuildAbstractColumn (xmlReader,elem,sc); BuildAbstractColumn (xmlReader,elem,sc);
sortingCollection.Add(sc); sortingCollection.Add(sc);
@ -181,8 +178,8 @@ namespace SharpReportCore{
XmlNodeList nodeList = xmlCol.ChildNodes; XmlNodeList nodeList = xmlCol.ChildNodes;
this.groupingsCollection.Clear(); this.groupingsCollection.Clear();
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
GroupColumn gc = new GroupColumn(); GroupColumn gc = new GroupColumn();
BuildAbstractColumn (xmlReader,elem,gc); BuildAbstractColumn (xmlReader,elem,gc);
groupingsCollection.Add(gc); groupingsCollection.Add(gc);
@ -195,8 +192,8 @@ namespace SharpReportCore{
XmlNodeList nodeList = xmlCol.ChildNodes; XmlNodeList nodeList = xmlCol.ChildNodes;
this.reportParametersCollection.Clear(); this.reportParametersCollection.Clear();
foreach( XmlNode node in nodeList) { foreach( XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
SqlParameter parameter = new SqlParameter(); SqlParameter parameter = new SqlParameter();
BuildReportParameter (xmlReader, BuildReportParameter (xmlReader,
elem, elem,
@ -205,10 +202,7 @@ namespace SharpReportCore{
} }
} }
break; break;
} }
default:
throw new SharpReportException ("Invalid Collection found in ReportSettings:CheckForCollection");
} }
} }
@ -218,8 +212,8 @@ namespace SharpReportCore{
XmlFormReader xmlFormReader = new XmlFormReader(); XmlFormReader xmlFormReader = new XmlFormReader();
base.InitDone = false; base.InitDone = false;
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
CheckForCollection (xmlFormReader,elem); CheckForCollection (xmlFormReader,elem);
if (elem.Name == "PageSettings") { if (elem.Name == "PageSettings") {
@ -228,9 +222,7 @@ namespace SharpReportCore{
CultureInfo.InvariantCulture); CultureInfo.InvariantCulture);
} }
else if (elem.Name == "DefaultFont") {
Font f = XmlFormReader.MakeFont (elem.GetAttribute("value"));
}
else if (elem.HasAttribute("value")) { else if (elem.HasAttribute("value")) {
xmlFormReader.SetValue (this,elem.Name,elem.GetAttribute("value")); xmlFormReader.SetValue (this,elem.Name,elem.GetAttribute("value"));
} }
@ -526,9 +518,9 @@ namespace SharpReportCore{
get { get {
return sortingCollection; return sortingCollection;
} }
set { // set {
sortingCollection = value; // sortingCollection = value;
} // }
} }
[Browsable(false)] [Browsable(false)]
[XmlIgnoreAttribute] [XmlIgnoreAttribute]
@ -539,6 +531,7 @@ namespace SharpReportCore{
} }
return groupingsCollection; return groupingsCollection;
} }
/*
set { set {
if (this.groupingsCollection == null) { if (this.groupingsCollection == null) {
groupingsCollection = new ColumnCollection(); groupingsCollection = new ColumnCollection();
@ -548,6 +541,7 @@ namespace SharpReportCore{
this.NotifyPropertyChanged(); this.NotifyPropertyChanged();
} }
} }
*/
} }
[Browsable(false)] [Browsable(false)]

9
src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportCore.csproj

@ -32,12 +32,12 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <Reference Include="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<Reference Include="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <Reference Include="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<Reference Include="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <Reference Include="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Data" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="BaseItems\BaseTextItem.cs" /> <Compile Include="BaseItems\BaseTextItem.cs" />
@ -50,13 +50,10 @@
<Compile Include="BaseItems\Functions\BaseToday.cs" /> <Compile Include="BaseItems\Functions\BaseToday.cs" />
<Compile Include="BaseItems\Functions\BasePageNumber.cs" /> <Compile Include="BaseItems\Functions\BasePageNumber.cs" />
<Compile Include="DataManager\Comparer\BaseComparer.cs" /> <Compile Include="DataManager\Comparer\BaseComparer.cs" />
<Compile Include="DataManager\Comparer\GroupComparer.cs" />
<Compile Include="DataManager\Comparer\GroupSeperator.cs" /> <Compile Include="DataManager\Comparer\GroupSeperator.cs" />
<Compile Include="DataManager\Comparer\SortComparer.cs" /> <Compile Include="DataManager\Comparer\SortComparer.cs" />
<Compile Include="DataManager\ListHandling\ExtendedPropertyDescriptor.cs" /> <Compile Include="DataManager\ListHandling\ExtendedPropertyDescriptor.cs" />
<Compile Include="DataManager\ListHandling\ExtendedTypeDescriptor.cs" /> <Compile Include="DataManager\ListHandling\ExtendedTypeDescriptor.cs" />
<Compile Include="DataManager\ListHandling\IExtendedList.cs" />
<Compile Include="DataManager\ListHandling\IHierarchicalArray.cs" />
<Compile Include="DataManager\ListHandling\PropertyTypeHash.cs" /> <Compile Include="DataManager\ListHandling\PropertyTypeHash.cs" />
<Compile Include="DataManager\ListHandling\SharpArrayList.cs" /> <Compile Include="DataManager\ListHandling\SharpArrayList.cs" />
<Compile Include="DataManager\ListStrategy\BaseListStrategy.cs" /> <Compile Include="DataManager\ListStrategy\BaseListStrategy.cs" />
@ -85,7 +82,6 @@
<Compile Include="Interfaces\IBaseRenderer.cs" /> <Compile Include="Interfaces\IBaseRenderer.cs" />
<Compile Include="Interfaces\IDataContainer.cs" /> <Compile Include="Interfaces\IDataContainer.cs" />
<Compile Include="Interfaces\IDataViewStrategy.cs" /> <Compile Include="Interfaces\IDataViewStrategy.cs" />
<Compile Include="Interfaces\IHierarchyInterfaces.cs" />
<Compile Include="Interfaces\IItemRenderer.cs" /> <Compile Include="Interfaces\IItemRenderer.cs" />
<Compile Include="Interfaces\IOutputStrategy.cs" /> <Compile Include="Interfaces\IOutputStrategy.cs" />
<Compile Include="Interfaces\IRender.cs" /> <Compile Include="Interfaces\IRender.cs" />
@ -129,6 +125,7 @@
<Compile Include="Collections\Collections.cs" /> <Compile Include="Collections\Collections.cs" />
<Compile Include="DataManager\SqlQueryChecker.cs" /> <Compile Include="DataManager\SqlQueryChecker.cs" />
<Compile Include="Exceptions\MissingModelException.cs" /> <Compile Include="Exceptions\MissingModelException.cs" />
<Compile Include="Interfaces\IHierarchyInterfaces.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="BaseItems" /> <Folder Include="BaseItems" />

61
src/AddIns/Misc/SharpReport/SharpReportCore/SharpReportEngine.cs

@ -41,6 +41,7 @@ namespace SharpReportCore {
private PreviewControl previewControl; private PreviewControl previewControl;
private ConnectionObject connectionObject; private ConnectionObject connectionObject;
private DataManager dataManager;
public event EventHandler <SharpReportEventArgs> NoData; public event EventHandler <SharpReportEventArgs> NoData;
public event EventHandler <SharpReportParametersEventArgs> ParametersRequest; public event EventHandler <SharpReportParametersEventArgs> ParametersRequest;
@ -134,22 +135,18 @@ namespace SharpReportCore {
} }
} }
private DataManager SetupDataContainer (ReportSettings settings) { private void InitDataContainer (ReportSettings settings) {
if (settings.ReportType == GlobalEnums.enmReportType.DataReport) { if (settings.ReportType == GlobalEnums.enmReportType.DataReport) {
if (settings.CommandText != null) { if (settings.CommandText != null) {
try { try {
GrapSqlParameters (settings); GrapSqlParameters (settings);
if (this.connectionObject != null) { if (this.connectionObject != null) {
DataManager container = new DataManager(this.connectionObject, this.dataManager = new DataManager(this.connectionObject,
settings); settings);
if (container.DataBind() == true) { this.dataManager.DataBind();
return container;
} else {
return null;
}
}else { }else {
throw new NullReferenceException("SetupContainer:connectionObject is missing"); throw new NullReferenceException("SetupContainer:connectionObject is missing");
} }
@ -163,7 +160,6 @@ namespace SharpReportCore {
} }
} }
} }
return null;
} }
@ -187,6 +183,7 @@ namespace SharpReportCore {
protected SharpReportCore.AbstractRenderer SetupStandartRenderer (ReportModel model) { protected SharpReportCore.AbstractRenderer SetupStandartRenderer (ReportModel model) {
AbstractRenderer abstr = null; AbstractRenderer abstr = null;
switch (model.ReportSettings.ReportType) { switch (model.ReportSettings.ReportType) {
//FormSheets reports //FormSheets reports
@ -195,9 +192,10 @@ namespace SharpReportCore {
break; break;
//Databased reports //Databased reports
case GlobalEnums.enmReportType.DataReport : case GlobalEnums.enmReportType.DataReport :
DataManager dataManager = SetupDataContainer (model.ReportSettings); // DataManager dataManager = SetupDataContainer (model.ReportSettings);
if (dataManager != null) { InitDataContainer (model.ReportSettings);
if (dataManager.DataSource != null) { if (this.dataManager != null) {
if (this.dataManager.DataSource != null) {
abstr = new RendererFactory().Create (model,dataManager); abstr = new RendererFactory().Create (model,dataManager);
} }
@ -239,11 +237,12 @@ namespace SharpReportCore {
} }
AbstractRenderer abstr = null; AbstractRenderer abstr = null;
DataManager dataManager = new DataManager (dataTable,model.ReportSettings);
if (dataManager != null) { this.dataManager = new DataManager (dataTable,model.ReportSettings);
dataManager.DataBind();
if (dataManager.DataSource != null) { if (this.dataManager != null) {
this.dataManager.DataBind();
if (this.dataManager.DataSource != null) {
abstr = new RendererFactory().Create (model,dataManager); abstr = new RendererFactory().Create (model,dataManager);
} }
@ -475,7 +474,7 @@ namespace SharpReportCore {
try { try {
model = ModelFromFile (fileName); model = ModelFromFile (fileName);
if (!CheckForPushModel(model)) { if (!CheckForPushModel(model)) {
throw new SharpReportException ("PrintPushdataReport: No valid ReportModel"); throw new MissingModelException();
} }
renderer = this.SetupPushDataRenderer (model,dataTable); renderer = this.SetupPushDataRenderer (model,dataTable);
@ -555,19 +554,25 @@ namespace SharpReportCore {
} }
protected virtual void Dispose(bool disposing){ protected virtual void Dispose(bool disposing){
if (disposing) { try {
// Free other state (managed objects). if (disposing) {
if (this.connectionObject != null) { // Free other state (managed objects).
this.connectionObject.Dispose(); if (this.connectionObject != null) {
} this.connectionObject.Dispose();
if (this.previewControl != null) { }
this.previewControl.Dispose(); if (this.dataManager != null) {
this.dataManager.Dispose();
this.dataManager = null;
}
if (this.previewControl != null) {
this.previewControl.Dispose();
}
} }
} finally {
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
} }
// Release unmanaged resources.
// Set large fields to null.
// Call Dispose on your base class.
} }
#endregion #endregion
} }

30
src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs

@ -44,12 +44,8 @@ namespace SharpReportCore {
/// ///
public static bool IsSharpReport (XmlElement elem) { public static bool IsSharpReport (XmlElement elem) {
bool isOk = false; bool isOk = false;
try { if (elem.Name.Equals (SharpReportCore.GlobalValues.SharpReportString)) {
if (elem.Name.Equals (SharpReportCore.GlobalValues.SharpReportString)) { isOk = true;
isOk = true;
}
} catch (Exception) {
throw ;
} }
return isOk; return isOk;
} }
@ -75,13 +71,13 @@ namespace SharpReportCore {
// Valid Document // Valid Document
return xmlDoc; return xmlDoc;
} else { } else {
throw new SharpReportException ("XmlHelper.OpenSharpReport - > No SharpReport"); throw new IllegalFileFormatException();
} }
} else { } else {
throw new SharpReportException ("XmlHelper.OpenSharpReport - > No valid DocumentElement"); throw new IllegalFileFormatException();
} }
} }
catch (System.Xml.XmlException) { catch (System.Xml.XmlException ) {
IllegalFileFormatException wf = new IllegalFileFormatException("XmlHelper.OpenSharpReport - > Wrong File Format"); IllegalFileFormatException wf = new IllegalFileFormatException("XmlHelper.OpenSharpReport - > Wrong File Format");
throw wf; throw wf;
} }
@ -108,19 +104,13 @@ namespace SharpReportCore {
XmlNodeList nodeList = element.ChildNodes; XmlNodeList nodeList = element.ChildNodes;
foreach (XmlNode node in nodeList) { foreach (XmlNode node in nodeList) {
if (node is XmlElement) { XmlElement elem = node as XmlElement;
XmlElement elem = (XmlElement) node; if (elem != null) {
if (elem.HasAttribute("value")) { if (elem.HasAttribute("value")) {
try { reader.SetValue (section,elem.Name,elem.GetAttribute("value"));
reader.SetValue (section,elem.Name,elem.GetAttribute("value"));
} catch (Exception e) {
MessageBox.Show (elem.Name + " / " + elem.GetAttribute("value"));
MessageBox.Show (e.Message);
}
} }
} else { }else {
throw new System.Xml.XmlException ("Report : SetValues Wrong Node in Report"); throw new System.Xml.XmlException ();
} }
} }
} }

Loading…
Cancel
Save