-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmMain.pas
503 lines (456 loc) · 14.8 KB
/
frmMain.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
unit frmMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, dmSCM, Vcl.StdCtrls, Vcl.DBCtrls,
Vcl.ExtCtrls, Vcl.VirtualImage, Vcl.BaseImageCollection, Vcl.ImageCollection,
Vcl.Buttons, System.ImageList, Vcl.ImgList, Vcl.VirtualImageList, dmRPTS,
Vcl.Themes, Vcl.ComCtrls;
type
TMain = class(TForm)
Panel1: TPanel;
DBtxtSwimClubCaption: TDBText;
DBtxtSwimClubNickName: TDBText;
DBtxtStartOfSwimSeason: TDBText;
ImageCollection1: TImageCollection;
VirtualImage1: TVirtualImage;
VirtualImageList1: TVirtualImageList;
spbRefresh: TSpeedButton;
Panel2: TPanel;
lblMembershipcardHeader: TLabel;
Label2: TLabel;
btnDesignMembershipCard: TButton;
btnDesignPodium: TButton;
lblMembershipCardDetail: TLabel;
Panel3: TPanel;
Panel4: TPanel;
Label1: TLabel;
btnMembershipCards: TButton;
Panel9: TPanel;
Button6: TButton;
ProgressBar1: TProgressBar;
sbtnInfo: TSpeedButton;
sbtnOptions: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnMembershipCardsClick(Sender: TObject);
procedure btnDesignMembershipCardClick(Sender: TObject);
procedure btnPodiumCertificatesClick(Sender: TObject);
procedure btnDesignPodiumClick(Sender: TObject);
procedure sbtnInfoClick(Sender: TObject);
procedure sbtnOptionsClick(Sender: TObject);
private
{ Private declarations }
fSwimClubID, fMaxAllowToPick: integer;
fdefaultStyleName, fCustRptMemShip: string;
fCustRptCertifGOLD, fCustRptCertifSILVER, fCustRptCertifBRONZE: string;
// inifiles section name
fSectionName: string;
// P R E F E R E N C E F I L E A C C E S S .
procedure ReadPreferences(iniFileName: string);
public
{ Public declarations }
end;
var
Main: TMain;
implementation
{$R *.dfm}
uses dlgBasicLogin, exeinfo, SCMUtility, dlgAbout, System.IniFiles, System.UITypes,
System.DateUtils, FireDAC.Stan.Param, dlgMembership, dlgPickMember,
dlgPickCertif, System.Contnrs, dlgDesignCertif, dlgPref;
procedure TMain.btnDesignMembershipCardClick(Sender: TObject);
//var
// iniFileName: string;
// iFile: TIniFile;
begin
if Assigned(RPTS) then
begin
// set style to default - designer looks better.
if Assigned(TStyleManager.ActiveStyle) and
(TStyleManager.ActiveStyle.Name <> 'Windows') then
begin
TStyleManager.TrySetStyle('Windows');
end;
RPTS.frxRptMembership.DesignReport(True);
// restore application
if Assigned(TStyleManager.ActiveStyle) then
TStyleManager.TrySetStyle(fdefaultStyleName);
// update customisation filename...
fCustRptMemShip := LoadSharedIniFileSetting(fSectionName, 'CustRptMemShip');
// iniFileName := GetSCMPreferenceFileName;
// if FileExists(iniFileName) then
// begin
// iFile := TIniFile.create(iniFileName);
// fCustRptMemShip := iFile.ReadString(IniSectionName, 'CustRptMemShip', '');
// iFile.free;
// end;
end;
end;
procedure TMain.FormCreate(Sender: TObject);
var
aBasicLogin: TBasicLogin;
result: TmodalResult;
iniFileName: string;
begin
// ----------------------------------------------------
// C R E A T E D A T A M O D U L E S C M .
// ----------------------------------------------------
try
SCM := TSCM.create(Self);
finally
// with SCM created and the essential tables are open then
// asserting the connection should be true
if not Assigned(SCM) then
begin
MessageDlg('The SCM connection couldn''t be created!', mtError,
[mbOk], 0);
Application.Terminate;
end;
end;
if not Assigned(SCM) then
Exit;
// ----------------------------------------------------
// C O N N E C T T O S E R V E R .
// ----------------------------------------------------
aBasicLogin := TBasicLogin.create(Self);
aBasicLogin.DBName := 'SwimClubMeet';
aBasicLogin.DBConnection := SCM.scmConnection;
result := aBasicLogin.ShowModal;
aBasicLogin.free;
if (result = mrAbort) or (result = mrCancel) then
begin
Application.Terminate;
Exit;
end;
// ----------------------------------------------------
// C R E A T E D A T A M O D U L E R P T S .
// ----------------------------------------------------
try
RPTS := TRPTS.create(Self);
finally
// with SCM created and the essential tables are open then
// asserting the connection should be true
if not Assigned(RPTS) then
begin
MessageDlg('The report module couldn''t be created!', mtError,
[mbOk], 0);
Application.Terminate;
end;
end;
if not Assigned(RPTS) then
Exit;
// ----------------------------------------------------
// A C T I V A T E S C M .
// ----------------------------------------------------
SCM.ActivateTable();
// A S S E R T .
if not SCM.IsActive then
begin
MessageDlg('An error occurred during MSSQL table activation.' + sLineBreak +
'The database''s schema may need updating.' + sLineBreak +
'The application will terminate!', mtError, [mbOk], 0);
// note: cleans and destroys SCM
Application.Terminate;
end;
// ----------------------------------------------------
// A C T I V A T E R P T S .
// ----------------------------------------------------
{TODO -oBSA -cGeneral : Create RPTS activation routine}
RPTS.qrySharedHeader.Connection := SCM.scmConnection;
RPTS.qryMember.Connection := SCM.scmConnection;
// ----------------------------------------------------
// I N I T I A L I Z E P A R A M S .
// ----------------------------------------------------
Application.ShowHint := True; // enable hints
fSwimClubID := 1;
fMaxAllowToPick := 20;
fCustRptMemShip := '';
fCustRptCertifGOLD := '';
fCustRptCertifSILVER := '';
fCustRptCertifBRONZE := '';
fSectionName := 'MoreReports';
// ----------------------------------------------------
// R E A D P R E F E R E N C E S .
// ----------------------------------------------------
iniFileName := GetSCMPreferenceFileName;
if FileExists(iniFileName) then
begin
ReadPreferences(iniFileName);
end;
// ----------------------------------------------------
// D I S P L A Y H E A D E R I N F O .
// ----------------------------------------------------
if fSwimClubID <> 0 then
begin
SCM.qryLBHeader.Connection := SCM.scmConnection;
SCM.qryLBHeader.ParamByName('SWIMCLUBID').AsInteger := fSwimClubID;
SCM.qryLBHeader.Prepare;
SCM.qryLBHeader.Open;
end;
if SCM.qryLBHeader.Active then
begin
DBtxtSwimClubCaption.DataSource := SCM.dsLBHeader;
DBtxtSwimClubNickName.DataSource := SCM.dsLBHeader;
DBtxtStartOfSwimSeason.DataSource := SCM.dsLBHeader;
end;
Application.ShowHint := True;
// store the current theme
if Assigned(TStyleManager.ActiveStyle) then
fdefaultStyleName := TStyleManager.ActiveStyle.Name;
end;
procedure TMain.FormDestroy(Sender: TObject);
begin
// de-activate RPTS (FastReport)
if Assigned(RPTS) then
begin
FreeAndNil(RPTS);
end;
// de-activete SCM DataModule
if Assigned(SCM) then
begin
SCM.scmConnection.Close;
FreeAndNil(SCM);
end;
end;
procedure TMain.ReadPreferences(iniFileName: string);
var
iFile: TIniFile;
begin
iFile := TIniFile.create(iniFileName);
fMaxAllowToPick := iFile.ReadInteger(fSectionName, 'MaxAllowToPick', 20);
fCustRptCertifGOLD := iFile.ReadString(fSectionName,
'CustRptCertifGOLD', '');
fCustRptCertifSILVER := iFile.ReadString(fSectionName,
'CustRptCertifSILVER', '');
fCustRptCertifBRONZE := iFile.ReadString(fSectionName,
'CustRptCertifBRONZE', '');
fCustRptMemShip := iFile.ReadString(fSectionName, 'CustRptMemShip', '');
iFile.free;
// ----------------------------------------------------
// Load customized report
// if the FileName is empty, then the default report design is used.
// ----------------------------------------------------
if Assigned(RPTS) then
begin
if Length(fCustRptMemShip) > 0 then
BEGIN
if FileExists(fCustRptMemShip) then
RPTS.frxRptMembership.LoadFromFile(fCustRptMemShip);
END;
if Length(fCustRptCertifGOLD) > 0 then
begin
if FileExists(fCustRptCertifGOLD) then
RPTS.frxRptGold.LoadFromFile(fCustRptCertifGOLD);
end;
if Length(fCustRptCertifSILVER) > 0 then
begin
if FileExists(fCustRptCertifSILVER) then
RPTS.frxRptSilver.LoadFromFile(fCustRptCertifSILVER);
end;
if Length(fCustRptCertifBRONZE) > 0 then
begin
if FileExists(fCustRptCertifBRONZE) then
RPTS.frxRptBronze.LoadFromFile(fCustRptCertifBRONZE);
end;
end;
end;
procedure TMain.sbtnInfoClick(Sender: TObject);
var
dlg: TAbout;
begin
dlg := TAbout.create(Self);
dlg.DBName := 'SwimClubMeet';
if Assigned(SCM) then
dlg.DBConnection := SCM.scmConnection;
dlg.ShowModal;
dlg.free;
end;
procedure TMain.sbtnOptionsClick(Sender: TObject);
var
dlg: TPref;
iniFileName: string;
begin
dlg := TPref.create(Self);
dlg.ShowModal;
dlg.free;
// ----------------------------------------------------
// R E - R E A D P R E F E R E N C E S .
// ----------------------------------------------------
iniFileName := GetSCMPreferenceFileName;
if FileExists(iniFileName) then
begin
ReadPreferences(iniFileName);
end;
end;
procedure TMain.btnPodiumCertificatesClick(Sender: TObject);
var
dlg: TPickCertif;
dlg2: TDesignCertif;
SessionID: integer;
begin
if not Assigned(SCM) then
Exit;
if not Assigned(RPTS) then
Exit;
dlg := TPickCertif.create(Self);
if IsPositiveResult(dlg.ShowModal) then
begin
SessionID := dlg.GetCurrSessionID;
if SessionID = 0 then
Exit;
// prepare and open gold, silver, bronze podium queries
RPTS.PreparePodium(SessionID);
// Assign Filters
RPTS.qryPodiumGold.Filter := dlg.GetGoldFilterStr;
RPTS.qryPodiumSilver.Filter := dlg.GetSilverFilterStr;
RPTS.qryPodiumBronze.Filter := dlg.GetBronzeFilterStr;
// Asset - enable filters
if not RPTS.qryPodiumGold.Filtered then
RPTS.qryPodiumGold.Filtered := True;
if not RPTS.qryPodiumSilver.Filtered then
RPTS.qryPodiumSilver.Filtered := True;
if not RPTS.qryPodiumBronze.Filtered then
RPTS.qryPodiumBronze.Filtered := True;
// Fianlly - prepare report ...
RPTS.frxRptGold.PrepareReport();
RPTS.frxRptSilver.PrepareReport();
RPTS.frxRptBronze.PrepareReport();
// finished with dialogue - dispose off
FreeAndNil(dlg);
// display dialogue to preview, print, export
dlg2 := TDesignCertif.create(Self);
dlg2.ShowModal;
dlg2.free;
end;
if Assigned(dlg) then
dlg.free;
end;
procedure TMain.btnDesignPodiumClick(Sender: TObject);
var
dlg: TDesignCertif;
begin
if Assigned(RPTS) then
begin
dlg := TDesignCertif.create(Self);
dlg.doPodiumDesign := True;
if Assigned(SCM) then
// Finds a session with 1st,2nd,3rd place holders...
// so FastReport preview has some data to display.
dlg.SessionID := SCM.GetSampleSessionID;
// prepare and open gold, silver, bronze podium queries
RPTS.PreparePodium(dlg.SessionID);
dlg.ShowModal;
dlg.free;
end;
end;
procedure TMain.btnMembershipCardsClick(Sender: TObject);
var
dlg: TMembership;
dlgMP: TPickMember;
TagNum, I, J: integer;
doGenerate, doPrefix: Boolean;
filterStr, s: string;
obj: TscmMember;
begin
if (not Assigned(SCM)) or (not Assigned(RPTS)) then
Exit;
dlg := TMembership.create(Self);
if IsPositiveResult(dlg.ShowModal) then
begin
TagNum := dlg.TagNum;
doGenerate := dlg.chkboxGenerateNum.Checked;
if doGenerate then
begin
SCM.GenerateMembershipNums(fSwimClubID);
end;
case TagNum of
1:
begin
// WITHIN A DATE RANGE ...
// -----------------------------------
if (RPTS.qryMember.Filtered) then
RPTS.qryMember.Filtered := false;
RPTS.PrepareMembership(dlg.calDateFrom.Date,
dlg.calDateTo.Date, True);
FreeAndNil(dlg);
RPTS.frxRptMembership.PrepareReport();
RPTS.frxRptMembership.ShowReport();
end;
2:
begin
// USER PICKS MEMBERS FROM LIST ...
// -----------------------------------
FreeAndNil(dlg); // finished with dlg.
// create the quick pick dlg ...
dlgMP := TPickMember.create(Self);
if IsPositiveResult(dlgMP.ShowModal) then
begin
// prepare - all swimmers
RPTS.PrepareMembership(0, 0, false);
// build a members' list for filtering.
filterStr := '';
doPrefix := false;
J := 0;
// limit to 20xCards (2xA4 pages)
// --------------------------------
if dlgMP.lboxR.count > fMaxAllowToPick then
begin
MessageDlg('You have exceeded the allowed amount of members!' +
sLineBreak + 'Only the first ' + IntToStr(fMaxAllowToPick) +
' will appear in the report.' + sLineBreak +
'(This limit can be changed in the config file.)',
TMsgDlgType.mtWarning, [mbOk], 0);
end;
for I := 0 to dlgMP.lboxR.count - 1 do
begin
s := 'MemberID = ';
obj := dlgMP.lboxR.Items.Objects[I] as TscmMember;
s := s + IntToStr(obj.ID);
// first iteration doesn't require prefix
if doPrefix then
filterStr := filterStr + ' OR ' + s
else
filterStr := filterStr + s;
doPrefix := True;
J := J + 1;
if J > fMaxAllowToPick then
break;
end;
if (Length(filterStr) > 0) then
begin
try
RPTS.qryMember.Filter := filterStr;
RPTS.qryMember.Filtered := True;
RPTS.frxRptMembership.PrepareReport();
RPTS.frxRptMembership.ShowReport();
finally
// disable filtering on query
if (RPTS.qryMember.Filtered) then
RPTS.qryMember.Filtered := false;
RPTS.qryMember.Filter := '';
end;
end;
end;
FreeAndNil(dlgMP); // finished with quick pick dlg.
end;
3:
begin
// ALL ACTIVE SWIMMERS ...
// -----------------------------------
if (RPTS.qryMember.Filtered) then
RPTS.qryMember.Filtered := false;
FreeAndNil(dlg); // finished with dlg
RPTS.PrepareMembership(0, 0, false);
RPTS.frxRptMembership.PrepareReport();
// no PREVIEW assignment needed ...
RPTS.frxRptMembership.ShowReport();
end;
else
// do nothing
end;
end;
if Assigned(dlg) then
dlg.free;
end;
end.