-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu_Objectives.pas
383 lines (316 loc) · 8.92 KB
/
u_Objectives.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
unit u_Objectives;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.WinXCtrls,
Vcl.Imaging.pngimage, Vcl.StdCtrls, Vcl.Buttons, u_ObjectiveO;
type
TfrmObjectives = class(TForm)
svSide: TSplitView;
rpHold: TRelativePanel;
imgMenu: TImage;
gpTop: TGridPanel;
gpBottom: TGridPanel;
pnl1: TPanel;
pnl2: TPanel;
pnl3: TPanel;
pnl4: TPanel;
pnl5: TPanel;
pnl6: TPanel;
pnl7: TPanel;
pnl8: TPanel;
imgView1: TImage;
imgView2: TImage;
imgView4: TImage;
imgView5: TImage;
imgView6: TImage;
imgView7: TImage;
imgView8: TImage;
imgView3: TImage;
stName: TStaticText;
btnBack: TBitBtn;
lblRecordCount: TLabel;
bhHelp: TBalloonHint;
imgHelp: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
// Fix for multi forums.
procedure CreateParams(var Params: TCreateParams); override;
procedure resetPanels();
procedure showObjective(Panel: TPanel);
procedure imgMenuClick(Sender: TObject);
procedure btnBackClick(Sender: TObject);
procedure pnl1Click(Sender: TObject);
procedure pnl2Click(Sender: TObject);
procedure pnl3Click(Sender: TObject);
procedure pnl4Click(Sender: TObject);
procedure pnl5Click(Sender: TObject);
procedure pnl6Click(Sender: TObject);
procedure pnl7Click(Sender: TObject);
procedure pnl8Click(Sender: TObject);
procedure imgHelpMouseEnter(Sender: TObject);
procedure imgHelpMouseLeave(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// Public vars for other forms.
iSelectedObjectiveID: Integer;
// All our objective objects.
arrObjects: Array of TObjectiveO;
end;
var
frmObjectives: TfrmObjectives;
// Added.
bShown: Boolean;
iPanelAmount: Integer;
// We don't know size, but we can use Length() to get elements.
arrTitles: Array of string;
arrViews: Array of Integer;
// ** Parallel Arrays.
// Added.
arrPanels: TArray<TPanel>;
arrImages: TArray<TImage>;
implementation
{$R *.dfm}
uses u_Functions, u_DatabaseConnection, u_Application, u_View, u_Create;
procedure TfrmObjectives.btnBackClick(Sender: TObject);
begin
// Move.
frmObjectives.Hide;
frmApplication.Show;
end;
procedure TfrmObjectives.CreateParams(var Params: TCreateParams);
begin
inherited;
// Set style sheet so Windows knows its another "window".
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
Params.WndParent := GetDesktopWindow;
end;
procedure TfrmObjectives.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Fix multi form issues.
Application.Terminate;
end;
procedure TfrmObjectives.FormCreate(Sender: TObject);
begin
// Form setup.
Functions.disableSize(frmObjectives);
Functions.makeRound(pnl1);
Functions.makeRound(pnl2);
Functions.makeRound(pnl3);
Functions.makeRound(pnl4);
Functions.makeRound(pnl5);
Functions.makeRound(pnl6);
Functions.makeRound(pnl7);
Functions.makeRound(pnl8);
end;
procedure TfrmObjectives.FormShow(Sender: TObject);
var
I: Integer;
objObjective: TObjectiveO;
// Object vars.
ID, SignatureCount: Integer;
Title, Body: String;
VictoryStatus, Donation: Boolean;
CreationDate: TDateTime;
DonationAmount, DonationGoal: Real;
begin
// Make sure we are working with latest.
dmConnection.tblObjectives.close;
dmConnection.tblObjectives.open;
// Always should be centre.
Functions.sizeCentre(frmObjectives);
// Set
bShown := true;
iPanelAmount := 0;
// Safe reset dynamic array.
SetLength(arrViews, 0);
SetLength(arrTitles, 0);
SetLength(arrObjects, 0);
Finalize(arrViews);
Finalize(arrTitles);
Finalize(arrObjects);
arrViews := nil;
arrTitles := nil;
arrObjects := nil;
// Default everything.
resetPanels;
// Lets now populate our arrays.
// Ready.
dmConnection.tblObjectives.Sort := 'O_ID ASC';
dmConnection.tblObjectives.First;
while NOT(dmConnection.tblObjectives.Eof) do
begin
// Deny if panel amount is 8.
if (iPanelAmount = 8) then
begin
Break;
end;
// Put into array
SetLength(arrTitles, iPanelAmount + 1);
SetLength(arrViews, iPanelAmount + 1);
SetLength(arrObjects, iPanelAmount + 1);
arrTitles[iPanelAmount] := dmConnection.tblObjectives['Title'];
arrViews[iPanelAmount] := dmConnection.tblObjectives['ViewCount'];
Inc(iPanelAmount);
// Move
dmConnection.tblObjectives.Next;
end;
// Create arrays.
arrPanels := TArray<TPanel>.create(pnl1, pnl2, pnl3, pnl4, pnl5, pnl6,
pnl7, pnl8);
arrImages := TArray<TImage>.create(imgView1, imgView2, imgView3, imgView4,
imgView5, imgView6, imgView7, imgView8);
// Populate our objectives.
for I := 0 to Length(arrTitles) - 1 do
begin
arrPanels[I].Caption := arrTitles[I];
arrImages[I].Hint := 'Views: ' + IntToStr(arrViews[I]);
arrImages[I].Show;
end;
// Create Objects and put into array.
for I := 0 to Length(arrTitles) - 1 do
begin
// Ready all vars.
ID := Functions.findID(arrTitles[I]);
Title := arrTitles[I];
Body := Functions.findBody(ID);
VictoryStatus := Functions.findVictoryStatus(ID);
Donation := Functions.findDonation(ID);
CreationDate := Functions.findCreationDate(ID);
SignatureCount := Functions.findSignatureCount(ID);
DonationAmount := Functions.findDonationAmount(ID);
DonationGoal := Functions.findDonationGoal(ID);
// Finally, create object and add to array.
objObjective := TObjectiveO.create(ID, Title, Body, VictoryStatus, Donation,
CreationDate, SignatureCount, DonationAmount, DonationGoal);
arrObjects[I] := objObjective;
end;
// Count records.
Functions.openSQL('SELECT Count(Title) AS RecordsNumber FROM tblObjectives');
lblRecordCount.Caption := 'Amount: ' + dmConnection.qrQuery.Fields[0]
.AsString;
end;
procedure TfrmObjectives.imgHelpMouseEnter(Sender: TObject);
begin
bhHelp.Title := 'Impactify help:';
bhHelp.Description := 'Click on a panel to create a new objective.';
bhHelp.ShowHint(pnl1);
end;
procedure TfrmObjectives.imgHelpMouseLeave(Sender: TObject);
begin
bhHelp.HideHint;
end;
procedure TfrmObjectives.imgMenuClick(Sender: TObject);
begin
// Sliding panel logic.
if (bShown = true) then
begin
svSide.Opened := false;
rpHold.BevelInner := bvNone;
rpHold.BevelKind := bkNone;
rpHold.BevelOuter := bvNone;
bShown := false;
// Set new size
rpHold.Width := 950;
rpHold.Alignment := taLeftJustify;
rpHold.Align := alLeft;
end
else
begin
svSide.Opened := true;
rpHold.BevelInner := bvNone;
rpHold.BevelKind := bkNone;
rpHold.BevelOuter := bvRaised;
bShown := true;
// Set old size
rpHold.Width := 600;
rpHold.Alignment := taCenter;
rpHold.Align := alClient;
end;
end;
procedure TfrmObjectives.pnl1Click(Sender: TObject);
begin
showObjective(pnl1);
end;
procedure TfrmObjectives.pnl2Click(Sender: TObject);
begin
showObjective(pnl2);
end;
procedure TfrmObjectives.pnl3Click(Sender: TObject);
begin
showObjective(pnl3);
end;
procedure TfrmObjectives.pnl4Click(Sender: TObject);
begin
showObjective(pnl4);
end;
procedure TfrmObjectives.pnl5Click(Sender: TObject);
begin
showObjective(pnl5);
end;
procedure TfrmObjectives.pnl6Click(Sender: TObject);
begin
showObjective(pnl6);
end;
procedure TfrmObjectives.pnl7Click(Sender: TObject);
begin
showObjective(pnl7);
end;
procedure TfrmObjectives.pnl8Click(Sender: TObject);
begin
showObjective(pnl8);
end;
procedure TfrmObjectives.resetPanels;
begin
// Reset all panels to default.
pnl1.Caption := 'Click to create an objective';
pnl2.Caption := 'Click to create an objective';
pnl3.Caption := 'Click to create an objective';
pnl4.Caption := 'Click to create an objective';
pnl5.Caption := 'Click to create an objective';
pnl6.Caption := 'Click to create an objective';
pnl7.Caption := 'Click to create an objective';
pnl8.Caption := 'Click to create an objective';
imgView1.Hide;
imgView2.Hide;
imgView3.Hide;
imgView4.Hide;
imgView5.Hide;
imgView6.Hide;
imgView7.Hide;
imgView8.Hide;
end;
procedure TfrmObjectives.showObjective(Panel: TPanel);
begin
// Should we show the objective?
if (Panel.Caption <> 'Click to create an objective') then
begin
// Get ID.
dmConnection.tblObjectives.First;
while NOT(dmConnection.tblObjectives.Eof) do
begin
if (dmConnection.tblObjectives['Title'] = Panel.Caption) then
begin
iSelectedObjectiveID := dmConnection.tblObjectives['O_ID'];
// Stop.
Break;
end;
// Move.
dmConnection.tblObjectives.Next;
end;
// Move to new form (show).
frmObjectives.Hide;
frmView.Show;
end
else
begin
// Move to new form (create).
frmObjectives.Hide;
frmCreate.Show;
end;
end;
end.