-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmTimeKeeper.pas
1375 lines (1244 loc) · 38.4 KB
/
frmTimeKeeper.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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit frmTimeKeeper;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.ListView.Types, FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
Data.Bind.EngExt, FMX.Bind.DBEngExt, System.Rtti, System.Bindings.Outputs,
FMX.Bind.Editors, System.ImageList, FMX.ImgList, System.Actions, FMX.ActnList,
Data.Bind.Components, Data.Bind.DBScope, FMX.Objects, FMX.StdCtrls,
FMX.ListView, FMX.ListBox, FMX.Edit, FMX.Controls.Presentation,
FMX.TabControl, FMX.Layouts, dmSCM, System.Character,
System.IOUtils, Data.DB, FireDAC.Stan.Param, FMX.EditBox, FMX.SpinBox,
ProgramSetting, FMX.Styles.Objects;
type
TDefaultFont = class(TInterfacedObject, IFMXSystemFontService)
public
function GetDefaultFontFamilyName: string;
function GetDefaultFontSize: Single;
end;
TTimeKeeper = class(TForm)
ActionList1: TActionList;
actnConnect: TAction;
actnDisconnect: TAction;
actnPostTime: TAction;
actnRefresh: TAction;
actnSCMOptions: TAction;
AniIndicator1: TAniIndicator;
BindingsList1: TBindingsList;
bsEntrant: TBindSourceDB;
bsEvent: TBindSourceDB;
bsHeat: TBindSourceDB;
bsLane: TBindSourceDB;
bsSession: TBindSourceDB;
bsSwimClub: TBindSourceDB;
btn00: TButton;
btn01: TButton;
btn02: TButton;
btn03: TButton;
btn04: TButton;
btn05: TButton;
btn06: TButton;
btn07: TButton;
btn08: TButton;
btn09: TButton;
btnBackSpace: TButton;
btnClear: TButton;
btnClearTime: TButton;
btnConnect: TButton;
btnDisconnect: TButton;
btnGetTime: TButton;
btnPoint: TButton;
btnPost: TButton;
btnRefresh: TButton;
chkbLockToLane: TCheckBox;
chkbSessionVisibility: TCheckBox;
chkbUseOsAuthentication: TCheckBox;
cmbSessionList: TComboBox;
cmbSwimClubList: TComboBox;
edtPassword: TEdit;
edtServerName: TEdit;
edtUser: TEdit;
GridPanelLayout1: TGridPanelLayout;
ImageControl2: TImageControl;
imgBackSpaceCntrl: TImageControl;
Label1: TLabel;
Label12: TLabel;
Label18: TLabel;
Label3: TLabel;
Label4: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
layConnectButtons: TLayout;
layEntrantList: TLayout;
layEntrantName: TLayout;
layEntrantRaceTime: TLayout;
layEntrantStats: TLayout;
layEventHeat: TLayout;
layEventHeatTitleBar: TLayout;
layFooter: TLayout;
layLoginToServer: TLayout;
Layout1: TLayout;
layPersonalBest: TLayout;
layRaceTime: TLayout;
layRaceTimeDetail: TLayout;
layRaceTimeEditBox: TLayout;
layRaceTimeEnterTime: TLayout;
layRaceTimeText: TLayout;
layRaceTimeTitleBar: TLayout;
layRace_Time: TLayout;
laySelectSession: TLayout;
layTabs: TLayout;
layTimeToBeat: TLayout;
layTitleRaceTime: TLayout;
lblAniIndicatorStatus: TLabel;
lblEntrantName: TLabel;
lblEvent: TLabel;
lblHeat: TLabel;
lblPersonalBest: TLabel;
lblRaceTime: TLabel;
lblSelectSession: TLabel;
lblSelectSwimClub: TLabel;
lblStatusBar: TLabel;
lblTimeToBeat: TLabel;
lblTitleRaceTime: TLabel;
LinkListControlToField1: TLinkListControlToField;
LinkListControlToField2: TLinkListControlToField;
LinkListControlToField3: TLinkListControlToField;
LinkListControlToField4: TLinkListControlToField;
LinkListControlToField5: TLinkListControlToField;
LinkPropertyToFieldText5: TLinkPropertyToField;
LinkPropertyToFieldText6: TLinkPropertyToField;
LinkPropertyToFieldText7: TLinkPropertyToField;
LinkPropertyToFieldText8: TLinkPropertyToField;
ListViewEvent: TListView;
ListViewHeat: TListView;
ListViewLane: TListView;
Rectangle1: TRectangle;
Rectangle2: TRectangle;
ScaledLayout1: TScaledLayout;
SizeGrip1: TSizeGrip;
spinbNumOfDecimalPlaces: TSpinBox;
spinboxLockToLane: TSpinBox;
StyleBook1: TStyleBook;
StyleBook2: TStyleBook;
TabControl1: TTabControl;
tabEntrantRaceTime: TTabItem;
tabEventHeat: TTabItem;
tabLoginSession: TTabItem;
Timer1: TTimer;
txt03: TLabel;
txtRaceTime: TLabel;
procedure actnConnectExecute(Sender: TObject);
procedure actnConnectUpdate(Sender: TObject);
procedure actnDisconnectExecute(Sender: TObject);
procedure actnDisconnectUpdate(Sender: TObject);
procedure actnPostTimeExecute(Sender: TObject);
procedure actnPostTimeUpdate(Sender: TObject);
procedure actnRefreshExecute(Sender: TObject);
procedure actnRefreshUpdate(Sender: TObject);
procedure btnBackSpaceClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnClearTimeClick(Sender: TObject);
procedure btnGetTimeClick(Sender: TObject);
procedure btnNumClick(Sender: TObject);
procedure btnPointClick(Sender: TObject);
procedure chkbSessionVisibilityChange(Sender: TObject);
procedure cmbSessionListChange(Sender: TObject);
procedure cmbSwimClubListChange(Sender: TObject);
procedure edtRaceTimeEnter(Sender: TObject);
procedure edtRaceTimeKeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar;
Shift: TShiftState);
procedure ListViewEventChange(Sender: TObject);
procedure ListViewHeatChange(Sender: TObject);
procedure ListViewLaneChange(Sender: TObject);
procedure TabControl1Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
const
CONNECTIONTIMEOUT = 48;
var
fConnectionCountdown: Integer;
fLoginTimeOut: Integer;
fNumOfLanes: Integer;
procedure ClearRaceTime;
procedure ConnectOnTerminate(Sender: TObject);
function GetDisplayRaceTime(aRawString: string): string;
function GetRawRaceTime(RaceTimeStr: string): string;
function GetSCMVerInfo(): string;
procedure LoadFromSettings; // JSON Program Settings
procedure LoadSettings; // JSON Program Settings
procedure PostRaceTime;
procedure SaveToSettings; // JSON Program Settings
procedure Status_ConnectionDescription;
procedure Status_EventDescription;
procedure StickToLane;
procedure StripTimeChars(var s: string);
procedure TruncateTimeChars(var s: string; nodp: integer = 2);
procedure Update_EntrantStat;
procedure Update_Layout;
procedure Update_SessionVisibility;
procedure Update_TabSheetCaptions;
public
{ Public declarations }
procedure Refresh_Entrant;
procedure Refresh_Lane;
end;
var
TimeKeeper: TTimeKeeper;
implementation
{$R *.fmx}
uses
{$IFDEF MSWINDOWS}
// needed for call to winapi MessageBeep & Beep
Winapi.Windows,
// needed to show virtual keyboard in windows 10 32/64bit
// Shellapi,
{$ENDIF}
// FOR scmLoadOptions
// System.IniFiles,
// FOR Floor
System.Math, ExeInfo, SCMSimpleConnect, SCMUtility;
procedure TTimeKeeper.actnConnectExecute(Sender: TObject);
var
myThread: TThread;
sc: TSimpleConnect;
begin
if (Assigned(SCM) and (SCM.scmConnection.Connected = false)) then
begin
lblAniIndicatorStatus.Text := 'Connecting';
fConnectionCountdown := fLoginTimeOut;
AniIndicator1.Visible := true; // progress timer
AniIndicator1.Enabled := true; // start spinning
lblAniIndicatorStatus.Visible := true; // a label with countdown
Timer1.Enabled := true; // start the countdown
actnConnect.Visible := false;
application.ProcessMessages;
myThread := TThread.CreateAnonymousThread(
procedure
begin
// can only be assigned if not connected
SCM.scmConnection.Params.Values['LoginTimeOut'] :=
IntToStr(fLoginTimeOut);
sc := TSimpleConnect.CreateWithConnection(Self, SCM.scmConnection);
sc.DBName := 'SwimClubMeet'; // DEFAULT
sc.SimpleMakeTemporyConnection(edtServerName.Text, edtUser.Text,
edtPassword.Text, chkbUseOsAuthentication.IsChecked);
Timer1.Enabled := false;
sc.Free
end);
myThread.OnTerminate := ConnectOnTerminate;
myThread.Start;
end;
end;
procedure TTimeKeeper.actnConnectUpdate(Sender: TObject);
begin
// verbose code - stop unecessary repaints ...
if Assigned(SCM) then
begin
if SCM.scmConnection.Connected and actnConnect.Visible then
actnConnect.Visible := false;
if not SCM.scmConnection.Connected and not actnConnect.Visible then
actnConnect.Visible := true;
end
else // D E F A U L T I N I T . Data module not created.
begin
if not actnConnect.Visible then
actnConnect.Visible := true;
end;
end;
procedure TTimeKeeper.actnDisconnectExecute(Sender: TObject);
begin
// IF DATA-MODULE EXISTS ... break the current connection.
if Assigned(SCM) then
begin
SCM.DeActivateTable;
SCM.scmConnection.Connected := false;
lblStatusBar.Text := 'No connection.';
end;
AniIndicator1.Visible := false;
lblAniIndicatorStatus.Visible := false;
AniIndicator1.Enabled := false;
tabEventHeat.Text := 'Event-Heat';
tabEntrantRaceTime.Text := 'Entrant-RaceTime';
UpdateAction(actnDisconnect);
UpdateAction(actnConnect);
Update_Layout;
end;
procedure TTimeKeeper.actnDisconnectUpdate(Sender: TObject);
begin
// verbose code - stop unecessary repaints ...
if Assigned(SCM) then
begin
if SCM.scmConnection.Connected and not actnDisconnect.Visible then
actnDisconnect.Visible := true;
if not SCM.scmConnection.Connected and actnDisconnect.Visible then
actnDisconnect.Visible := false;
end
else // D E F A U L T I N I T . Data module not created.
begin
if actnDisconnect.Visible then
actnDisconnect.Visible := false;
end;
end;
procedure TTimeKeeper.actnPostTimeExecute(Sender: TObject);
begin
if (Assigned(SCM) and SCM.IsActive) then
begin
// Test if the heat is closed or raced or session is closed .
if ((SCM.qryHeat.FieldByName('HeatStatusID').AsInteger <> 1) or
(SCM.qrySession.FieldByName('SessionStatusID').AsInteger <> 1)) then
begin
{$IFDEF MSWINDOWS}
MessageBeep(MB_ICONERROR);
{$ENDIF}
lblStatusBar.Text :=
'Failed to PostTime because the session/heat is locked/closed.';
end
else
begin
PostRaceTime; // Extract TDateTime, post and display status message.
bsEntrant.DataSet.Refresh; // display changes in lblRaceTime.
end;
end
end;
procedure TTimeKeeper.actnPostTimeUpdate(Sender: TObject);
begin
// connected to SwimClubMeet
if (Assigned(SCM) and SCM.IsActive) then
begin
// is the heat open? Is the session unlocked?
if ((SCM.qryHeat.FieldByName('HeatStatusID').AsInteger = 1) and
(SCM.qrySession.FieldByName('SessionStatusID').AsInteger = 1)) then
// Is there a swimmer assigned to the lane?
begin
if (not SCM.qryEntrant.IsEmpty) then
btnBackSpace.Enabled := true
else
btnBackSpace.Enabled := false;
end
// session is locked or heat is raced or closed ...
else
btnBackSpace.Enabled := false;
end
// database isn't connected
else
btnBackSpace.Enabled := false;
end;
procedure TTimeKeeper.actnRefreshExecute(Sender: TObject);
var
EventID, HeatID: Integer;
begin
if (Assigned(SCM) and SCM.IsActive) then
begin
// disable listviews
SCM.qryEvent.DisableControls;
SCM.qryHeat.DisableControls;
// store the current database record identities
EventID := SCM.qryHeat.FieldByName('EventID').AsInteger;
HeatID := SCM.qryHeat.FieldByName('HeatID').AsInteger;
// run the queries
SCM.qryEvent.Refresh;
lblStatusBar.Text := 'SCM Refreshed.';
// restore database record indexes
SCM.LocateEventID(EventID);
SCM.LocateHeatID(HeatID);
// performs full ReQuery of lane table.
Refresh_Lane;
end;
SCM.qryEvent.EnableControls;
SCM.qryHeat.EnableControls;
end;
procedure TTimeKeeper.actnRefreshUpdate(Sender: TObject);
begin
if (Assigned(SCM) and SCM.IsActive) then
actnRefresh.Enabled := true
else
actnRefresh.Enabled := false;
end;
procedure TTimeKeeper.btnBackSpaceClick(Sender: TObject);
var
s: string;
begin
s := txtRaceTime.Text;
StripTimeChars(s);
Delete(s, Length(s), 1);
s := GetDisplayRaceTime(s);
txtRaceTime.Text := s;
end;
procedure TTimeKeeper.btnClearClick(Sender: TObject);
begin
txtRaceTime.Text := '';
end;
procedure TTimeKeeper.btnClearTimeClick(Sender: TObject);
begin
// Check for connection
if (Assigned(SCM) and SCM.IsActive) then
begin
if ((SCM.qryHeat.FieldByName('HeatStatusID').AsInteger <> 1) or
(SCM.qrySession.FieldByName('SessionStatusID').AsInteger <> 1)) then
begin
{$IFDEF MSWINDOWS}
MessageBeep(MB_ICONERROR);
{$ENDIF}
lblStatusBar.Text :=
'Failed to Clear Time because the session/heat is locked/closed.';
end
else
ClearRaceTime; // routine will post and display a status message
Refresh_Lane;
end
end;
procedure TTimeKeeper.btnGetTimeClick(Sender: TObject);
var
s: string;
begin
if bsLane.DataSet.FieldByName('MemberID').IsNull then
txtRaceTime.Text := ''
else
begin
s := bsEntrant.DataSet.FieldByName('RaceTimeStr').AsString;
s := GetRawRaceTime(s);
StripTimeChars(s);
s := GetDisplayRaceTime(s);
txtRaceTime.Text := s;
end;
end;
procedure TTimeKeeper.btnNumClick(Sender: TObject);
var
s: string;
begin
s := txtRaceTime.Text;
s := s + TButton(Sender).Text;
StripTimeChars(s);
TruncateTimeChars(s, ROUND(spinbNumOfDecimalPlaces.Value));
s := GetDisplayRaceTime(s);
txtRaceTime.Text := s;
end;
procedure TTimeKeeper.btnPointClick(Sender: TObject);
var
Key: Word;
KeyChar: Char;
ShiftState: TShiftState;
begin
Key := VK_DECIMAL;
KeyChar := '.';
if txtRaceTime.IsFocused then
KeyDown(Key, KeyChar, ShiftState);
end;
procedure TTimeKeeper.chkbSessionVisibilityChange(Sender: TObject);
begin
if (Assigned(SCM) and SCM.scmConnection.Connected) then
Update_SessionVisibility();
end;
procedure TTimeKeeper.ClearRaceTime;
begin
lblStatusBar.Text := '';
if not Assigned(SCM) then
exit;
if not SCM.IsActive then
exit;
// session cannot be locked.
if not(SCM.qrySession.FieldByName('SessionStatusID').AsInteger = 1) then
exit;
// only opened or raced heats can be cleared ...
if (SCM.qryHeat.FieldByName('HeatStatusID').AsInteger = 3) then
exit;
// Is there an ENTRANT.
if SCM.qryLane.FieldByName('MemberID').IsNull then
exit;
if not SCM.qryEntrant.FieldByName('EntrantID').IsNull then
begin
try
begin
SCM.qryEntrant.DisableControls;
SCM.qryEntrant.Edit;
SCM.qryEntrant.FieldByName('RaceTime').Clear;
SCM.qryEntrant.Post;
SCM.qryEntrant.EnableControls;
Refresh_Entrant;
{$IFDEF MSWINDOWS}
MessageBeep(MB_ICONINFORMATION);
{$ENDIF}
lblStatusBar.Text :=
'INFO: The RaceTime was successfully cleared.';
end
except
on E: Exception do
begin
// bad conversion
{$IFDEF MSWINDOWS}
MessageBeep(MB_ICONERROR);
{$ENDIF}
lblStatusBar.Text :=
'ERROR: Unable to clear time to the SCM database!'
end;
end;
end;
end;
procedure TTimeKeeper.cmbSessionListChange(Sender: TObject);
begin
if Assigned(SCM) and SCM.scmConnection.Connected then
begin
if SCM.IsActive then
begin
bsEvent.DataSet.First;
bsHeat.DataSet.First;
end;
Update_TabSheetCaptions;
lblStatusBar.Text := '';
end;
end;
procedure TTimeKeeper.cmbSwimClubListChange(Sender: TObject);
begin
if Assigned(SCM) and SCM.scmConnection.Connected then
begin
if SCM.IsActive then
begin
bsSession.DataSet.First;
bsEvent.DataSet.First;
bsHeat.DataSet.First;
end;
Update_TabSheetCaptions;
lblStatusBar.Text := '';
end;
end;
procedure TTimeKeeper.ConnectOnTerminate(Sender: TObject);
begin
lblAniIndicatorStatus.Visible := false;
AniIndicator1.Enabled := false;
AniIndicator1.Visible := false;
if TThread(Sender).FatalException <> nil then
begin
// something went wrong
// Exit;
end;
if not Assigned(SCM) then
exit;
// C O N N E C T E D .
if (SCM.scmConnection.Connected) then
begin
SCM.ActivateTable;
// ALL TABLES SUCCESSFULLY MADE ACTIVE ...
if (SCM.IsActive = true) then
begin
// Set the visibility of closed sessions.
Update_SessionVisibility;
// I N I T L A N E L I S T .
Refresh_Lane;
end;
Status_ConnectionDescription;
fNumOfLanes := bsSwimClub.DataSet.FieldByName('NumOfLanes').AsInteger;
if (fNumOfLanes > 0) then
spinboxLockToLane.Max := fNumOfLanes;
end;
// VERY SICK OF BIND COMPONETS BREAKING!
if Assigned(SCM) and SCM.IsActive then
begin
if not Assigned(bsSwimClub.DataSet) then
bsSwimClub.DataSet := SCM.tblSwimClub;
if not Assigned(bsSession.DataSet) then
bsSession.DataSet := SCM.qrySession;
if not Assigned(bsEvent.DataSet) then
bsEvent.DataSet := SCM.qryEvent;
if not Assigned(bsHeat.DataSet) then
bsHeat.DataSet := SCM.qryHeat;
if not Assigned(bsEntrant.DataSet) then
bsEntrant.DataSet := SCM.qryEntrant;
if not Assigned(bsLane.DataSet) then
bsLane.DataSet := SCM.qryLane;
end;
if not SCM.scmConnection.Connected then
begin
// Attempt to connect failed.
lblStatusBar.Text :=
'A connection couldn''t be made. (Check you input values.)';
end;
// Disconnect button vivibility
UpdateAction(actnDisconnect);
// Connect button vivibility
UpdateAction(actnConnect);
// Display of layout panels (holding TListView grids).
Update_Layout;
end;
procedure TTimeKeeper.edtRaceTimeEnter(Sender: TObject);
begin
// selectall behavious is different in FMX
// this works ...
TThread.CreateAnonymousThread(
procedure()
begin
TThread.Synchronize(nil,
procedure()
begin
// edtRaceTime.SelectAll();
end);
end).Start;
// THIS shows the OLD windows 10 virtual keyboard. NOT THE TOUCH KEYBOARD
// var
// sWindowsDir: string;
// sWindowsSysDir: string;
// {$IFDEF MSWINDOWS}
// sWindowsSysDir := GetEnvironmentVariable('SYSTEMROOT');
// ShellExecute(HWND(Handle), 'open', PChar(sWindowsSysDir + '\SysNative\OSK.EXE'), nil, nil, SW_Show);
// sWindowsDir := GetEnvironmentVariable('WINDIR');
// if FileExists(sWindowsSysDir + '\OSK.exe') then
// ShellExecute(HWND(Handle), 'open', PChar(sWindowsDir + '\SysNative\OSK.EXE'), nil, nil, SW_Show)
// else
// ShellExecute(HWND(Handle), 'open', PChar(sWindowsDir + '\SysNative\OSK.EXE'), nil, nil, SW_Show);
// end;
// {$ENDIF}
end;
procedure TTimeKeeper.edtRaceTimeKeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
// test for DONE.
// if edtRaceTime.ReturnKeyType = TReturnKeyType.Done then
// Post the time to the database.
// actnPostTimeExecute(self);
end;
end;
procedure TTimeKeeper.FormCreate(Sender: TObject);
begin
// Initialization of params.
application.ShowHint := true;
AniIndicator1.Visible := false;
AniIndicator1.Enabled := false;
btnDisconnect.Visible := false;
Timer1.Enabled := false;
lblAniIndicatorStatus.Visible := false;
cmbSessionList.Items.Clear;
cmbSwimClubList.Items.Clear;
chkbSessionVisibility.IsChecked := true;
fLoginTimeOut := CONNECTIONTIMEOUT;
fConnectionCountdown := fLoginTimeOut;
chkbLockToLane.IsChecked := false;
txtRaceTime.Text := '';
fNumOfLanes := 8;
// A Class that uses JSON to read and write application configuration
if Settings = nil then
Settings := TPrgSetting.Create;
// C R E A T E T H E D A T A M O D U L E .
if NOT Assigned(SCM) then
SCM := TSCM.Create(Self);
if SCM.scmConnection.Connected then
SCM.scmConnection.Connected := false;
// READ APPLICATION C O N F I G U R A T I O N PARAMS.
// JSON connection settings. Windows location :
// %SYSTEMDRIVE\%%USER%\%USERNAME%\AppData\Roaming\Artanemus\SwimClubMeet\TimeKeeper
LoadSettings;
// TAB_SHEET : DEFAULT: Login-Session
TabControl1.TabIndex := 0;
Update_Layout;
// Connection status - located in footer bar.
lblStatusBar.Text := 'NOT CONNECTED';
end;
procedure TTimeKeeper.FormDestroy(Sender: TObject);
begin
if Assigned(SCM) then
begin
if SCM.scmConnection.Connected then
begin
SaveToSettings;
SCM.scmConnection.Connected := false;
end;
SCM.Free;
end;
end;
procedure TTimeKeeper.FormKeyDown(Sender: TObject; var Key: Word;
var KeyChar: WideChar; Shift: TShiftState);
var
s, keytxt: string;
begin
if (TabControl1.TabIndex = 2) then
begin
if KeyChar IN ['0','1','2','3','4','5','6','7','8','9'] then
// if Key in [vkNumpad0, vkNumpad1, vkNumpad2, vkNumpad3, vkNumpad4, vkNumpad5,
// vkNumpad6, vkNumpad7, vkNumpad8, vkNumpad9,
// vk0, vk1, vk2, vk3, vk4, vk5, vk6, vk7, vk8, vk9] then
begin
s := txtRaceTime.Text;
// convert the Key value to char 1, 2, 3, 4, 5, 6,7 , 8, 9, 0
// if Key in [vkNumpad0, vkNumpad1, vkNumpad2, vkNumpad3, vkNumpad4, vkNumpad5,
// vkNumpad6, vkNumpad7, vkNumpad8, vkNumpad9] then
// keytxt := Chr(Key - vkNumpad0 + Ord('0'))
// else
// keytxt := Chr(Key - vk0 + Ord('0'));
s := s + keychar;
StripTimeChars(s);
TruncateTimeChars(s, ROUND(spinbNumOfDecimalPlaces.Value));
s := GetDisplayRaceTime(s);
txtRaceTime.Text := s;
Key := 0;
end;
if (KeyChar = 'C') or (KeyChar = 'c') then
begin
txtRaceTime.Text := '';
Key := 0;
end;
if (Key = vkBack) or (KeyChar = char(8)) then
begin
btnBackSpaceClick(Sender);
// s := txtRaceTime.Text;
// StripTimeChars(s);
// Delete(s, Length(s), 1);
// s := GetDisplayRaceTime(s);
// txtRaceTime.Text := s;
end;
end;
end;
function TTimeKeeper.GetDisplayRaceTime(aRawString: string): string;
var
nodp: Integer; // Number of decimal places.
len, i: Integer; // length of raw string.
hours, minutes, seconds, hundredths: string;
function FormatTime(h, m, s, hund: string): string;
begin
if hund <> '' then
hund := '.' + hund;
if h = '' then
begin
if m = '' then
result := Format('%s%s', [s, hund])
else
result := Format('%s:%s%s', [m, s, hund]);
end
else
result := Format('%s:%s:%s%s', [h, m, s, hund]);
end;
begin
if aRawString = '' then
exit('');
nodp := Round(spinbNumOfDecimalPlaces.Value);
len := Length(aRawString);
if nodp > 0 then
begin
if len > nodp then
hundredths := Copy(aRawString, len - nodp + 1, nodp)
else
exit('.' + Copy(aRawString, 1, len));
end
else
hundredths := '';
i := len - nodp;
if i in [1, 2] then
begin
seconds := Copy(aRawString, 1, i);
exit(FormatTime('', '', seconds, hundredths));
end
else
seconds := Copy(aRawString, len - nodp - 1, 2);
i := len - nodp - 2;
if i in [1, 2] then
begin
minutes := Copy(aRawString, 1, i);
exit(FormatTime('', minutes, seconds, hundredths));
end
else
minutes := Copy(aRawString, len - nodp - 3, 2);
i := len - nodp - 4;
if i in [1, 2] then
begin
hours := Copy(aRawString, 1, i);
exit(FormatTime(hours, minutes, seconds, hundredths));
end;
result := FormatTime('', minutes, seconds, hundredths);
end;
function TTimeKeeper.GetRawRaceTime(RaceTimeStr: string): string;
var
s: string;
nodp: Integer;
begin
// takes RaceTimeStr given by dbo.Entrant and strips down
// to raw numbers.
s := RaceTimeStr;
// three decimal places are used in the RaceTimeStr string
nodp := Round(spinbNumOfDecimalPlaces.Value);
if nodp = 0 then
Delete(s, Length(s) - 2, 3); // remove all decimal place chars.
if nodp = 1 then
Delete(s, Length(s) - 1, 2); // last two chars'
if nodp = 2 then
Delete(s, Length(s), 1); // single character.
result := s;
end;
function TTimeKeeper.GetSCMVerInfo(): string;
{$IF defined(MSWINDOWS)}
var
myExeInfo: TExeInfo;
{$ENDIF}
begin
result := '';
// if connected - display the application version
// and the SwimClubMeet database version.
if Assigned(SCM) then
if SCM.scmConnection.Connected then
result := 'DB v' + SCM.GetDBVerInfo;
{$IF defined(MSWINDOWS)}
// get the application version number
myExeInfo := TExeInfo.Create(Self);
result := 'App v' + myExeInfo.FileVersion + ' - ' + result;
myExeInfo.Free;
{$ENDIF}
end;
procedure TTimeKeeper.ListViewEventChange(Sender: TObject);
begin
Update_TabSheetCaptions;
Status_EventDescription;
end;
procedure TTimeKeeper.ListViewHeatChange(Sender: TObject);
begin
Update_TabSheetCaptions;
Status_EventDescription;
end;
procedure TTimeKeeper.ListViewLaneChange(Sender: TObject);
begin
Update_EntrantStat; // Empty lanes don't show entrant stats.
// S T A T U S L I N E E V E N T D E S C R I P T I O N .
// Distance Stroke, NOM and ENT count ....
lblStatusBar.Text := bsEvent.DataSet.FieldByName
('ListDetailStr').AsString;
// setting focus onto tab enables form KeyDown ro function....
SetFocused(tabEntrantRaceTime);
end;
procedure TTimeKeeper.LoadFromSettings;
begin
edtServerName.Text := Settings.Server;
edtUser.Text := Settings.User;
edtPassword.Text := Settings.Password;
chkbUseOsAuthentication.IsChecked := Settings.OSAuthent;
chkbSessionVisibility.IsChecked := Settings.SessionVisibility;
chkbLockToLane.IsChecked := Settings.LockToLane;
fLoginTimeOut := Settings.LoginTimeOut;
spinboxLockToLane.Value := Settings.LockToLaneNumber;
end;
procedure TTimeKeeper.LoadSettings;
begin
if Settings = nil then
Settings := TPrgSetting.Create;
if not FileExists(Settings.GetDefaultSettingsFilename()) then
begin
ForceDirectories(Settings.GetSettingsFolder());
Settings.SaveToFile();
end;
Settings.LoadFromFile();
LoadFromSettings();
end;
procedure TTimeKeeper.PostRaceTime;
var
s, s1, s2: String;
i, pos, len: Integer;
dt: TDateTime;
Hour, Min, Sec, MSec: Word;
begin
lblStatusBar.Text := '';
if Assigned(SCM) and SCM.IsActive then
begin
// only opened heats can be cleared ...
if ((SCM.qryHeat.FieldByName('HeatStatusID').AsInteger = 1) and
(SCM.qrySession.FieldByName('SessionStatusID').AsInteger = 1)) then
begin
// Are there ENTRANTS?
if (not SCM.qryEntrant.IsEmpty) then
begin
// init PARAMS
Hour := 0;
Min := 0;
Sec := 0;
MSec := 0;
s1 := '';
s2 := 'ERROR: Invalid RaceTime. Please check input.';
// USER INPUT DATA
s := txtRaceTime.Text;
// strip unwanted characters.
// String[] index is base one .... IsDigit is base one.
i := 1;
while i <= s.Length do
begin
if s[i].IsDigit or (s[i] = '.') then
s1 := s1 + s[i];
inc(i);
end;
// if we find valid numerical data - next we extract character
// by character each part - working backwards along the string.
if (not s1.IsEmpty) then
begin
// is there a decimal point
// Delphi IndexOf is base zero - returns -1 if not found.
pos := s1.IndexOf('.');
if (pos <> -1) then
begin
// found decimal point
// grab everything prior to the decimal point
// substring index is base zero
len := String(s1.SubString(0, pos)).Length;
if (len > 0) then
Sec := Word(StrToInt(s1.SubString(pos - 1, 1)));
if (len > 1) then
Sec := Sec + Word(StrToInt(s1.SubString(pos - 2, 1)) * 10);
if (len > 2) then
Min := Word(StrToInt(s1.SubString(pos - 3, 1)));
if (len > 3) then
Min := Min + Word(StrToInt(s1.SubString(pos - 4, 1)) * 10);
// grab everything after the decimal point
len := s1.Length - (pos + 1);
if (len > 0) then
MSec := Word(StrToInt(s1.SubString(pos + 1, 1)) * 100);
if (len > 1) then
MSec := MSec + Word(StrToInt(s1.SubString(pos + 2, 1)) * 10);
if (len > 2) then
MSec := MSec + Word(StrToInt(s1.SubString(pos + 3, 1)) * 1);
end
else
begin
// no decimal point
len := s1.Length;
if (len > 0) then
Sec := Word(StrToInt(s1.SubString(len - 1, 1)));
if (len > 1) then
Sec := Sec + Word(StrToInt(s1.SubString(len - 2, 1)) * 10);
if (len > 2) then
Min := Word(StrToInt(s1.SubString(len - 3, 1)));
if (len > 3) then