forked from urgn-zz/school_schedule_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTimeTable.pas
728 lines (602 loc) · 20.8 KB
/
TTimeTable.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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
unit TTimeTable;
interface
uses Classes, Contnrs, SQLExpr, SysUtils, Data.Db, Dialogs;
type
//Base classes
TTeacher = class
TeacherID : Integer;
constructor Create(aTeacherID : Integer);
end;
TRoom = class
RoomID : Integer;
HasPC : Boolean;
constructor Create(aRoomID : Integer; aHasPC : Boolean);
end;
TGroup = class
GroupID : Integer;
constructor Create(aGroupID : Integer);
end;
TSubject = class
SubjectId : integer;
constructor Create ( SubjectID : Integer );
end;
// Load item (Lesson)
TLoadItem = class
LoadID : Integer;
Teacher : TTeacher;
Group : TGroup;
NeedPC : BOOLEAN;
Checked : BOOLEAN;
constructor Create ( LoadID : Integer; Teacher: TTeacher; Group: TGroup; NeedPC : Boolean);
end;
// All lessons in current time
TCurrentLesson = class
TimeID : INTEGER;
Lessons : TObjectList;
BusyGroups : TObjectList;
FreeGroups : TObjectList;
BusyRooms : TObjectList;
FreeRooms : TObjectList;
BusyTeachers : TObjectList;
FreeTeachers : TObjectList;
AssignedLoad : TObjectList;
ReadyLessons : TObjectList;
Checked : Boolean;
constructor Create ( aTimeID : Integer) ;
end;
// Assigned lesson
TLesson = class
Parent : TCurrentLesson;
LoadItem : TLoadItem;
Room : TRoom;
constructor Create( aParent : TCurrentLesson; aLoadItem : TLoadItem; aRoom : TRoom );
end;
TLessons = array of array of array of TCurrentLesson;
// All lesson of all time
T_TimeTable = class
FData : TLessons;
AllTeachers : TObjectList;
AllGroups : TObjectList;
AllRooms : TObjectList;
AllSubjects : TObjectList;
AllLoad : TObjectList;
FreeLoad : TObjectList;
BusyLoad : TObjectList;
AllLessons : TObjectList;
l_count : integer;
w_count : integer;
d_count : integer;
// Loading catalog data
procedure loadTeacherData (ds_Teacher, ds_Avlblt : TSQLDataSet );
procedure loadGroupData (ds_Group, ds_Avlblt : TSQLDataSet);
procedure loadRoomData (ds_Room, ds_Avlblt : TSQLDataSet) ;
procedure loadSubjectData (ds_Subject : TSQLDataSet);
// Loading LOAD Data
procedure loadLoadData (ds_Load : TSQLDataSet);
// Usefull shit
function findTeacherById (TeacherID : Integer) : TTeacher;
function findGroupById (GroupID : Integer) : TGroup;
function findRoomByID (RoomID : Integer) : TRoom;
procedure fillFirstDraft;
function placeIntoTimeTable (li : TLoadItem) : boolean;
procedure fitRooms;
constructor Create( ads_Teacher, ads_Group,
ads_Room, ads_Subject,
ads_Avlblt, ads_Load : TSQLDataSet );
end;
implementation
{ TTeacher }
constructor TTeacher.Create(aTeacherID: Integer);
begin
self.TeacherID := aTeacherID;
end;
{ TRoom }
constructor TRoom.Create(aRoomID: Integer; aHasPC : Boolean);
begin
self.RoomID := aRoomID;
self.HasPC := aHasPC;
end;
{ TGroup }
constructor TGroup.Create(aGroupID: Integer);
begin
self.GroupID := aGroupID;
end;
{ TCurrentLesson }
constructor TCurrentLesson.Create(aTimeID: Integer);
begin
self.TimeID := aTimeID;
self.BusyGroups := TObjectList.Create(false);
self.FreeGroups := TOBjectList.Create(false);
self.FreeTeachers := TObjectList.Create(false);
self.BusyTeachers := TObjectList.Create(false);
self.BusyRooms := TObjectList.Create(false);
self.FreeRooms := TObjectList.Create(false);
self.AssignedLoad := TObjectList.Create(false);
self.ReadyLessons := TObjectList.Create(false);
end;
{ T_TimeTable }
constructor T_TimeTable.Create( ads_Teacher, ads_Group, ads_Room,
ads_Subject, ads_Avlblt, ads_Load : TSQLDataSet );
var
i, j, k : Integer;
begin
w_count := 2;
d_count := 6;
l_count := 6;
// Creating cells
SetLength(FData, w_count);
for I := 0 to pred(w_count) do
BEGIN
SetLength(FData[i], d_count);
for J := 0 to pred(d_count) do
BEGIN
SetLength(FData[i,j], l_count);
for K := 0 to pred(l_count) do
begin
FData[i,j,k] := TCurrentLesson.Create((i + 1)*100 + (j + 1)*10 + k + 1);
end;
END;
END;
// Loading initial catalogs and avialability
AllSubjects := TObjectList.Create(true);
loadSubjectData(ads_Subject);
AllGroups := TObjectList.Create(true);
loadGroupData(ads_Group, ads_Avlblt);
AllTeachers := TObjectList.Create(true);
loadTeacherData(ads_Teacher, ads_Avlblt);
AllRooms := TObjectList.Create(true);
loadRoomData(ads_Room, ads_Avlblt);
FreeLoad := TObjectList.Create(false);
BusyLoad := TObjectList.Create(false);
AllLessons := TObjectList.Create(false);
loadLoadData(ads_Load);
fillFirstDraft;
fitRooms;
end;
procedure T_TimeTable.fillFirstDraft;
var
i,j : Integer;
TempLoad : TLoadItem;
begin
for I := pred( FreeLoad.Count ) downto 0 do
begin
for j := 0 to pred(AllLoad.Count) do (AllLoad.Items[i] AS TLoadItem).Checked := false;
TempLoad := (FreeLoad.Items[i] AS TLoadItem);
if (placeIntoTimeTable(TempLoad)) then
begin
BusyLoad.Add(TempLoad);
FreeLoad.Remove(TempLoad);
end;
end;
if (FreeLoad.Count > 0) then ShowMessage('You got ' + IntToStr(FreeLoad.Count) + ' conflict(s);');
end;
function T_TimeTable.findGroupById(GroupID: Integer): TGroup;
var
i: Integer;
begin
for i := 0 to pred(AllGroups.Count) do
begin
if ((AllGroups.Items[i]) AS TGroup).GroupID = GroupID then
begin
Result := (AllGroups.Items[i] AS TGroup);
exit;
end;
end;
end;
function T_TimeTable.findRoomByID(RoomID: Integer): TRoom;
var
i: Integer;
begin
for i := 0 to pred(AllGroups.Count) do
begin
if ((AllGroups.Items[i]) AS TRoom).RoomID = RoomID then
begin
Result := (AllRooms.Items[i] AS TRoom);
exit;
end;
end;
end;
function T_TimeTable.findTeacherById(TeacherID: Integer): TTeacher;
var
i: Integer;
begin
for i := 0 to pred(AllTeachers.Count) do
begin
if ((AllTeachers.Items[i]) AS TTeacher).TeacherID = TeacherID then
begin
Result := (AllTeachers.Items[i] AS TTeacher);
exit;
end;
end;
end;
procedure T_TimeTable.fitRooms;
var
w, d, l, i, j : Integer;
temp_load : TLoadItem;
temp_room : TRoom;
temp_lesson1, temp_lesson2 : TLesson;
k: Integer;
begin
// ASSIGN ROOMS WITH SPECIALS INSIDE SCOPE OF 1 time-slot
for i := 0 to pred(AllLessons.Count) do
begin
with (AllLessons.Items[i] AS TLesson) do
begin
if not LoadItem.NeedPC then continue;
temp_lesson1 := (AllLessons.Items[i] AS TLesson);
temp_load := temp_lesson1.LoadItem;
//showMessage(IntToStr(Parent.FreeRooms.Count));
for j := 0 to pred(Parent.FreeRooms.Count) do
begin
if (Parent.FreeRooms.Items[j] AS TRoom).HasPC then
begin
Room := (Parent.FreeRooms.Items[j] AS TRoom);
Parent.BusyRooms.Add((Parent.FreeRooms.Items[j] AS TRoom));
Parent.FreeRooms.Remove((Parent.FreeRooms.Items[j] AS TRoom));
break;
end;
end;
end;
end;
//SWAP LESSONS INTO ANOTHER TIME-SLOT WHERE SUCH ROOM EXISTS
for i := 0 to pred(AllLessons.Count) do
begin
temp_lesson1 := AllLessons.Items[i] AS TLesson;
if (not (temp_lesson1.LoadItem.NeedPC))
OR (temp_lesson1.Room <> nil) then continue;
for j := 0 to pred(AllLessons.Count) do
begin
temp_lesson2 := AllLessons.Items[j] AS TLesson;
if (temp_lesson1.LoadItem.Teacher = temp_lesson2.LoadItem.Teacher)
AND (temp_lesson1.LoadItem.Group = temp_lesson2.LoadItem.Group )
AND not temp_lesson2.LoadItem.NeedPC
then
begin
for k := 0 to pred(temp_lesson2.Parent.FreeRooms.Count) do
begin
temp_room := temp_lesson2.Parent.FreeRooms.Items[k] AS TRoom;
if temp_room.HasPC then
begin
temp_lesson1.Room := temp_room;
temp_lesson2.Parent.FreeGroups.Remove(temp_room);
temp_lesson2.Parent.BusyGroups.Add(temp_room);
temp_lesson2.Parent.Lessons.Add(temp_lesson1);
temp_lesson2.Parent.Lessons.Remove(temp_lesson2);
temp_lesson1.Parent.Lessons.Add(temp_lesson2);
temp_lesson1.Parent.Lessons.Remove(temp_lesson1);
break;
end;
end;
end;
end;
end;
//Try to rooms without specials
// ASSIGN ROOMS WITHOUT SPECIALS INSIDE SCOPE OF 1 time-slot
for i := 0 to pred(AllLessons.Count) do
begin
with (AllLessons.Items[i] AS TLesson) do
begin
if LoadItem.NeedPC then continue;
for j := 0 to pred(Parent.FreeRooms.Count) do
begin
Room := (Parent.FreeRooms.Items[j] AS TRoom);
Parent.BusyRooms.Add((Parent.FreeRooms.Items[j] AS TRoom));
Parent.FreeRooms.Remove((Parent.FreeRooms.Items[j] AS TRoom));
break;
end;
end;
end;
//SWAP LESSONS INTO ANOTHER TIME-SLOT WHERE SUCH ROOM EXISTS
for i := 0 to pred(AllLessons.Count) do
begin
temp_lesson1 := AllLessons.Items[i] AS TLesson;
if (temp_lesson1.LoadItem.NeedPC) OR (temp_lesson1.Room <> nil) then continue;
for j := 0 to pred(AllLessons.Count) do
begin
temp_lesson2 := AllLessons.Items[j] AS TLesson;
if (temp_lesson1.LoadItem.Teacher = temp_lesson2.LoadItem.Teacher)
AND (temp_lesson1.LoadItem.Group = temp_lesson2.LoadItem.Group )
then
begin
for k := 0 to pred(temp_lesson2.Parent.FreeRooms.Count) do
begin
temp_room := temp_lesson2.Parent.FreeRooms.Items[k] AS TRoom;
temp_lesson1.Room := temp_room;
temp_lesson2.Parent.FreeGroups.Remove(temp_room);
temp_lesson2.Parent.BusyGroups.Add(temp_room);
temp_lesson2.Parent.Lessons.Add(temp_lesson1);
temp_lesson2.Parent.Lessons.Remove(temp_lesson2);
temp_lesson1.Parent.Lessons.Add(temp_lesson2);
temp_lesson1.Parent.Lessons.Remove(temp_lesson1);
break;
end;
end;
end;
end;
end;
procedure T_TimeTable.loadGroupData(ds_Group, ds_Avlblt: TSQLDataSet);
var
TempGroup : TGroup;
AvQuery : String;
Time_ID,
w, d, l : Integer;
begin
if not ds_Group.Active then ds_Group.Open;
ds_Group.First;
while not ds_Group.eof do
begin
TempGroup := TGroup.Create(ds_Group.Fields[0].Value);
AllGroups.Add(TempGroup);
//Load avialability
if ds_Avlblt.Active then ds_Avlblt.Close;
avQuery := 'SELECT "time_id" FROM "av_Group" WHERE "flag" = ''1'' AND "Group_id" = ' + IntToStr(TempGroup.GroupID) + ';';
ds_Avlblt.CommandType := ctQuery;
ds_Avlblt.CommandText := AvQuery;
ds_Avlblt.Open;
ds_Avlblt.First;
while not ds_Avlblt.Eof do
begin
Time_Id := ds_Avlblt.Fields[0].Value;
w := time_Id div 100;
d := (time_id - w*100) div 10;
l := time_id - w*100 - d*10;
FData[w - 1,d - 1,l - 1].FreeGroups.Add(TempGroup);
ds_Avlblt.Next;
end;
ds_Avlblt.Close;
ds_Group.Next;
end;
end;
procedure T_TimeTable.loadLoadData(ds_Load: TSQLDataSet);
var
i: Integer;
a : TGRoup;
gid : integer;
temp_load : TLoadItem;
t : String ;
begin
AllLoad := TObjectList.Create(false);
if not (ds_Load.Active) then ds_Load.Open;
ds_Load.First;
while not ds_Load.Eof do
begin
for i := 1 to ds_Load.FieldByName('num_hours').Value do
begin
//gid := ds_Load.FieldByName('group_id').Value;
//a := findGroupById(ds_Load.FieldByName('group_id').Value);
temp_load := TLoadItem.Create( ds_Load.FieldByName('Load_id').Value,
findTeacherById(ds_Load.FieldByName('teacher_id').Value),
findGroupById(ds_Load.FieldByName('group_id').Value),
length(ds_Load.FieldByName('NeedPC').Value) = 1);
FreeLoad.Add(temp_load);
AllLoad.Add(temp_load);
end;
ds_Load.Next;
end;
end;
procedure T_TimeTable.loadRoomData(ds_Room, ds_Avlblt: TSQLDataSet);
var
TempRoom : TRoom;
AvQuery : String;
Time_ID,
w, d, l : Integer;
begin
if not ds_Room.Active then ds_Room.Open;
ds_Room.First;
while not ds_Room.eof do
begin
TempRoom := TRoom.Create(ds_Room.FieldByName('room_id').Value, ds_Room.FieldByName('room_pc_flag').Value <> 0);
AllRooms.Add(TempRoom);
//Load avialability
if ds_Avlblt.Active then ds_Avlblt.Close;
avQuery := 'SELECT "time_id" FROM "av_Room" WHERE "flag" = ''1'' AND "Room_id" = ' + IntToStr(TempRoom.RoomID) + ';';
ds_Avlblt.CommandType := ctQuery;
ds_Avlblt.CommandText := AvQuery;
ds_Avlblt.Open;
ds_Avlblt.First;
//ds_Avlblt.First;
while not ds_Avlblt.Eof do
begin
Time_Id := ds_Avlblt.Fields[0].Value;
w := time_Id div 100;
d := (time_id - w*100) div 10;
l := time_id - w*100 - d*10;
FData[w - 1,d - 1,l - 1].FreeRooms.Add(TempRoom);
ds_Avlblt.Next;
end;
ds_Avlblt.Close;
ds_Room.Next;
end;
end;
procedure T_TimeTable.loadSubjectData(ds_Subject: TSQLDataSet);
var
TempSubject : TSubject;
begin
if not ds_Subject.Active then ds_Subject.Open;
ds_Subject.First;
while not ds_Subject.eof do
begin
AllSubjects.Add(TSubject.Create(ds_Subject.Fields[0].Value));
ds_Subject.Next;
end;
end;
procedure T_TimeTable.loadTeacherData(ds_Teacher, ds_Avlblt: TSQLDataSet);
var
TempTeacher : TTeacher;
AvQuery : String;
Time_ID,
w, d, l, x : Integer;
begin
if not ds_Teacher.Active then ds_Teacher.Open;
ds_Teacher.First;
while not ds_Teacher.eof do
begin
TempTeacher := TTeacher.Create(ds_Teacher.Fields[0].Value);
AllTeachers.Add(TempTeacher);
//Load avialability
if ds_Avlblt.Active then ds_Avlblt.Close;
avQuery := 'SELECT "time_id" FROM "av_Teacher" WHERE "flag" = ''1'' AND "Teacher_id" = ' + IntToStr(TempTeacher.TeacherID) + ';';
ds_Avlblt.CommandType := ctQuery;
ds_Avlblt.CommandText := AvQuery;
ds_Avlblt.Open;
ds_Avlblt.First;
while not ds_Avlblt.Eof do
begin
Time_Id := ds_Avlblt.Fields[0].Value;
w := time_Id div 100;
d := (time_id - w*100) div 10;
l := time_id - w*100 - d*10;
FData[w - 1,d - 1,l - 1].FreeTeachers.Add(TempTeacher);
ds_Avlblt.Next;
end;
ds_Avlblt.Close;
ds_Teacher.Next;
end;
end;
function T_TimeTable.placeIntoTimeTable(li: TLoadItem): boolean;
var
w, d, l: Integer;
li2 : TLoadItem;
i: Integer;
rdy_Lesson : TLesson;
begin
Result := false;
li.Checked := true;
//Look for free cells
for l := 0 to pred(length(FData[0][0])) do
for d := 0 to pred(length(FData[0])) do
for w := 0 to pred(length(FData)) do
WITH FData[w][d][l] AS TCurrentLesson DO
begin
if (FreeTeachers.IndexOf(li.Teacher) >= 0)
AND (FreeGroups.IndexOf(li.Group) >= 0) then
begin
FreeTeachers.Remove(li.Teacher);
BusyTeachers.Add(li.Teacher);
FreeGroups.Remove(li.Group);
BusyGroups.Add(li.Group);
BusyLoad.Add(li);
FreeLoad.Remove(li);
AssignedLoad.Add(li);
rdy_Lesson := TLesson.Create(FData[w][d][l], li, nil);
ReadyLessons.Add(rdy_Lesson);
AllLessons.Add(rdy_Lesson);
Result := true;
exit;
end;
end;
//Look for semi-busy cells
for l := 0 to pred(l_count) do
for d := 0 to pred(d_count) do
for w := 0 to pred(w_count) do
begin
// Teacher is free but group is busy by li2
if (FData[w][d][l].FreeTeachers.IndexOf(li.Teacher) >= 0)
AND (FData[w][d][l].BusyGroups.IndexOf(li.Group) >= 0)
then
begin
//get load item of busy group
li2 := nil;
for i := 0 to pred(FData[w][d][l].AssignedLoad.Count) do
if li.Group = (FData[w][d][l].AssignedLoad.Items[i] AS TLoadItem).Group then
begin
li2 := FData[w][d][l].AssignedLoad.Items[i] AS TLoadItem;
end;
//replace li2 by li1, we find new place for li2 and placing li1 to the old place of li2
if li2.Checked then continue;
if (placeIntoTimeTable(li2)) then
begin
FData[w][d][l].AssignedLoad.Remove(li2);
FData[w][d][l].AssignedLoad.Add(li);
FData[w][d][l].FreeTeachers.Remove(li.Teacher);
FData[w][d][l].BusyTeachers.Add(li.Teacher);
rdy_Lesson := TLesson.Create(FData[w][d][l], li, nil);
FData[w][d][l].ReadyLessons.Add(rdy_Lesson);
AllLessons.Add(rdy_Lesson);
Result := true;
exit;
end;
end;
// Teacher is busy by li2 but group is free
if (FData[w][d][l].BusyTeachers.IndexOf(li.Teacher) >= 0)
AND (FData[w][d][l].FreeGroups.IndexOf(li.Group) >= 0) then
begin
li2 := nil;
for i := 0 to pred(FData[w][d][l].AssignedLoad.Count) do
if li.Teacher = (FData[w][d][l].AssignedLoad.Items[i] AS TLoadItem).Teacher then
begin
li2 := FData[w][d][l].AssignedLoad.Items[i] AS TLoadItem;
end;
if li2.Checked then continue;
if (placeIntoTimeTable(li2)) then
begin
FData[w][d][l].AssignedLoad.Remove(li2);
FData[w][d][l].AssignedLoad.Add(li);
FData[w][d][l].FreeGroups.Remove(li.Group);
FData[w][d][l].BusyGroups.Add(li.Group);
rdy_Lesson := TLesson.Create(FData[w][d][l], li, nil);
FData[w][d][l].ReadyLessons.Add(rdy_Lesson);
AllLessons.Add(rdy_Lesson);
Result := true;
exit;
end;
end;
end;
//Look for busy teacher and busy group
for w := 0 to pred(length(FData)) do
for l := 0 to pred(length(FData[0][0])) do
for d := 0 to pred(length(FData[0])) do
WITH FData[w][d][l] AS TCurrentLesson DO
begin
if (BusyTeachers.IndexOf(li.Teacher) >= 0)
AND (BusyGroups.IndexOf(li.Group) >= 0) then
begin
for i := 0 to pred(AssignedLoad.Count) do
if (li.Teacher = (AssignedLoad.Items[i] AS TLoadItem).Teacher)
AND (li.Group = (AssignedLoad.Items[i] AS TLoadItem).Group) then
begin
li2 := AssignedLoad.Items[i] AS TLoadItem;
break;
end;
if li2.Checked then continue;
if (placeIntoTimeTable(li2)) then
begin
FreeTeachers.Remove(li.Teacher);
BusyTeachers.Add(li.Teacher);
FreeGroups.Remove(li.Group);
BusyGroups.Add(li.Group);
BusyLoad.Add(li);
FreeLoad.Remove(li);
AssignedLoad.Add(li);
rdy_Lesson := TLesson.Create(FData[w][d][l], li, nil);
FData[w][d][l].ReadyLessons.Add(rdy_Lesson);
AllLessons.Add(rdy_Lesson);
Result := true;
exit;
end;
end;
end;
Result := false;
end;
{ TLoadItem }
constructor TLoadItem.Create( LoadID : Integer; Teacher: TTeacher; Group: TGroup; NeedPC : Boolean);
begin
self.LoadID := LoadID;
self.Teacher := Teacher;
self.Group := Group;
self.NeedPC := NeedPC;
self.Checked := false;
end;
{ TSubject }
constructor TSubject.Create(SubjectID: Integer);
begin
self.SubjectId := SubjectID;
end;
{ TLesson }
constructor TLesson.Create(aParent : TCurrentLesson; aLoadItem: TLoadItem; aRoom: TRoom);
begin
self.Parent := aParent;
self.LoadItem := aLoadItem;
self.Room := aRoom;
end;
end.