Repository navigation
Expand file tree
/
Copy pathColumnCollection.cs
More file actions
120 lines (112 loc) · 3.23 KB
/
Copy pathColumnCollection.cs
File metadata and controls
120 lines (112 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using FastReport.Utils;
namespace FastReport.Data
{
/// <summary>
/// Represents the collection of <see cref="Column"/> objects.
/// </summary>
public class ColumnCollection : FRCollectionBase
{
/// <summary>
/// Gets or sets a column.
/// </summary>
/// <param name="index">The index of a column in this collection.</param>
/// <returns>The column with specified index.</returns>
public Column this[int index]
{
get { return List[index] as Column; }
set { List[index] = value; }
}
/// <summary>
/// Finds a column by its name.
/// </summary>
/// <param name="name">The name of a column.</param>
/// <returns>The <see cref="Column"/> object if found; otherwise <b>null</b>.</returns>
public Column FindByName(string name)
{
foreach (Column c in this)
{
if (String.Compare(c.Name, name, true) == 0)
return c;
}
return null;
}
/// <summary>
/// Finds a column by its alias.
/// </summary>
/// <param name="alias">The alias of a column.</param>
/// <returns>The <see cref="Column"/> object if found; otherwise <b>null</b>.</returns>
public Column FindByAlias(string alias)
{
foreach (Column c in this)
{
if (String.Compare(c.Alias, alias, true) == 0)
return c;
}
return null;
}
/// <summary>
/// Returns an unique column name based on given name.
/// </summary>
/// <param name="name">The base name.</param>
/// <returns>The unique name.</returns>
public string CreateUniqueName(string name)
{
string baseName = name;
int i = 1;
while (FindByName(name) != null)
{
name = baseName + i.ToString();
i++;
}
return name;
}
/// <summary>
/// Returns an unique column alias based on given alias.
/// </summary>
/// <param name="alias">The base alias.</param>
/// <returns>The unique alias.</returns>
public string CreateUniqueAlias(string alias)
{
string baseAlias = alias;
int i = 1;
while (FindByAlias(alias) != null)
{
alias = baseAlias + i.ToString();
i++;
}
return alias;
}
/// <summary>
/// Sorts the collection of columns.
/// </summary>
public void Sort()
{
InnerList.Sort(new ColumnComparer());
}
/// <summary>
/// Initializes a new instance of the <see cref="ColumnCollection"/> class with default settings.
/// </summary>
/// <param name="owner">The owner of this collection.</param>
public ColumnCollection(Base owner) : base(owner)
{
}
}
/// <summary>
/// Represents the comparer class that used for sorting the collection of columns.
/// </summary>
public class ColumnComparer : IComparer
{
/// <inheritdoc/>
public int Compare(object x, object y)
{
object xValue = x.GetType().GetProperty("Name").GetValue(x, null);
object yValue = y.GetType().GetProperty("Name").GetValue(y, null);
IComparable comp = xValue as IComparable;
return comp.CompareTo(yValue);
}
}
}