-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuModel.Report.DataSet.pas
129 lines (107 loc) · 3.3 KB
/
uModel.Report.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
unit uModel.Report.DataSet;
interface
uses
uModel.Report.Interfaces,
System.Generics.Collections,
System.Variants,
System.Classes;
type
TModelReportDataSet = class(TInterfacedObject, iModelReportDataSet)
private
FDataList: TInterfaceList;
FParent: iModelReport;
FColumnLabels: TArray<string>;
public
constructor Create(AParent: iModelReport; AColLabels: TArray<string>);
destructor Destroy; override;
class function New(AParent: iModelReport; AColLabels: TArray<string>): iModelReportDataSet;
function AddReportData(AColLabels: TArray<Variant>): iModelReportDataSet;
function Data(Index: Integer): iModelReportData;
function Generate: string;
function RecordCount: Integer;
function ClearData: iModelReportDataSet;
function &End: iModelReport;
function ColumnLabels: TArray<string>;
end;
implementation
uses
uModel.Report.Data;
constructor TModelReportDataSet.Create(AParent: iModelReport; AColLabels: TArray<string>);
begin
FParent := AParent;
FDataList := TInterfaceList.Create;
FColumnLabels := AColLabels;
end;
destructor TModelReportDataSet.Destroy;
begin
FDataList.Free;
inherited;
end;
class function TModelReportDataSet.New(AParent: iModelReport; AColLabels: TArray<string>): iModelReportDataSet;
begin
Result := Self.Create(AParent, AColLabels);
end;
function TModelReportDataSet.AddReportData(AColLabels: TArray<Variant>): iModelReportDataSet;
var
I: Integer;
ReportData: iModelReportData;
begin
Result := Self;
if Length(FColumnLabels) = 0 then
begin
SetLength(FColumnLabels, Length(AColLabels));
for I := 0 to High(AColLabels) do
FColumnLabels[I] := VarToStr(AColLabels[I]);
end;
for I := 0 to High(AColLabels) do
begin
ReportData := TModelReportData.Create(self);
ReportData.Value(AColLabels[I]);
FDataList.Add(ReportData);
end;
end;
function TModelReportDataSet.Data(Index: Integer): iModelReportData;
begin
Result := FDataList.Items[Index] as iModelReportData;
end;
function TModelReportDataSet.Generate: string;
var
I, J: Integer;
RowData: iModelReportData;
begin
Result := '<table class="table table-striped table-bordered" border="1" cellspacing="0" cellpadding="5">';
Result := Result + '<tr>';
for I := 0 to High(FColumnLabels) do
Result := Result + '<th>' + FColumnLabels[I] + '</th>';
Result := Result + '</tr>';
for I := 0 to (FDataList.Count div Length(FColumnLabels)) - 1 do
begin
Result := Result + '<tr>';
for J := 0 to High(FColumnLabels) do
if (I * Length(FColumnLabels) + J) < FDataList.Count then
begin
RowData := FDataList.Items[I * Length(FColumnLabels) + J] as iModelReportData;
Result := Result + '<td>' + VarToStr(RowData.Value) + '</td>';
end;
Result := Result + '</tr>';
end;
Result := Result + '</table>';
end;
function TModelReportDataSet.RecordCount: Integer;
begin
Result := FDataList.Count;
end;
function TModelReportDataSet.ClearData: iModelReportDataSet;
begin
FDataList.Clear;
Result := Self;
end;
function TModelReportDataSet.ColumnLabels: TArray<string>;
begin
Result := FColumnLabels;
end;
function TModelReportDataSet.&End: iModelReport;
begin
Result := FParent;
end;
end.