-
Notifications
You must be signed in to change notification settings - Fork 0
/
uDroneLaunch.pas
98 lines (85 loc) · 3.4 KB
/
uDroneLaunch.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
unit uDroneLaunch;
interface
uses
uDB_Source, uLibrary, SysUtils;
procedure AssignStaffToService(DroneFlightID : string);
procedure ScheduleFlight(Service, Date, Time, UserID, UserServiceID,
SuburbID : string);
procedure AssignUserServiceToFlight(UserServiceID, DroneFlightID: string);
implementation
{ TDroneLaunch }
//-------------------------------------ASSIGNS A STAFF MEMBER TO A FLIGHT
procedure AssignStaffToService(DroneFlightID : string);
var
sSQL : string;
arrStaffMembers : TDynamicArray;
iRandom : word;
begin
sSQL := 'Select [StaffID] '
+ 'from Staff, JobTitles '
+ 'where [Job Title] = [JobTitleID] AND [Job Title Name] = ' +
'"Surveillance Analyst"';
arrStaffMembers := objDB.ToArray(sSQL);
Randomize;
iRandom := Random(Length(arrStaffMembers));
sSQL := 'Insert into SurveillanceReports '
+ '([DroneFlightID], [StaffID]) '
+ 'Values(' + DroneFlightID + ', ' + arrStaffMembers[iRandom] + ')';
objDB.DoSQL(sSQL);
end;
//-------------------------------------ASSIGNS A USERS SERVICE REQUEST TO
//-------------------------------------A SPECIFIC FLIGHT
procedure AssignUserServiceToFlight(UserServiceID, DroneFlightID: string);
var
sSQL : string;
begin
sSQL := 'Insert into FlightToServiceAssignment '
+ '([UserServiceID], [DroneFlightID]) '
+ 'Values(' + UserServiceID + ', ' + DroneFlightID + ')';
objDB.DoSQL(sSQL);
end;
//-------------------------------------SCHEDULES ALL THE FLIGHTS FOR
//-------------------------------------A SERVICE REQUEST
procedure ScheduleFlight(Service, Date, Time, UserID, UserServiceID,
SuburbID : string);
var
sSQL, sServiceID, sDroneFlightID : string;
arrAvailableDrones : TDynamicArray;
iRandom : byte;
begin
sSQL := 'Select [ServiceID] '
+ 'from Services '
+ 'where [Service Name] = "' + Service + '"';
sServiceID := objDB.ToString(sSQL, '');
//-------------------------------------FINDS ALL AVAILABLE DRONES FOR THE
//-------------------------------------SPECIFIC DATE
sSQL := 'Select [DroneID] '
+ 'from Drones '
+ 'where [Drone Type] = ' + sServiceID + 'AND [Suburb] = ' +
SuburbID + ' AND [DroneID] NOT IN (Select [DroneID] ' +
'from DroneFlights where Format(' +
'[Date and Time of Response], "Short Date") = #' +
Date + '# AND [Status] <> "Completed")';
arrAvailableDrones := objDB.ToArray(sSQL);
if Length(arrAvailableDrones) <> 0 then
begin
//-------------------------------------ASSIGNS A RANDOM DRONE TO
//-------------------------------------A SERVICE REQUEST
Randomize;
iRandom := Random(Length(arrAvailableDrones));
sSQL := 'Insert into DroneFlights '
+ '([DroneID], [Date and Time of Response]) '
+ 'Values(' + arrAvailableDrones[iRandom] + ', Format("' + Date +
' ' + Time + '", "General Date"))';
objDB.DoSQL(sSQL);
sSQL := 'Select [DroneFlightID] '
+ 'from DroneFlights '
+ 'where [DroneID] = ' + arrAvailableDrones[iRandom] +
' AND [Status] = "Scheduled" AND [DroneFlightID] NOT ' +
'IN (Select [DroneFlightID] from FlightToServiceAssignment)';
sDroneFlightID := objDB.ToString(sSQL, '');
AssignUserServiceToFlight(UserServiceID, sDroneFlightID);
AssignStaffToService(sDroneFlightID);
end;
end;
end.