forked from academiadocodigo/TBGWebCharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generic.DataSet.pas
172 lines (148 loc) · 4.17 KB
/
Generic.DataSet.pas
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
unit Generic.DataSet;
interface
uses
Interfaces,
Data.DB,
Generics.Collections;
type
TModelGenericDataset<T : IInterface> = class(TInterfacedObject, iModelGenericDataSet<T>)
private
[weak]
FParent : T;
FDataSet : TDataSet;
FValueName : String;
FLabelName : String;
FRGBName : String;
FCallbackLink : TDictionary<string, string>;
public
constructor Create(Parent : T);
destructor Destroy; override;
class function New(Parent : T) : iModelGenericDataset<T>;
function DataSet (Value : TDataSet) : iModelGenericDataset<T>; overload;
function ValueName(Value : String) : iModelGenericDataSet<T>; overload;
function LabelName(Value : String) : iModelGenericDataSet<T>; overload;
function RGBName(Value : String) : iModelGenericDataSet<T>; overload;
function &End : T;
function DataSet : TDataSet; overload;
function ValueName : String; overload;
function LabelName : String; overload;
function RGBName : String; overload;
function CallbackLink(Field : String; MethodName : String) : iModelGenericDataSet<T>; overload;
function CallbackLink : TDictionary<String, String>; overload;
function DataSetJstringify : string;
end;
implementation
uses
Injection,
System.SysUtils,
Utilities.Str;
{ TModelGenericDataset<T> }
function TModelGenericDataset<T>.CallbackLink(Field,
MethodName: String): iModelGenericDataSet<T>;
begin
Result := Self;
FCallbackLink.Add(Field, MethodName);
end;
function TModelGenericDataset<T>.CallbackLink: TDictionary<String, String>;
begin
Result := FCallbackLink;
end;
constructor TModelGenericDataset<T>.Create(Parent: T);
begin
{$IF RTLVERSION > 27 }
TInjection.Weak(@FParent, Parent);
{$ELSE}
FParent := Parent;
{$IFEND}
FCallbackLink := TDictionary<string, string>.Create;
FLabelName := 'Label';
end;
function TModelGenericDataset<T>.DataSet: TDataSet;
begin
Result := FDataSet;
end;
function TModelGenericDataset<T>.DataSetJstringify: string;
var
I: Integer;
J: Integer;
Aux : string;
Aux_ : string;
_Field : String;
_Value : String;
begin
Result := '[';
FDataSet.First;
for I := 0 to Pred(FDataSet.RecordCount) do
begin
Result := Result + '{';
Aux := ', ';
Aux_ := ', ';
if I = Pred(FDataSet.RecordCount) then
Aux_ := '';
for J := 0 to Pred(FDataSet.Fields.Count) do
begin
if J = Pred(FDataSet.Fields.Count) then
Aux := '';
if FDataSet.Fields[J].Visible then
begin
if FDataSet.Fields[J].DisplayName <> '' then
_Field := FDataSet.Fields[J].DisplayName
else
_Field := FDataSet.Fields[J].FieldName;
_Value := TUtilitiesStr.FloatCurrFieldToStrValue(FDataSet.Fields[J]);
Result := Result + QuotedStr(_Field) + ':"' + _Value + '"' + Aux;
end;
end;
Result := Result + '}' + aux_ ;
FDataSet.Next;
end;
Result := Result + ']';
end;
function TModelGenericDataset<T>.DataSet(Value: TDataSet): iModelGenericDataset<T>;
begin
Result := Self;
FDataSet := Value;
end;
destructor TModelGenericDataset<T>.Destroy;
begin
FreeAndNil(FCallbackLink);
inherited;
end;
function TModelGenericDataset<T>.&End: T;
begin
Result := FParent;
end;
function TModelGenericDataset<T>.LabelName: String;
begin
Result := FLabelName;
end;
function TModelGenericDataset<T>.LabelName(
Value: String): iModelGenericDataSet<T>;
begin
Result := Self;
FLabelName := Value;
end;
class function TModelGenericDataset<T>.New(Parent: T): iModelGenericDataset<T>;
begin
Result := Self.Create(Parent)
end;
function TModelGenericDataset<T>.RGBName: String;
begin
Result := FRGBName;
end;
function TModelGenericDataset<T>.RGBName(
Value: String): iModelGenericDataSet<T>;
begin
Result := Self;
FRGBName := Value;
end;
function TModelGenericDataset<T>.ValueName: String;
begin
Result := FValueName;
end;
function TModelGenericDataset<T>.ValueName(Value: String): iModelGenericDataset<T>;
begin
Result := Self;
FValueName := Value;
end;
end.