1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using System.Collections.ObjectModel;
7
using System.Globalization;
10
using ICSharpCode.Reports.Core.Exporter;
11
using ICSharpCode.Reports.Core.Interfaces;
13
namespace ICSharpCode.Reports.Core{
15
public class CollectionChangedEventArgs<T> : EventArgs
25
public CollectionChangedEventArgs(T item)
31
/// Comparer to Sort the <see cref="ReportItemCollection"></see>
32
/// by System.Drawing.Location.Y, so we have <see cref="BaseReportItem"></see> in the Order we use them
35
internal class LocationSorter : IComparer<BaseReportItem> {
36
public int Compare(BaseReportItem lhs, BaseReportItem rhs){
47
if (lhs.Location.Y == rhs.Location.Y){
48
return lhs.Location.X - rhs.Location.X;
50
return lhs.Location.Y - rhs.Location.Y;
56
/// A collection that holds <see cref='IItemRenderer'/> objects.
58
public class ReportItemCollection : Collection<BaseReportItem>
61
// Trick to get the inner list as List<T> (InnerList always has that type because we only use
62
// the parameterless constructor on Collection<T>)
64
private List<BaseReportItem> InnerList {
65
get { return (List<BaseReportItem>)base.Items; }
68
private void Sort(IComparer<BaseReportItem> comparer)
70
InnerList.Sort(comparer);
73
public void ForEach (Action <BaseReportItem> action)
75
this.InnerList.ForEach (action);
79
public void AddRange(IEnumerable<BaseReportItem> items)
81
foreach (BaseReportItem item in items) Add(item);
85
public void SortByLocation () {
87
this.Sort(new LocationSorter());
92
public bool Exist (string itemName)
94
if (String.IsNullOrEmpty(itemName)) {
95
throw new ArgumentNullException("itemName");
98
if (InnerFind(itemName) == null) {
107
private BaseReportItem InnerFind (string name)
109
return this.FirstOrDefault(x => 0 == String.Compare(x.Name, name,true,CultureInfo.InvariantCulture));
113
public BaseReportItem Find (string itemName)
115
if (String.IsNullOrEmpty(itemName)) {
116
throw new ArgumentNullException("itemName");
118
return this.InnerFind (itemName);
122
public BaseReportItem FindHighestElement()
124
if (this.InnerList.Count == 0) {
127
BaseReportItem heighest = this.InnerList[0];
128
foreach (BaseReportItem item in this.InnerList)
130
if (item.Size.Height > heighest.Size.Height) {
138
protected override void InsertItem(int index, BaseReportItem item)
140
base.InsertItem(index, item);
144
protected override void RemoveItem(int index)
146
base.RemoveItem(index);
149
#region Grouphandling
151
public Collection<GroupHeader> FindGroupHeader()
153
return new Collection<GroupHeader>(this.Items.OfType<GroupHeader>().ToList());
157
public Collection<GroupFooter> FindGroupFooter()
159
return new Collection<GroupFooter>(this.Items.OfType<GroupFooter>().ToList());
163
private Collection<BaseDataItem> CreateGroupedList ()
165
Collection<BaseDataItem> inheritedReportItems = null;
166
foreach (BaseReportItem element in this) {
167
ISimpleContainer container = element as ISimpleContainer;
168
if (container == null) {
169
inheritedReportItems = new Collection<BaseDataItem>(this.OfType<BaseDataItem>().ToList());
172
inheritedReportItems = new Collection<BaseDataItem>(container.Items.OfType<BaseDataItem>().ToList());
176
return inheritedReportItems;
180
public ReportItemCollection ExtractGroupedColumns ()
182
Collection<BaseDataItem> inheritedReportItems = CreateGroupedList();
183
ReportItemCollection r = new ReportItemCollection();
184
r.AddRange(inheritedReportItems);
192
/// This class holds all the available Sections of an Report
195
public sealed class ReportSectionCollection: Collection<BaseSection>
202
public class AvailableFieldsCollection: Collection<AbstractColumn>{
204
public AvailableFieldsCollection(){
207
public AbstractColumn Find (string columnName)
209
if (String.IsNullOrEmpty(columnName)) {
210
throw new ArgumentNullException("columnName");
213
return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
221
public class SortColumnCollection: ColumnCollection
223
public SortColumnCollection()
227
public new AbstractColumn Find (string columnName)
229
if (String.IsNullOrEmpty(columnName)) {
230
throw new ArgumentNullException("columnName");
233
return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
237
public void AddRange (IEnumerable<SortColumn> items)
239
foreach (SortColumn item in items){
246
/// The Culture is used for direct String Comparison
249
public new static CultureInfo Culture
251
get { return CultureInfo.CurrentCulture;}
257
public class GroupColumnCollection: SortColumnCollection
259
public GroupColumnCollection()
263
public new AbstractColumn Find (string columnName)
265
if (String.IsNullOrEmpty(columnName)) {
266
throw new ArgumentNullException("columnName");
269
return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
276
public class ColumnCollection: Collection<AbstractColumn>{
278
public ColumnCollection()
282
public AbstractColumn Find (string columnName)
284
if (String.IsNullOrEmpty(columnName)) {
285
throw new ArgumentNullException("columnName");
288
return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
292
public void AddRange (IEnumerable<AbstractColumn> items)
294
foreach (AbstractColumn item in items){
301
/// The Culture is used for direct String Comparison
304
public static CultureInfo Culture
306
get { return CultureInfo.CurrentCulture;}
311
public class SqlParameterCollection : Collection<SqlParameter>
313
public SqlParameterCollection()
317
public SqlParameter Find (string parameterName)
319
if (String.IsNullOrEmpty(parameterName)) {
320
throw new ArgumentNullException("parameterName");
322
return this.FirstOrDefault(x => 0 == String.Compare(x.ParameterName,parameterName,true,CultureInfo.InvariantCulture));
326
public void AddRange (IEnumerable<SqlParameter> items)
328
foreach (SqlParameter item in items){
333
public static CultureInfo Culture
335
get { return System.Globalization.CultureInfo.CurrentCulture; }
340
public class ParameterCollection: Collection<BasicParameter>{
342
public ParameterCollection()
347
public BasicParameter Find (string parameterName)
349
if (String.IsNullOrEmpty(parameterName)) {
350
throw new ArgumentNullException("parameterName");
352
return this.FirstOrDefault(x => 0 == String.Compare(x.ParameterName,parameterName,true,CultureInfo.InvariantCulture));
356
public System.Collections.Hashtable CreateHash ()
358
System.Collections.Hashtable ht = new System.Collections.Hashtable();
359
foreach(BasicParameter bt in this){
360
ht.Add(bt.ParameterName,bt.ParameterValue);
365
public static CultureInfo Culture
367
get { return System.Globalization.CultureInfo.CurrentCulture; }
371
public void AddRange (IEnumerable<BasicParameter> items)
373
foreach (BasicParameter item in items){
379
#region ExporterCollection
381
public class ExporterCollection : Collection<BaseExportColumn>
384
public void AddRange (IEnumerable <BaseExportColumn> items){
385
foreach (var item in items) {
392
public class PagesCollection :Collection<ExporterPage>
400
public class CurrentItemsCollection:Collection<CurrentItem>
402
public CurrentItem Find (string columnName)
404
if (String.IsNullOrEmpty(columnName)) {
405
throw new ArgumentNullException("columnName");
408
return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));