-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules.dm1.pas
More file actions
158 lines (139 loc) · 7.02 KB
/
Copy pathmodules.dm1.pas
File metadata and controls
158 lines (139 loc) · 7.02 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
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
unit modules.dm1;
interface
uses
System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.IB,
FireDAC.Phys.IBDef, FireDAC.FMXUI.Wait, Data.DB, FireDAC.Comp.Client,
FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
FireDAC.Comp.DataSet, FMXTee.Engine, FMXTee.Chart,
FireDAC.Phys.IBLiteDef, FireDAC.Comp.UI;
type
TDataModule1 = class(TDataModule)
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
FDTable1: TFDTable;
FDDeleteContents: TFDQuery;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
procedure DataModuleCreate(Sender: TObject);
private
FMS: TFormatSettings;
procedure CreateChartData(const TheTable: string; const WithLabels: Boolean; TheVals: array of Integer; TheLabels: array of string);
public
procedure ActivateDatabase;
procedure GetChartValues(const TheTable: string; const TheSeries: TChartSeries; const WithLabels: boolean);
procedure CreateChartValues;
end;
var
DataModule1: TDataModule1;
implementation
uses FMX.Dialogs;
{%CLASSGROUP 'FMX.Controls.TControl'}
{$R *.dfm}
const
///////////////////////////////////////////////////////////////////////////////////
// ///
// Change these values to match your own details - see the notes later though! ///
// ///
// cDatabase = 'c:\databases\IB_WEBINAR.IB'; ///
{$IFDEF MACOS}
cDatabase = 'IB_WEBINAR.IB'; ///
cServer = ''; ///
cPort = '3050'; ///
{$ELSE}
cDatabase = '..\..\data\IB_WEBINAR.IB'; ///
cServer = '127.0.0.1'; ///
cPort = '3055'; ///
{$ENDIF}
cUser_Name = 'SYSDBA'; ///
cPassword = 'masterkey'; ///
// ///
///////////////////////////////////////////////////////////////////////////////////
{ TDataModule1 }
procedure TDataModule1.ActivateDatabase;
begin
if FDConnection1.Connected then exit;
try
var DBName: string := ExpandFileName(cDatabase); // Necessary if the database is on a relative path like '../something/mydb.ib'
if not FileExists(DBName) then
ShowMessage('The database is not in the data folder!' + sLineBreak + sLineBreak + 'Should be here: "' + DBName + '"')
else
begin
///////////////////////////////////////////////////////////////////////////////////
// ///
// You should NEVER do this in a production app - it would be VERY easy for ///
// someone to examine the strings in your app and get the database credentials! ///
// We are doing this here for the sake of an easy/configurable demo ///
// ///
// You should either store it encrypted (and then decrypt it) or use techniques ///
// like private encrypted environment variables or indeed anything other than ///
// plain text! ///
// ///
FDConnection1.Params.Clear; ///
FDConnection1.Params.Add('DriverName=IB'); ///
FDConnection1.Params.Add('DriverID=IB'); ///
FDConnection1.Params.Add('Database=' + DBName); ///
FDConnection1.Params.Add('Server=' + cServer); ///
FDConnection1.Params.Add('Port=' + cPort); ///
FDConnection1.Params.Add('User_Name=' + cUser_Name); ///
FDConnection1.Params.Add('Password=' + cPassword); ///
// ///
///////////////////////////////////////////////////////////////////////////////////
FDConnection1.Open;
end;
except On E: Exception do
ShowMessage('DB Error - "' + E.Message + '"');
end;
end;
procedure TDataModule1.CreateChartData(const TheTable: string; const WithLabels: Boolean; TheVals: array of Integer; TheLabels: array of string);
begin
FDTable1.Active := False;
FDDeleteContents.Sql.Text := 'TRUNCATE TABLE ' + TheTable;
FDDeleteContents.ExecSQL;
FDTable1.TableName := TheTable;
FDTable1.Active := True;
for var LLoop := Low(TheVals) to High(TheVals) do
begin
FDTable1.Append;
FDTable1.FieldByName('ID').AsInteger := LLoop;
FDTable1.FieldByName('VAL1').AsInteger := TheVals[LLoop];
if WithLabels then
FDTable1.FieldByName('VAL2').AsString := TheLabels[LLoop];
FDTable1.Post;
end;
FDTable1.Active := False;
end;
procedure TDataModule1.CreateChartValues;
begin
CreateChartData('CHART1', True, [100, 200, 500, 100, 200, 500], ['Direct', 'Email', 'Website', 'Partner', 'Reseller', 'Social']);
CreateChartData('CHART2', False, [100, 200, 500, 100, 200, 500, 150, 102, 207, 134, 100], []);
CreateChartData('CHART3', False, [100, 200, 500, 100, 200, 500, 150, 102, 207, 134, 100], []);
CreateChartData('CHART4', True, [100, 200, 500, 100, 200, 500], ['Books', 'Audio', 'Notes', 'Folders', 'Files', 'Apps']);
CreateChartData('CHART5', False, [100, 200, 500, 100, 200, 500, 150, 102, 207, 134, 100], []);
CreateChartData('CHART6_0', False, [14, 22, 53, 88, 29, 51, 15, 12, 37, 14, 18], []);
CreateChartData('CHART6_1', False, [10, 20, 50, 10, 20, 50, 15, 12, 27, 13, 10], []);
CreateChartData('CHART6_2', False, [10, 20, 50, 10, 20, 50, 15, 12, 27, 13, 10], []);
end;
procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
FMS := TFormatSettings.Create;
end;
procedure TDataModule1.GetChartValues(const TheTable: string; const TheSeries: TChartSeries; const WithLabels: boolean);
var
LLabel: string;
begin
TheSeries.Clear;
FDQuery1.SQL.Text := 'select * from ' + TheTable + ' order by ID';
FDQuery1.Active := True;
while not FDQuery1.EOF do
begin
if WithLabels then
LLabel := FDQuery1.FieldByName('VAL2').AsString
else
LLabel := FMS.ShortMonthNames[(FDQuery1.RecordCount mod 11) + 1];
TheSeries.Add(FDQuery1.FieldByName('VAL1').AsInteger, LLabel);
FDQuery1.Next;
end;
FDQuery1.Active := False;
end;
end.