-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlgPreferences.pas
569 lines (512 loc) · 17.3 KB
/
dlgPreferences.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
unit dlgPreferences;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, 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, Data.DB,
FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.StdCtrls, Vcl.Buttons,
Vcl.Samples.Spin, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.Mask, Vcl.DBCtrls,
Vcl.ExtDlgs, Vcl.WinXCtrls;
type
TPreferences = class(TForm)
Bevel1: TBevel;
btn1: TSpeedButton;
btnClearClubLogo: TButton;
btnClose: TButton;
btnLoadClubLogo: TButton;
btnSaveClubLogo: TButton;
DBEdit1: TDBEdit;
DBEdit10: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit9: TDBEdit;
DBImage1: TDBImage;
DBText1: TDBText;
dsSwimClub: TDataSource;
dtpStartOfSwimSeason: TDateTimePicker;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lblSeedDepth1: TLabel;
lblSeedDepth2: TLabel;
OpenPictureDialog1: TOpenPictureDialog;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
prefCheckUnNomination: TCheckBox;
prefDisplayDivisions: TCheckBox;
prefDisplaySwimmerCAT: TCheckBox;
prefEnableDCodes: TCheckBox;
prefEnableSplitTimesForINDV: TCheckBox;
prefEnableSplitTimesForTEAM: TCheckBox;
prefEnableTeamEvents: TCheckBox;
prefExcludeOutsideLanes: TCheckBox;
prefGenerateEventDescription: TCheckBox;
prefGenerateEventDescStr: TEdit;
prefGroupBy: TRadioGroup;
prefHeatAlgorithm: TRadioGroup;
prefImportSeedTime: TRadioGroup;
prefRaceTimeTopPercent: TSpinEdit;
prefSeperateGender: TCheckBox;
prefShowDebugInfo: TCheckBox;
prefUseDefRaceTime: TCheckBox;
prefUseWindowsDefTheme: TCheckBox;
qrySwimClub: TFDQuery;
rgpSeedMethod: TRadioGroup;
SavePictureDialog1: TSavePictureDialog;
spnSeedDepth: TSpinEdit;
tab1: TTabSheet;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
TabSheet6: TTabSheet;
tblSystem: TFDTable;
TabSheet7: TTabSheet;
edtMemberChartDataPoints: TEdit;
Label19: TLabel;
Label20: TLabel;
prefHideTitlePanel: TCheckBox;
procedure btnClearClubLogoClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnLoadClubLogoClick(Sender: TObject);
procedure btnSaveClubLogoClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure PageControl1Changing(Sender: TObject; var AllowChange: Boolean);
private
FConnection: TFDConnection;
// procedure AssignClubLogoToImage(AImage: TImage); //--
procedure AssignDTtoStartOfSwimSeason();
procedure AssignStartOfSwimSeasonToDT();
procedure ReadPreferences(IniFileName: string);
procedure WritePreferences(IniFileName: string);
public
constructor Create(AOwner: TComponent; AConnection: TFDConnection);
reintroduce; overload;
property Connection: TFDConnection read FConnection write FConnection;
// property MemberChartDataPoints: integer read fMemberChartDataPoints write fMemberChartDataPoints;
end;
var
Preferences: TPreferences;
implementation
{$R *.dfm}
uses SCMUtility, IniFiles, Imaging.jpeg, Imaging.pngimage, System.UITypes;
constructor TPreferences.Create(AOwner: TComponent; AConnection: TFDConnection);
begin
inherited Create(AOwner);
if Assigned(AConnection) then
FConnection := AConnection
else
FConnection := nil;
end;
{ TPreferences }
{
procedure TPreferences.AssignClubLogoToImage(AImage: TImage);
var
Stream: TStream;
aJpgImage: TJPEGImage;
aPngImage: TPngImage;
aBmpImage: TBitmap;
fn, s: String;
begin
// Clear TImage
AImage.Picture.Assign(nil);
if not Assigned(FConnection) then
exit;
if not qrySwimClub.Active then
exit;
if qrySwimClub.FieldByName('LogoDir').IsNull then
exit;
// I N I T I A L I Z E .
Stream := nil;
aJpgImage := nil;
aPngImage := nil;
aBmpImage := nil;
fn := qrySwimClub.FieldByName('LogoDir').AsString;
if fn.IsEmpty then
exit;
s := ExtractFileExt(fn);
s := LowerCase(s);
if ((s = '.jpg') or (s = '.jpeg')) then
begin
try
begin
aJpgImage := TJPEGImage.Create;
Stream := qrySwimClub.CreateBlobStream
(qrySwimClub.FieldByName('LogoImg'), bmRead);
Stream.Seek(0, 0);
aJpgImage.LoadFromStream(Stream);
AImage.Picture.Assign(aJpgImage);
end;
finally
begin
aJpgImage.free;
Stream.free;
end;
end;
end
else if (s = '.png') then
begin
try
begin
aPngImage := TPngImage.Create;
Stream := qrySwimClub.CreateBlobStream
(qrySwimClub.FieldByName('LogoImg'), bmRead);
Stream.Seek(0, 0);
aPngImage.LoadFromStream(Stream);
AImage.Picture.Assign(aPngImage);
end;
finally
begin
aPngImage.free;
Stream.free;
end;
end;
end
else if (s = '.bmp') then
begin
try
begin
aBmpImage := TBitmap.Create;
Stream := qrySwimClub.CreateBlobStream
(qrySwimClub.FieldByName('LogoImg'), bmRead);
Stream.Seek(0, 0);
aBmpImage.LoadFromStream(Stream);
AImage.Picture.Bitmap.Assign(aBmpImage);
end;
finally
begin
aBmpImage.free;
Stream.free;
end;
end;
end;
end;
}
procedure TPreferences.AssignDTtoStartOfSwimSeason;
begin
if (Assigned(FConnection) and (qrySwimClub.Active)) then
begin
if qrySwimClub.FieldByName('StartOfSwimSeason').AsDateTime <>
dtpStartOfSwimSeason.Date then
begin
qrySwimClub.Edit;
qrySwimClub.FieldByName('StartOfSwimSeason').AsDateTime :=
dtpStartOfSwimSeason.Date;
qrySwimClub.Post;
end;
end;
end;
procedure TPreferences.AssignStartOfSwimSeasonToDT;
var
dt: TDateTime;
begin
if (Assigned(FConnection) and (qrySwimClub.Active)) then
begin
dt := qrySwimClub.FieldByName('StartOfSwimSeason').AsDateTime;
if (dt > 0) then
dtpStartOfSwimSeason.Date := dt
else
dtpStartOfSwimSeason.Date := Date;
end;
end;
procedure TPreferences.btnClearClubLogoClick(Sender: TObject);
begin
if (Assigned(FConnection) and (qrySwimClub.Active)) then
begin
qrySwimClub.Edit;
qrySwimClub.FieldByName('LogoDir').Clear;
qrySwimClub.FieldByName('LogoImg').Clear;
qrySwimClub.FieldByName('LogoType').Clear;
qrySwimClub.Post;
end;
end;
procedure TPreferences.btnCloseClick(Sender: TObject);
begin
// w r i t e o u t d a t a b a s e c h a n g e s .
if (Assigned(FConnection)) and (qrySwimClub.Active) then
begin
AssignDTtoStartOfSwimSeason;
qrySwimClub.CheckBrowseMode;
qrySwimClub.Close;
end;
ModalResult := mrOk;
end;
procedure TPreferences.btnLoadClubLogoClick(Sender: TObject);
var
s: string;
FileStream: TFileStream;
BlobStream: TStream;
begin
// NOTE: TOpenPictureDialog.options - ofPathMustExist, ofFileMustExist.
if (OpenPictureDialog1.Execute) then
begin
qrySwimClub.Edit;
try
// part 1 : deal with the blob - .png, .bmp, .jpeg, .jpg
// qrySwimClub.FieldByName('LogoImg').Clear;
BlobStream := qrySwimClub.CreateBlobStream
(qrySwimClub.FieldByName('LogoImg'), bmWrite);
FileStream := TFileStream.Create(OpenPictureDialog1.FileName,
fmOpenRead or fmShareDenyNone);
BlobStream.CopyFrom(FileStream, FileStream.Size);
FileStream.free;
BlobStream.free;
// part 2 : directory info and image type
// the filename is used to identify the graphic type.
qrySwimClub.FieldByName('LogoDir').AsString :=
OpenPictureDialog1.FileName;
s := ExtractFileExt(OpenPictureDialog1.FileName);
s := LowerCase(s);
qrySwimClub.FieldByName('LogoType').AsString := s;
qrySwimClub.Post;
except
qrySwimClub.Cancel;
end;
// (qrySwimClub.FieldByName('LogoImg') as TBlobField)
// .LoadFromFile(OpenPictureDialog1.FileName);
// Display the new logo into the UI
// AssignClubLogoToImage(LogoImage);
end;
end;
procedure TPreferences.btnSaveClubLogoClick(Sender: TObject);
var
FileStream: TFileStream;
BlobStream: TStream;
begin
// test table is connected and open
if not(qrySwimClub.Active) then
exit;
if (SavePictureDialog1.Execute) then
begin
FileStream := TFileStream.Create(SavePictureDialog1.FileName, fmCreate);
BlobStream := qrySwimClub.CreateBlobStream
(qrySwimClub.FieldByName('LogoImg'), bmRead);
FileStream.CopyFrom(BlobStream, BlobStream.Size);
BlobStream.free;
FileStream.free;
end;
end;
procedure TPreferences.FormCreate(Sender: TObject);
var
IniFileName: string;
begin
// I N I T L O C A L U I P A R A M S .
PageControl1.TabIndex := 0;
dtpStartOfSwimSeason.Date := Date;
rgpSeedMethod.Enabled := true;
spnSeedDepth.Enabled := true;
lblSeedDepth1.Enabled := true;
lblSeedDepth2.Enabled := true;
rgpSeedMethod.ItemIndex := 0;
// r e a d p r e f e r e n c e .
IniFileName := SCMUtility.GetSCMPreferenceFileName();
if (FileExists(IniFileName)) then
ReadPreferences(IniFileName);
// ensures a data connection is viable - if the main data module is active
if Assigned(FConnection) then
begin
DBImage1.DataField := 'LogoImg';
qrySwimClub.Connection := FConnection;
qrySwimClub.Open;
if (qrySwimClub.Active = true) then
begin
AssignStartOfSwimSeasonToDT;
end;
end;
end;
procedure TPreferences.FormDestroy(Sender: TObject);
var
IniFileName: string;
begin
// w r i t e p r e f e r e n c e s .
IniFileName := SCMUtility.GetSCMPreferenceFileName();
if (FileExists(IniFileName)) then
WritePreferences(IniFileName);
end;
procedure TPreferences.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = vk_escape then
begin
// special note:
// By default all database changes are saved.
btnCloseClick(self);
Key := 0;
end;
end;
procedure TPreferences.PageControl1Changing(Sender: TObject;
var AllowChange: Boolean);
begin
if (Assigned(FConnection) and (qrySwimClub.Active)) then
begin
if (PageControl1.TabIndex = 0) or (PageControl1.TabIndex = 1) then
qrySwimClub.CheckBrowseMode;
end;
AllowChange := true;
end;
procedure TPreferences.ReadPreferences(IniFileName: string);
var
iFile: TIniFile;
i, iUnChecked, iChecked: integer;
begin
iFile := TIniFile.Create(IniFileName);
{
Using Ord is generally considered best practice when converting an
enumeration to its corresponding integer value in Delphi.
}
iUnChecked := Ord(TCheckBoxState.cbUnchecked);
iChecked := Ord(TCheckBoxState.cbChecked);
// 2024/08/31 Add more screen real estate.
i := iFile.ReadInteger('Preferences', 'HideTitlePanel', iUnChecked);
prefHideTitlePanel.State := TCheckBoxState(i);
i := iFile.ReadInteger('Preferences', 'ShowDebugInfo', iUnChecked);
prefShowDebugInfo.State := TCheckBoxState(i);
i := iFile.ReadInteger('Preferences', 'UseWindowsDefTheme', iUnChecked);
prefUseWindowsDefTheme.State := TCheckBoxState(i);
// TTB defaults to (1) .. the entrant's average of top 3 race-times
prefHeatAlgorithm.ItemIndex :=
(iFile.ReadInteger('Preferences', 'HeatAlgorithm', 1));
// default to - get an average race-time of other swimmers
i := iFile.ReadInteger('Preferences', 'UseDefRaceTime', iChecked);
prefUseDefRaceTime.State := TCheckBoxState(i);
i := iFile.ReadInteger('Preferences', 'CheckUnNomination', iUnChecked);
prefCheckUnNomination.State := TCheckBoxState(i);
// The bottom percent to select from ... default is 50%
prefRaceTimeTopPercent.Value :=
(iFile.ReadInteger('Preferences', 'RaceTimeTopPercent', 50));
// defaullt - do nothing - ignore
prefImportSeedTime.ItemIndex := iFile.ReadInteger('Preferences',
'ImportSeedTime', 0);
// auto-create heats - this option will omit gutter lanes
i := iFile.ReadInteger('Preferences', 'ExcludeOutsideLanes', iUnChecked);
prefExcludeOutsideLanes.State := TCheckBoxState(i);
// auto-create heats - seperate male from female
i := iFile.ReadInteger('Preferences', 'SeperateGender', iUnChecked);
prefSeperateGender.State := TCheckBoxState(i);
prefGroupBy.ItemIndex := iFile.ReadInteger('Preferences', 'GroupBy', 0);
rgpSeedMethod.ItemIndex := iFile.ReadInteger('Preferences', 'SeedMethod', 0);
// Generate event descriptions
i := iFile.ReadInteger('Preferences', 'GenerateEventDescription', iUnChecked);
prefGenerateEventDescription.State := TCheckBoxState(i);
prefGenerateEventDescStr.Text := iFile.ReadString('Preferences',
'GenerateEventDescStr', ' - Individual, all genders, all ages.');
// Generate event descriptions (TEAM)
// i := iFile.ReadInteger('Preferences', 'GenerateTEAMDescription', iUnChecked);
// prefGenerateTEAMDescription.State := TCheckBoxState(i);
// prefGenerateTEAMDescStr.Text := iFile.ReadString('Preferences',
// 'GenerateEventTeamDescStr', ' - RELAY.');
rgpSeedMethod.ItemIndex := iFile.ReadInteger('Preferences', 'SeedMethod', 0);
{ /* 2020-11-01 auto-build v2 seed method */ }
rgpSeedMethod.ItemIndex := iFile.ReadInteger('Preferences', 'SeedMethod', 0);
{ /* 2020-11-01 auto-build v2 seed depth for Circle Seed */ }
spnSeedDepth.Value := (iFile.ReadInteger('Preferences', 'SeedDepth', 3));
// 2023.06.26
prefEnableTeamEvents.Checked := iFile.ReadBool('Preferences',
'EnableTeamEvents', true);
prefEnableDCodes.Checked := iFile.ReadBool('Preferences',
'EnableDCodes', false);
prefDisplaySwimmerCAT.Checked := iFile.ReadBool('Preferences',
'DisplaySwimmerCAT', false);
prefDisplayDivisions.Checked := iFile.ReadBool('Preferences',
'DisplayDivisions', false);
//2024/1/1
prefEnableSplitTimesForINDV.Checked := iFile.ReadBool('Preferences',
'EnableSplitTimesForINDV', false);
prefEnableSplitTimesForTeam.Checked := iFile.ReadBool('Preferences',
'EnableSplitTimesForTEAM', false);
// 2024/03/19 Value used by TFDQuery qryChart to select TOP ###
i := iFile.ReadInteger('ManageMemberData', 'MemberChartDataPoints', 26);
edtMemberChartDataPoints.Text := IntToStr(i);
iFile.free;
end;
procedure TPreferences.WritePreferences(IniFileName: string);
var
iFile: TIniFile;
i: integer;
begin
iFile := TIniFile.Create(IniFileName);
// 2024/08/31
iFile.WriteInteger('Preferences', 'HideTitlePanel',
integer(prefHideTitlePanel.State));
iFile.WriteInteger('Preferences', 'ShowDebugInfo',
integer(prefShowDebugInfo.State));
iFile.WriteInteger('Preferences', 'UseWindowsDefTheme',
integer(prefUseWindowsDefTheme.State));
iFile.WriteInteger('Preferences', 'HeatAlgorithm',
integer(prefHeatAlgorithm.ItemIndex));
iFile.WriteInteger('Preferences', 'UseDefRaceTime',
integer(prefUseDefRaceTime.State));
iFile.WriteInteger('Preferences', 'CheckUnNomination',
integer(prefCheckUnNomination.State));
iFile.WriteInteger('Preferences', 'RaceTimeTopPercent',
(prefRaceTimeTopPercent.Value));
iFile.WriteInteger('Preferences', 'ImportSeedTime',
(prefImportSeedTime.ItemIndex));
iFile.WriteInteger('Preferences', 'ExcludeOutsideLanes',
integer(prefExcludeOutsideLanes.State));
iFile.WriteInteger('Preferences', 'SeperateGender',
integer(prefSeperateGender.State));
iFile.WriteInteger('Preferences', 'GroupBy', prefGroupBy.ItemIndex);
// generate event description
iFile.WriteInteger('Preferences', 'GenerateEventDescription',
integer(prefGenerateEventDescription.State));
iFile.WriteString('Preferences', 'GenerateEventDescStr',
prefGenerateEventDescStr.Text);
// generate event description (TEAM)
// iFile.WriteInteger('Preferences', 'GenerateTEAMDescription',
// integer(prefGenerateTEAMDescription.State));
// iFile.WriteString('Preferences', 'GenerateTEAMDescStr',
// prefGenerateTEAMDescStr.Text);
{ 2020-11-01 auto-build v2 seed method }
iFile.WriteInteger('Preferences', 'SeedMethod', rgpSeedMethod.ItemIndex);
{ 2020-11-01 auto-build v2 seed depth for Circle Seed }
iFile.WriteInteger('Preferences', 'SeedDepth', (spnSeedDepth.Value));
// 2023.06.26
iFile.WriteBool('Preferences', 'EnableTeamEvents',
prefEnableTeamEvents.Checked);
iFile.WriteBool('Preferences', 'EnableDCodes',
prefEnableDCodes.Checked);
iFile.WriteBool('Preferences', 'DisplaySwimmerCAT', prefDisplaySwimmerCAT.Checked);
iFile.WriteBool('Preferences', 'DisplayDivision', prefDisplayDivisions.Checked);
//2024/1/1
iFile.WriteBool('Preferences', 'EnableSplitTimesForINDV',
prefEnableSplitTimesForINDV.Checked);
iFile.WriteBool('Preferences', 'EnableSplitTimesForTEAM',
prefEnableSplitTimesForTEAM.Checked);
// 2024/03/19 Value used by TFDQuery qryChart to select TOP ###
try
i := Round(StrToFloatDef(edtMemberChartDataPoints.Text, 0));
except
on E: Exception do i := 26;
end;
if (i < 10) then i := 10;
if (i > 1000) then i := 1000;
iFile.WriteInteger('ManageMemberData', 'MemberChartDataPoints', i);
iFile.free;
end;
end.