-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlgPointsScored.pas
393 lines (362 loc) · 10.1 KB
/
dlgPointsScored.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
unit dlgPointsScored;
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.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.Mask, Vcl.ExtCtrls,
Vcl.ComCtrls, frxPreview, frxClass, frxDBSet;
type
TPointsScored = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
btnClose: TButton;
lblPlace: TLabel;
lblPoints: TLabel;
lbl01: TLabel;
lbl02: TLabel;
lbl03: TLabel;
lbl04: TLabel;
lbl05: TLabel;
lbl06: TLabel;
lbl07: TLabel;
lbl08: TLabel;
lbl09: TLabel;
lbl10: TLabel;
lbl11: TLabel;
lbl12: TLabel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
edtm01: TMaskEdit;
edtm02: TMaskEdit;
edtm03: TMaskEdit;
edtm04: TMaskEdit;
edtm05: TMaskEdit;
edtm06: TMaskEdit;
edtm07: TMaskEdit;
edtm08: TMaskEdit;
edtm09: TMaskEdit;
edtm10: TMaskEdit;
edtm11: TMaskEdit;
edtm12: TMaskEdit;
cmdInsertPlace: TFDCommand;
cmdDeletePlace: TFDCommand;
dsScorePoints: TDataSource;
btnPointsScored: TButton;
Label10: TLabel;
tblScorePoints: TFDTable;
edtm00: TMaskEdit;
Label6: TLabel;
Label1: TLabel;
edtm13: TMaskEdit;
Label7: TLabel;
edtm14: TMaskEdit;
Label8: TLabel;
edtm15: TMaskEdit;
Label11: TLabel;
edtm16: TMaskEdit;
Label12: TLabel;
edtm17: TMaskEdit;
Label13: TLabel;
edtm18: TMaskEdit;
Label14: TLabel;
edtm19: TMaskEdit;
Label15: TLabel;
edtm20: TMaskEdit;
Label16: TLabel;
Label17: TLabel;
Label20: TLabel;
Label21: TLabel;
edtm21: TMaskEdit;
edtm22: TMaskEdit;
Label22: TLabel;
edtm23: TMaskEdit;
Label23: TLabel;
edtm24: TMaskEdit;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
edtm31: TMaskEdit;
edtm32: TMaskEdit;
Label28: TLabel;
edtm25: TMaskEdit;
Label29: TLabel;
edtm26: TMaskEdit;
Label30: TLabel;
edtm27: TMaskEdit;
Label31: TLabel;
edtm28: TMaskEdit;
Label32: TLabel;
edtm29: TMaskEdit;
Label33: TLabel;
edtm30: TMaskEdit;
Label34: TLabel;
Label35: TLabel;
qryRptHeader: TFDQuery;
frxDBDSRptHeader: TfrxDBDataset;
qryPointsScored: TFDQuery;
frxDSPointsScored: TfrxDBDataset;
frxPointsScored: TfrxReport;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure edtmOnChange(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure btnPointsScoredClick(Sender: TObject);
private
{ Private declarations }
fSwimClubID: integer;
fMaxEDTM: integer;
IsUnderConstruction: boolean;
IsModifiedScore: boolean;
fConnection: TFDConnection;
function LocatePlacing(place, SwimClubID: integer): boolean;
procedure WritePreferences(iniFileName: string);
procedure ReadPreferences(iniFileName: string);
procedure ReadScores();
procedure WriteScores();
public
{ Public declarations }
property Connection: TFDConnection write FConnection;
property SwimClubID: integer read FSwimClubID write FSwimClubID;
end;
var
PointsScored: TPointsScored;
implementation
{$R *.dfm}
uses SCMUtility, iniFiles;
procedure TPointsScored.btnCloseClick(Sender: TObject);
begin
ModalResult := mrOk;
end;
procedure TPointsScored.btnPointsScoredClick(Sender: TObject);
begin
// note : uses RPTS.qryRptHeader
if (fSwimClubID <> 0) and Assigned(fConnection) then
begin
WriteScores; // update DB Score table ...
IsModifiedScore := false;
// ready queries and send to fast reports
qryRptHeader.Connection := fConnection;
qryRptHeader.Open();
qryPointsScored.Connection := fConnection;
qryPointsScored.ParamByName('SWIMCLUBID').AsInteger := fSwimClubID;
qryPointsScored.Prepare();
qryPointsScored.Open();
if (qryPointsScored.Active) and (qryRptHeader.Active) then
frxPointsScored.ShowReport;
end;
end;
procedure TPointsScored.edtmOnChange(Sender: TObject);
begin
if not IsUnderConstruction then
IsModifiedScore := true;
end;
procedure TPointsScored.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (IsModifiedScore) then
begin
WriteScores; // update DB Score table ...
IsModifiedScore := false;
end;
Action := caFree;
end;
procedure TPointsScored.FormCreate(Sender: TObject);
var
i: integer;
s, iniFileName: string;
comp: TComponent;
begin
// i n i t p a r a m s .
// -------------------------------------
PageControl1.TabIndex := 0;
fSwimClubID := 1;
IsModifiedScore := false;
fMaxEDTM := 32; // 3xHeats at 8 per lanes
// -------------------------------------
// r e a d p r e f e r e n c e .
// -------------------------------------
iniFileName := SCMUtility.GetSCMPreferenceFileName;
if FileExists(iniFileName) then
ReadPreferences(iniFileName);
// -------------------------------------
// 'Zero' values in edtm TMaskEdit
// -------------------------------------
IsUnderConstruction := true;
for i := 0 to fMaxEDTM do
begin
s := 'edtm' + Format('%0.2d', [i]);
comp := FindComponent(s);
if assigned(comp) then
(comp as TMaskEdit).editText := '00.0';
end;
IsUnderConstruction := false;
PageControl1.TabIndex := 0;
end;
procedure TPointsScored.FormDestroy(Sender: TObject);
var
iniFileName: string;
begin
iniFileName := GetSCMPreferenceFileName();
if FileExists(iniFileName) then
WritePreferences(iniFileName);
end;
procedure TPointsScored.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
ModalResult := mrOk;
end;
procedure TPointsScored.FormShow(Sender: TObject);
begin
// -------------------------------------
// C O N N E C T L O C A L D A T A S E T S .
// -------------------------------------
if assigned(fConnection) then
begin
tblScorePoints.Connection := fConnection;
cmdInsertPlace.Connection := fConnection;
cmdDeletePlace.Connection := fConnection;
// Activate tables/queries contained in this dialogue
tblScorePoints.Open;
end;
IsUnderConstruction := true;
// -------------------------------------
// R E A D S C O R E S .
// -------------------------------------
ReadScores;
IsUnderConstruction := false;
end;
function TPointsScored.LocatePlacing(place, SwimClubID: integer): boolean;
begin
try
result := tblScorePoints.Locate('Place;SwimClubID',
VarArrayOf([place, SwimClubID]), [loPartialKey]);
except
on E: Exception do
result := false;
end;
end;
procedure TPointsScored.ReadPreferences(iniFileName: string);
var
iFile: TIniFile;
begin
iFile := TIniFile.Create(iniFileName);
//
iFile.Free;
end;
procedure TPointsScored.ReadScores;
var
i: integer;
s: string;
comp: TComponent;
success: boolean;
scorePoints: double;
begin
// populate visible edit boxes with data from SwimClubMeet table Score.
// if data doesn't exist then skip...
for i := 0 to fMaxEDTM do
begin
s := 'edtm' + Format('%0.2d', [i]);
comp := FindComponent(s);
if assigned(comp) then
begin
if (tblScorePoints.Active) then
begin
// locate 'score' for requested place.
success := LocatePlacing(i, fSwimClubID);
if (success) then
begin
scorePoints := tblScorePoints.FieldByName('Points').AsFloat;
s := FloatToStrF(scorePoints, ffFixed, 4, 1);
// pad with leading '0' to conform to editmask....
if Length(s) > 4 then
begin
s := s.SubString((Length(s) - 4), Length(s));
end;
if (Length(s) < 4) then
begin
s := '0' + s;
end;
(comp as TMaskEdit).editText := s;
end;
end;
end;
end;
end;
procedure TPointsScored.WritePreferences(iniFileName: string);
var
iFile: TIniFile;
begin
iFile := TIniFile.Create(iniFileName);
//
iFile.Free;
end;
procedure TPointsScored.WriteScores;
var
i: integer;
scorePoints: double;
s: String;
comp: TComponent;
edtm: TMaskEdit;
success: boolean;
begin
if (IsUnderConstruction = true) then
exit;
// update the Score table ...
for i := 0 to fMaxEDTM do
begin
s := 'edtm' + Format('%0.2d', [i]);
comp := FindComponent(s);
if assigned(comp) then
begin
edtm := comp as TMaskEdit;
scorePoints := double(StrToFloatDef(edtm.editText, 0));
if tblScorePoints.Active then
begin
success := LocatePlacing(edtm.Tag, fSwimClubID);
if (success) then
begin
tblScorePoints.Edit;
tblScorePoints.FieldByName('Points').AsFloat := scorePoints;
tblScorePoints.Post();
end
else
begin
if (fSwimClubID > 0) then
begin
cmdInsertPlace.Close;
cmdInsertPlace.ParamByName('SWIMCLUBID').AsInteger := fSwimClubID;
cmdInsertPlace.ParamByName('POINTS').AsFloat := double(scorePoints);
cmdInsertPlace.ParamByName('PLACE').AsInteger := edtm.Tag;
cmdInsertPlace.Prepare;
cmdInsertPlace.Open; // execute the command
cmdInsertPlace.Close;
end;
end;
end;
end;
end;
// --------------------------------------
// c l e a n D a t a B a s e .
// delete records greater than Lane-Count
// --------------------------------------
if (fSwimClubID > 0) then
begin
cmdDeletePlace.Close;
cmdDeletePlace.ParamByName('SWIMCLUBID').AsInteger := fSwimClubID;
cmdDeletePlace.ParamByName('PLACE').AsInteger := fMaxEDTM;
cmdDeletePlace.Prepare();
cmdDeletePlace.Open(); // execute the command
cmdDeletePlace.Close();
end;
IsModifiedScore := false;
end;
end.