-
Notifications
You must be signed in to change notification settings - Fork 9
/
GS.Common.Report.pas
87 lines (69 loc) · 2.12 KB
/
GS.Common.Report.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
///
/// Reporting base abstrat api ressource.
///
unit GS.Common.Report;
interface
uses sysutils, classes,
Generics.Collections,
Datasnap.DBClient,
Data.DB;
Type
IGSReportData = interface
procedure addVar(name : String; value : string); overload;
procedure addVar(name : String; value : TDateTime); overload;
procedure addVar(name : String; value : TBytes); overload;
procedure addVar(name : String; value : TClientDataset); overload;
procedure DataBufferAdd(aDataBufferName : String);
procedure DataBufferNewLine;
procedure DataBufferAddFieldData(fieldName :string; Value : String);
end;
IGSReport = interface
procedure Render(aTemplateFile : string; aTargetFile : string);
function Data : IGSReportData;
end;
IGSReportExporter = interface
procedure SaveToFile(afileName : String);
end;
IGSReportFactory = interface
function getInstance : IGSReport;
end;
TGSReportFactory = class
private
Class var FReportClasses : TDictionary<string,IGSReportFactory>;
Class procedure internalcheck;
public
class function GetInstansce(const _type : String = 'txt') : IGSReport;
class procedure ReportRegister(_type : String; _Factory : IGSReportFactory);
class procedure Terminate;
end;
implementation
{ TGSReportFactory }
class function TGSReportFactory.GetInstansce(const _type: String): IGSReport;
var lvo : IGSReportFactory;
begin
internalcheck;
if Not FReportClasses.TryGetValue(_type,lvo) then
raise Exception.Create(className+'.GetInstance : report type "'+_type+'" not registered.');
result := lvo.getInstance;
end;
class procedure TGSReportFactory.internalcheck;
begin
if not Assigned(FReportClasses) then
FReportClasses := TDictionary<string,IGSReportFactory>.create;
end;
class procedure TGSReportFactory.ReportRegister(_type : String; _Factory : IGSReportFactory);
var lv : IGSReportFactory;
begin
internalcheck;
if not FReportClasses.TryGetValue(_type,lv) then
FReportClasses.Add(_type,_Factory);
end;
class procedure TGSReportFactory.Terminate;
begin
if Assigned(FReportClasses) then
FreeAndNil(FReportClasses);
end;
Initialization
Finalization
TGSReportFactory.Terminate;
end.