-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlgSwapLanes.pas
226 lines (208 loc) · 6.17 KB
/
dlgSwapLanes.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
unit dlgSwapLanes;
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, FireDAC.Comp.Client,
Data.DB, FireDAC.Comp.DataSet, Vcl.StdCtrls, Vcl.DBCtrls, Vcl.ExtCtrls, dmSCM;
type
TSwapLanes = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Shape1: TShape;
DBText1: TDBText;
DBText2: TDBText;
DBText3: TDBText;
DBText4: TDBText;
DBText5: TDBText;
DBText6: TDBText;
DBText7: TDBText;
DBText8: TDBText;
DBNavigator1: TDBNavigator;
DBNavigator2: TDBNavigator;
DBNavigator3: TDBNavigator;
DBNavigator4: TDBNavigator;
Panel2: TPanel;
btnCancel: TButton;
btnSwapLanes: TButton;
tblEntrantA: TFDTable;
tblEntrantB: TFDTable;
tblHeatA: TFDTable;
tblHeatB: TFDTable;
tblEvent: TFDTable;
dsHeatA: TDataSource;
dsEvent: TDataSource;
dsHeatB: TDataSource;
dsEntrantB: TDataSource;
dsEntrantA: TDataSource;
tblFNameB: TFDTable;
tblFNameA: TFDTable;
dsFNameA: TDataSource;
dsFNameB: TDataSource;
procedure btnSwapLanesClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure btnCancelClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SwapLanes: TSwapLanes;
implementation
{$R *.dfm}
{ TSwapLanes }
procedure TSwapLanes.btnCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TSwapLanes.btnSwapLanesClick(Sender: TObject);
begin
SCM.Entrant_SwapLanes(tblEntrantA.FieldByName('EntrantID').AsInteger,
tblEntrantB.FieldByName('EntrantID').AsInteger);
ModalResult := mrOk;
end;
procedure TSwapLanes.FormCreate(Sender: TObject);
var
Opts: TLocateOptions;
i: integer;
fEventID: integer;
begin
if Assigned(SCM) then
begin
// As SCM is a TEMPORY connection - ASSERT assignment for FireDAC.
tblEvent.Connection := SCM.scmConnection;
tblFNameA.Connection := SCM.scmConnection;
tblFNameB.Connection := SCM.scmConnection;
tblHeatA.Connection := SCM.scmConnection;
tblHeatB.Connection := SCM.scmConnection;
tblEntrantA.Connection := SCM.scmConnection;
tblEntrantB.Connection := SCM.scmConnection;
// enable all datasets
tblEvent.Open;
tblHeatA.Open;
tblHeatB.Open;
tblEntrantA.Open;
tblEntrantB.Open;
tblFNameA.Open;
tblFNameB.Open;
// source eventID
fEventID := SCM.dsEvent.DataSet.FieldByName('EventID').AsInteger;
dsEvent.DataSet.Filter := '[EventID] = ' + IntToStr(fEventID);
// Master Source - init ...
if not dsEvent.DataSet.Filtered then
dsEvent.DataSet.Filtered := true;
// assign the current selected heatNum
i := SCM.dsHeat.DataSet.FieldByName('HeatID').AsInteger;
dsHeatA.DataSet.Locate('HeatID', i, Opts);
dsHeatB.DataSet.Locate('HeatID', i, Opts);
// assign the current select entrant (lane)
i := SCM.dsEntrant.DataSet.FieldByName('EntrantID').AsInteger;
dsEntrantA.DataSet.Locate('EntrantID', i, Opts);
dsEntrantB.DataSet.Locate('EntrantID', i, Opts);
end;
end;
procedure TSwapLanes.FormDestroy(Sender: TObject);
begin
tblEvent.Close;
tblHeatA.Close;
tblHeatB.Close;
tblEntrantA.Close;
tblEntrantB.Close;
tblFNameA.Close;
tblFNameB.Close;
end;
procedure TSwapLanes.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_ESCAPE) then
ModalResult := mrCancel;
end;
{$REGION 'DEPRECIATED CODE - USE FUNCTION IN SCM'}
(*
function TSwapLanes.SwapAcrossHeats_MoveDown(var AHeatID: integer;
var AEntrantID: integer): boolean;
var
Opts: TLocateOptions;
i: integer;
success: boolean;
begin
result := false;
AHeatID := 0;
AEntrantID := 0;
// Get the destination heat number. (current heat number + 1)
i := SCM.dsHeat.DataSet.FieldByName('HeatNum').AsInteger + 1;
// check : within range. Is it a valid heat number?
if (i <= SCM.dsHeat.DataSet.RecordCount) then
begin
// locate that destination heat
success := dsHeatB.DataSet.Locate('HeatNum', i, Opts);
if (success) then
begin
// it this heat closed? (LOCKED)
if not SCM.IsClosedHeat(dsHeatB.DataSet.FieldByName('HeatID').AsInteger)
then
begin
// Locate the entrant record for the first lane of the destination heat.
success := dsEntrantB.DataSet.Locate('Lane', 1, Opts);
if (success) then
begin
// do the swap ....
SCM.SwapLanes(tblEntrantA.FieldByName('EntrantID').AsInteger,
tblEntrantB.FieldByName('EntrantID').AsInteger);
// return info on the destination heat\entrant
AHeatID := dsHeatB.DataSet.FieldByName('HeatID').AsInteger;
AEntrantID := dsEntrantB.DataSet.FieldByName('EntrantID').AsInteger;
result := true;
end;
end;
end;
end;
end;
function TSwapLanes.SwapAcrossHeats_MoveUp(AHeatID,
AEntrantID: integer): boolean;
var
Opts: TLocateOptions;
i: integer;
success: boolean;
begin
aHeatID := NULL;
aEntrantID := NULL;
result := false;
// Construction has done all initialisation of SOURCE
// Prepare DESTINATION
// get the destination heat number - subtract 1 from current
i := SCM.dsHeat.DataSet.FieldByName('HeatNum').AsInteger - 1;
success := false;
// check range
if (i > 0) then begin
// locate that destination heat
success := dsHeatB.DataSet.Locate('HeatNum',i, Opts);
if (success) then begin
if not SCM.IsClosedHeat(dsHeatB.DataSet.FieldByName('HeatID') .AsInteger) then
begin
i := SCM.dsSwimClub.DataSet.FieldByName('NumOfLanes') .AsInteger;
// Locate the last lane in that destination heat
dsEntrantB.DataSet.Locate('Lane',i, Opts);
if (success) then
begin
// perform the swap ....
btnSwapLanesClick(self);
// last step - update form
aHeatID := dsHeatB.DataSet.FieldByName('HeatID').AsInteger;
aEntrantID := dsEntrantB.DataSet.FieldByName('EntrantID').AsInteger;
end;
end;
end;
end;
end;
*)
{$ENDREGION}
end.