-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlgCloneSession.pas
159 lines (141 loc) · 4.19 KB
/
dlgCloneSession.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
unit dlgCloneSession;
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.ExtCtrls, dmSCM,
Vcl.VirtualImage, Vcl.BaseImageCollection, Vcl.ImageCollection;
type
TCloneSession = class(TForm)
qrySrcEvent: TFDQuery;
tblSession: TFDTable;
tblEvent: TFDTable;
lblDescription: TLabel;
pnlFooter: TPanel;
btnClone: TButton;
btnCancel: TButton;
vimgClone: TVirtualImage;
imgcolClone: TImageCollection;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure btnCancelClick(Sender: TObject);
procedure btnCloneClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
function CloneExecute: boolean;
public
{ Public declarations }
end;
//var
// CloneSession: TCloneSession;
implementation
{$R *.dfm}
procedure TCloneSession.btnCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TCloneSession.btnCloneClick(Sender: TObject);
begin
if CloneExecute then
ModalResult := mrOk
else
begin
ModalResult := mrCancel;
end;
end;
function TCloneSession.CloneExecute: boolean;
var
i: integer;
begin
result := false;
i := 1;
// Session must no be empty
if not Assigned(SCM) then
exit;
if SCM.dsSession.DataSet.IsEmpty then
exit;
qrySrcEvent.Connection := SCM.scmConnection;
qrySrcEvent.ParamByName('SESSIONID').AsInteger := SCM.Session_ID;
qrySrcEvent.Prepare;
qrySrcEvent.Open;
if not qrySrcEvent.Active then
exit;
if qrySrcEvent.IsEmpty then
exit;
// create the clone session.
// ------------------------------
try
tblSession.Insert;
tblSession.FieldByName('SessionStart').AsDateTime := Now();
tblSession.FieldByName('SwimClubID').AsInteger :=
SCM.dsSession.DataSet.FieldByName('SwimClubID').AsInteger;
tblSession.FieldByName('SessionStatusID').AsInteger := 1;
tblSession.FieldByName('Caption').AsString := 'CLONE OF: ' +
SCM.dsSession.DataSet.FieldByName('Caption').AsString;
tblSession.Post;
except
on E: Exception do
exit;
end;
// create cloned events
// ------------------------------
qrySrcEvent.First;
while not qrySrcEvent.Eof do
begin
tblEvent.Insert();
// Assert event numbering
tblEvent.FieldByName('EventNum').AsInteger := i;
tblEvent.FieldByName('Caption').AsString :=
qrySrcEvent.FieldByName('Caption').AsString;;
// Stroke
tblEvent.FieldByName('StrokeID').AsInteger :=
qrySrcEvent.FieldByName('StrokeID').AsInteger;
// Distance
tblEvent.FieldByName('DistanceID').AsInteger :=
qrySrcEvent.FieldByName('DistanceID').AsInteger;
// Assign new inserted session ...
tblEvent.FieldByName('SessionID').AsInteger :=
tblSession.FieldByName('SessionID').AsInteger;
// Status = open
tblEvent.FieldByName('EventStatusID').AsInteger := 1;
// Schedule TTime for the event...
tblEvent.FieldByName('ScheduleDT').AsDateTime :=
qrySrcEvent.FieldByName('ScheduleDT').AsDateTime;
// RallyOpenDT .. RallyCloseDT .. OpenDT .. CloseDT
tblEvent.Post();
i := i + 1;
qrySrcEvent.Next;
end;
qrySrcEvent.Close();
result := true;
end;
procedure TCloneSession.FormCreate(Sender: TObject);
begin
if not Assigned(SCM) then
raise Exception.Create('SCM data module not assigned.');
tblSession.Connection := SCM.scmConnection;
tblEvent.Connection := SCM.scmConnection;
tblEvent.Open;
tblSession.Open;
if not(tblEvent.Active and tblSession.Active) then
raise Exception.Create('SCM error activating tables.');
end;
procedure TCloneSession.FormDestroy(Sender: TObject);
begin
tblSession.Close();
tblEvent.Close();
end;
procedure TCloneSession.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
begin
Key := 0;
ModalResult := mrCancel;
end;
end;
end.