-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgQualifyTimes.pas
324 lines (296 loc) · 8.34 KB
/
dlgQualifyTimes.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
unit dlgQualifyTimes;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, FireDAC.Stan.Intf,
FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.Grids, Vcl.DBGrids, Vcl.ComCtrls, dmSCM;
type
TQualifyTimes = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
DBGrid1: TDBGrid;
Panel1: TPanel;
Label3: TLabel;
Panel3: TPanel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
TabSheet2: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Label10: TLabel;
Label12: TLabel;
Label9: TLabel;
Label11: TLabel;
Label13: TLabel;
btnSessionReport: TButton;
btnMemberReport: TButton;
btnDistStrokeReport: TButton;
btnTableReport: TButton;
btnNotQualifyReport: TButton;
Panel2: TPanel;
BtnClose: TButton;
qryQualify: TFDQuery;
qryQualifyTrialDistID: TIntegerField;
qryQualifyQualifyDistID: TIntegerField;
qryQualifyStrokeID: TIntegerField;
qryQualifyIsShortCourse: TBooleanField;
qryQualifyGenderID: TIntegerField;
qryQualifyQualifyID: TFDAutoIncField;
qryQualifyluQDistance: TStringField;
qryQualifyluStroke: TStringField;
qryQualifyluTDistance: TStringField;
qryQualifyluGender: TStringField;
qryQualifyTrialTime: TTimeField;
DSQualify: TDataSource;
tblStroke: TFDTable;
tblGender: TFDTable;
qryQDistance: TFDQuery;
qryTDistance: TFDQuery;
procedure BtnCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure qryQualifyTrialTimeGetText(Sender: TField; var Text: string;
DisplayText: Boolean);
procedure qryQualifyTrialTimeSetText(Sender: TField; const Text: string);
procedure btnSessionReportClick(Sender: TObject);
procedure btnTableReportClick(Sender: TObject);
procedure btnMemberReportClick(Sender: TObject);
procedure btnDistStrokeReportClick(Sender: TObject);
procedure btnNotQualifyReportClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
QualifyTimes: TQualifyTimes;
implementation
{$R *.dfm}
uses rptQTSessionReportA, rptQTDistStrokeReportA, rptQTMemberReportA,
rptQTTableReportA, rptQTNotQualified;
procedure TQualifyTimes.BtnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TQualifyTimes.btnDistStrokeReportClick(Sender: TObject);
var
rptA: TQTDistStrokeReportA;
// rptB: TQTDistStrokeReportB;
begin
// run qulify for session report
try
// control key is pressed
if ((GetKeyState(VK_CONTROL) and 128) = 128) then
begin
// rptB := TQTDistStrokeReportB.Create(self);
// rptB.RunReport;
// rptB.Free;
end
else
begin
rptA := TQTDistStrokeReportA.Create(self);
rptA.RunReport();
rptA.Free;
end;
except
on E: Exception do
// illegal date..
ShowMessage('Error opening QualifyTimes : Session Report.');
end;
if BtnClose.CanFocus then
BtnClose.SetFocus;
end;
procedure TQualifyTimes.btnMemberReportClick(Sender: TObject);
var
rptA: TQTMemberReportA;
// rptB: TQTMemberReportB;
begin
// run qulify for session report
try
// control key is pressed
if ((GetKeyState(VK_CONTROL) and 128) = 128) then
begin
// rptB := TQTMemberReportB.Create(self);
// rptB.RunReport;
// rptB.Free;
end
else
begin
rptA := TQTMemberReportA.Create(self);
rptA.RunReport();
rptA.Free;
end;
except
on E: Exception do
// illegal date..
ShowMessage('Error opening QualifyTimes : Session Report.');
end;
if BtnClose.CanFocus then
BtnClose.SetFocus;
end;
procedure TQualifyTimes.btnNotQualifyReportClick(Sender: TObject);
var
rptA: TQTNotQualified;
begin
try
begin
rptA := TQTNotQualified.Create(self);
rptA.RunReport();
rptA.Free;
end
except
on E: Exception do
// illegal date..
ShowMessage('Error opening QualifyTimes : Session Report.');
end;
if BtnClose.CanFocus then BtnClose.SetFocus;
end;
procedure TQualifyTimes.btnSessionReportClick(Sender: TObject);
var
rptA: TQTSessionReportA;
begin
try
begin
rptA := TQTSessionReportA.Create(self);
rptA.RunReport();
rptA.Free;
end
except
on E: Exception do
// illegal date..
ShowMessage('Error opening QualifyTimes : Session Report.');
end;
if BtnClose.CanFocus then BtnClose.SetFocus;
end;
procedure TQualifyTimes.btnTableReportClick(Sender: TObject);
var
rptA: TQTTableReportA;
// rptB: TQTTableReportB;
begin
// run qulify for session report
try
// control key is pressed
if ((GetKeyState(VK_CONTROL) and 128) = 128) then
begin
// rptB := TQTTableReportB.Create(self);
// rptB.RunReport;
// rptB.Free;
end
else
begin
rptA := TQTTableReportA.Create(self);
rptA.RunReport();
rptA.Free;
end;
except
on E: Exception do
// illegal date..
ShowMessage('Error opening QualifyTimes : Table Report.');
end;
if BtnClose.CanFocus then
BtnClose.SetFocus;
end;
procedure TQualifyTimes.FormCreate(Sender: TObject);
begin
if not Assigned(SCM) then
raise Exception.Create('SCM not assigned.');
tblGender.Connection := SCM.scmConnection;
tblStroke.Connection := SCM.scmConnection;
qryQDistance.Connection := SCM.scmConnection;
qryTDistance.Connection := SCM.scmConnection;
qryQualify.Connection := SCM.scmConnection;
tblGender.Active := true;
tblStroke.Active := true;
qryQDistance.Active := true;
qryTDistance.Active := true;
// If changes have been made in option dialogue during the
// current connection session or on another station
// then refreshing the SwimClub table
// ensures LenOfPool reflects these changes.
if SCM.SwimClub_IsShortCourse then
begin
Label3.Caption := 'Qualification Times for Short Course Events (SC)';
qryQualify.ParamByName('ISSHORTCOURSE').AsBoolean := true;
end
else
begin
Label3.Caption := 'Qualification Times for Long Course Events (LC)';
qryQualify.ParamByName('ISSHORTCOURSE').AsBoolean := false;
end;
// ensures params changes are used
qryQualify.Prepare();
qryQualify.Open();
// Assert grid is connected
DBGrid1.DataSource := DSQualify;
PageControl1.TabIndex := 0;
end;
procedure TQualifyTimes.FormDestroy(Sender: TObject);
begin
qryQualify.Close;
end;
procedure TQualifyTimes.qryQualifyTrialTimeGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
var
Hour: word; // unsigned short: Word ;
Min: word; // unsigned short: Word ;
Sec: word;
MSec: word;
begin
DecodeTime(Sender.AsDateTime, Hour, Min, Sec, MSec);
// DisplayText is true if the field's value is to be used for display only;
// false if the string is to be used for editing the field's value.
if (DisplayText) then
begin
// "%" [index ":"] ["-"] [width] ["." prec] type
if (Min > 0) then
Text := Format('%0:2u:%1:2.2u.%2:3.3u', [Min, Sec, MSec])
else if ((Min = 0) and (Sec > 0)) then
Text := Format('%1:2u.%2:3.3u', [Min, Sec, MSec])
else if ((Min = 0) and (Sec = 0)) then
Text := '';
end
else
// "%" [index ":"] ["-"] [width] ["." prec] type
Text := Format('%0:2.2u:%1:2.2u.%2:3.3u', [Min, Sec, MSec]);
end;
procedure TQualifyTimes.qryQualifyTrialTimeSetText(Sender: TField;
const Text: string);
var
s: String;
dt: TDateTime;
Min, Sec, MSec: word;
i: integer;
failed: Boolean;
begin
failed := false;
// Take the user input that was entered into the time mask and replace
// spaces with '0'. Resulting in a valid TTime string.
// UnicodeString is '1-based'
s := Text;
for i := 1 to s.Length - 1 do
if (s[i] = ' ') then
s[i] := '0';
// SubString is '0-based'
Min := StrToIntDef(s.SubString(0, 2), 0);
Sec := StrToIntDef(s.SubString(3, 2), 0);
MSec := StrToIntDef(s.SubString(6, 3), 0);
try
begin
dt := EncodeTime(0, Min, Sec, MSec);
Sender.AsDateTime := dt;
end;
except
failed := true;
end;
// set the racetime to nil.
if failed then
Sender.Clear; // Sets the value of the field to NULL
end;
end.