-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmClient.pas
349 lines (303 loc) · 9.92 KB
/
frmClient.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
unit frmClient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, jpeg, ExtCtrls, DB, ADODB, Grids, DBGrids, StdCtrls,
uClient, uServiceRequest, Buttons, uClientReportsAndLogs, uAccountDetails,
uAutoDroneDeployment, uHelp, uLibrary, DateUtils;
type
TClientForm = class(TForm)
imgBackground: TImage;
pgcClient: TPageControl;
tbsDroneServices: TTabSheet;
tbsResponseLogs: TTabSheet;
tbsReports: TTabSheet;
tbsAccountDetails: TTabSheet;
dbgServices: TDBGrid;
adoServices: TADOQuery;
dtsServices: TDataSource;
dtpStart: TDateTimePicker;
dtpEnd: TDateTimePicker;
lblStartDate: TLabel;
lblEndDate: TLabel;
grbSummary: TGroupBox;
btnRequestService: TButton;
lblSummary: TLabel;
dbgDroneFlights: TDBGrid;
adoResponeLogs: TADOQuery;
dtsResponseLogs: TDataSource;
grpIncidentSummary: TGroupBox;
lblIncidentSummary: TLabel;
bmbRefreshLogs: TBitBtn;
rgpSort: TRadioGroup;
btnShowFootage: TButton;
rgpReportType: TRadioGroup;
redReports: TRichEdit;
btnSendToEmail: TButton;
Button1: TButton;
grpChangePassword: TGroupBox;
ledCurrentPass: TLabeledEdit;
ledNewPass: TLabeledEdit;
ledRetypedNewPass: TLabeledEdit;
btnChangePass: TButton;
grpDetails: TGroupBox;
lblNameTitle: TLabel;
lblSurnameTitle: TLabel;
lblEmailTitle: TLabel;
lblName: TLabel;
lblSurname: TLabel;
lblEmail: TLabel;
grpAddress: TGroupBox;
lblAddressTitle: TLabel;
lblSuburbTitle: TLabel;
lblAddress: TLabel;
lblSuburb: TLabel;
grpDeactivateAccount: TGroupBox;
bmbDeactivateAcc: TBitBtn;
grpLogout: TGroupBox;
bmbLogOut: TBitBtn;
tmrAuto: TTimer;
rgpStatus: TRadioGroup;
btnHelp: TButton;
procedure dbgServicesCellClick(Column: TColumn);
procedure dtpStartChange(Sender: TObject);
procedure dtpEndChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnRequestServiceClick(Sender: TObject);
procedure bmbRefreshLogsClick(Sender: TObject);
procedure dbgDroneFlightsCellClick(Column: TColumn);
procedure rgpSortClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure btnChangePassClick(Sender: TObject);
procedure bmbDeactivateAccClick(Sender: TObject);
procedure bmbLogOutClick(Sender: TObject);
procedure tmrAutoTimer(Sender: TObject);
procedure rgpStatusClick(Sender: TObject);
procedure btnSendToEmailClick(Sender: TObject);
procedure btnShowFootageClick(Sender: TObject);
procedure btnHelpClick(Sender: TObject);
private
procedure FormatServiceDBGrid;
procedure FormatFlightLogsDBGrid;
procedure FormatReportsRichEdit;
procedure UpdateSummary;
procedure PopulateServiceResponse;
procedure SurveillanceReport;
procedure AccountDetailsSetup;
procedure RefreshFlightLogs;
public
procedure FormSetup(ClientObj: TClient; AccountDetialsObj :
TAccountDetails; HelpObj : THelp);
end;
var
ClientForm: TClientForm;
objClient : TClient;
objServiceRequest : TServiceRequest;
objAccountDetails : TAccountDetails;
objHelp : THelp;
implementation
{$R *.dfm}
{ TClientForm }
procedure TClientForm.AccountDetailsSetup;
begin
lblName.Caption := objClient.GetName;
lblSurname.Caption := objClient.GetSurname;
lblEmail.Caption := objClient.GetEmail;
lblAddress.Caption := objClient.GetAddressLine1;
lblSuburb.Caption := objClient.GetSuburbName;
end;
procedure TClientForm.bmbDeactivateAccClick(Sender: TObject);
begin
objAccountDetails.DeactivateAcc(objClient.GetUserID, Self);
end;
procedure TClientForm.bmbLogOutClick(Sender: TObject);
begin
objAccountDetails.LogOut(Self);
end;
procedure TClientForm.bmbRefreshLogsClick(Sender: TObject);
begin
RefreshFlightLogs;
end;
procedure TClientForm.btnChangePassClick(Sender: TObject);
var
sOldPass, sNewPass, sRetypedPass : string;
bCompleted : boolean;
begin
sOldPass := Trim(ledCurrentPass.Text);
sNewPass := Trim(ledNewPass.Text);
sRetypedPass := Trim(ledRetypedNewPass.Text);
objAccountDetails.ChangePassword(sOldPass, sNewPass, sRetypedPass,
objClient.GetPass, objClient.GetUserID, objClient.GetName + ' ' +
objClient.GetSurname, objClient.GetEmail, bCompleted);
if bCompleted = true then
begin
objClient.SetPass(sNewPass);
AccountDetailsSetup;
end;
end;
procedure TClientForm.btnHelpClick(Sender: TObject);
begin
objHelp.LoadHelp(pgcClient.ActivePage.Caption);
end;
procedure TClientForm.btnRequestServiceClick(Sender: TObject);
var
sStartTime : string;
begin
if MessageDlg(objServiceRequest.ConfirmServiceRequest, mtConfirmation,
mbYesNo, 0) = mrYes then
begin
sStartTime := adoServices['Surveillance Start Time'];
objServiceRequest.RequestService(objClient.GetUserID, sStartTime);
end;
end;
procedure TClientForm.btnSendToEmailClick(Sender: TObject);
var
sReportName, sFullName : string;
begin
MessageDlg('Sending Email Please Wait...', mtInformation, mbOKCancel, 0);
sFullName := objClient.GetName + ' ' + objClient.GetSurname;
sReportName := Trim(rgpReportType.Items[rgpReportType.ItemIndex]);
objEmails.SendEmail(sFullName, objClient.GetEmail, sReportName +
' for ' + LongMonthNames[MonthOf(Date())], 'Dear ' + sFullName + ',' +
#13 + 'Here is the following report you requested.' + #13 +
redReports.Text + #13 + #13 + 'Regards,' + #13 + 'Birds Eye Security');
end;
procedure TClientForm.btnShowFootageClick(Sender: TObject);
var
sDroneFlightID : string;
begin
sDroneFlightID := adoResponeLogs['Flight No'];
ShowSurvFootage(sDroneFlightID);
end;
procedure TClientForm.Button1Click(Sender: TObject);
begin
if rgpReportType.ItemIndex = 0 then
redReports.Text := CostOfServicesReport(objClient.GetUserID)
else
redReports.Text := SuburbReport(objClient.GetUserID);
btnSendToEmail.Enabled := true;
end;
//-------------------------------------ASSIGNS OBJECTS AND WELCOMES USER
procedure TClientForm.FormSetup(ClientObj: TClient; AccountDetialsObj :
TAccountDetails; HelpObj : THelp);
begin
objClient := ClientObj;
objAccountDetails := AccountDetialsObj;
objHelp := HelpObj;
PopulateServiceResponse;
SurveillanceReport;
AccountDetailsSetup;
MessageDlg('Welcome ' + objClient.GetName + ' ' + objClient.GetSurname +
' you have been succesfully logged in!', mtInformation, mbOKCancel, 0);
end;
procedure TClientForm.dbgDroneFlightsCellClick(Column: TColumn);
begin
SurveillanceReport;
end;
procedure TClientForm.dbgServicesCellClick(Column: TColumn);
begin
UpdateSummary;
end;
procedure TClientForm.dtpEndChange(Sender: TObject);
begin
if dtpStart.Date > dtpEnd.Date then
dtpStart.Date := dtpEnd.Date;
UpdateSummary;
end;
procedure TClientForm.dtpStartChange(Sender: TObject);
begin
if dtpStart.Date > dtpEnd.Date then
dtpEnd.Date := dtpStart.Date;
UpdateSummary;
end;
//-------------------------------------FORMATS THE FLIGHT LOGS GRID
procedure TClientForm.FormatFlightLogsDBGrid;
begin
dbgDroneFlights.Columns.Items[0].Width := 65;
dbgDroneFlights.Columns.Items[3].Alignment := taRightJustify;
end;
//-------------------------------------FORMATS THE REPORTS RICH EDIT
procedure TClientForm.FormatReportsRichEdit;
begin
redReports.Paragraph.TabCount := 2;
redReports.Paragraph.Tab[0] := 140;
redReports.Paragraph.Tab[1] := 315;
end;
//-------------------------------------FORMATS THE REQUEST SERVICES GRID
procedure TClientForm.FormatServiceDBGrid;
begin
dbgServices.Columns.Items[1].Width := 160;
dbgServices.Columns.Items[2].Width := 160;
dbgServices.Columns.Items[3].Width := 120;
dbgServices.Columns.Items[1].Alignment := taRightJustify;
dbgServices.Columns.Items[2].Alignment := taRightJustify;
dbgServices.Columns.Items[3].Alignment := taRightJustify;
end;
procedure TClientForm.FormCreate(Sender: TObject);
begin
//-------------------------------------MAKES THIS FORM THE MAIN FORM
Pointer((@Application.MainForm)^) := Self;
objServiceRequest := TServiceRequest.Create;
adoServices.Active := true;
dtpStart.MinDate := Date();
dtpEnd.MinDate := Date();
UpdateSummary;
FormatServiceDBGrid;
FormatReportsRichEdit;
end;
procedure TClientForm.PopulateServiceResponse;
begin
adoResponeLogs.Active := false;
adoResponeLogs.SQL.Text := UserFlightReports(objClient.GetUserID,
rgpSort.ItemIndex, rgpStatus.ItemIndex);
adoResponeLogs.Active := true;
FormatFlightLogsDBGrid;
end;
procedure TClientForm.RefreshFlightLogs;
begin
adoResponeLogs.Active := false;
adoResponeLogs.Active := true;
FormatFlightLogsDBGrid;
end;
procedure TClientForm.rgpSortClick(Sender: TObject);
begin
PopulateServiceResponse;
end;
procedure TClientForm.rgpStatusClick(Sender: TObject);
begin
PopulateServiceResponse;
end;
procedure TClientForm.SurveillanceReport;
var
sFlightID : string;
begin
if adoResponeLogs.RecordCount <> 0 then
begin
sFlightID := adoResponeLogs['Flight No'];
lblIncidentSummary.Caption := SurveillanceSummary(sFlightID);
if adoResponeLogs['Status'] = 'Completed' then
btnShowFootage.Enabled := true
else
btnShowFootage.Enabled := false;
end;
end;
procedure TClientForm.tmrAutoTimer(Sender: TObject);
begin
DeployDrones;
CompleteFlights;
RefreshFlightLogs;
end;
procedure TClientForm.UpdateSummary;
var
startDate, endDate : TDate;
sService : string;
rPricePerDay : real;
begin
startDate := dtpStart.Date;
endDate := dtpEnd.Date;
sService := adoServices['Service Name'];
rPricePerDay := adoServices['Price Per Day'];
objServiceRequest.SetValues(startDate, endDate, sService, rPricePerDay);
lblSummary.Caption := objServiceRequest.UpdateServiceSummary;
end;
end.