-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUTesting.pas
More file actions
826 lines (741 loc) · 26.7 KB
/
UTesting.pas
File metadata and controls
826 lines (741 loc) · 26.7 KB
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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
unit UTesting;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Xml.xmldom, Xml.XMLIntf,
Xml.Win.msxmldom, Xml.XMLDoc, Vcl.Buttons, Vcl.ExtCtrls;
type
TFTesting = class(TForm)
BLoadTest: TButton;
grpGotov: TGroupBox;
LTestStatus: TLabel;
GInfoStudent: TGroupBox;
GSernameStudent: TGroupBox;
TSernameStudent: TEdit;
GNameStudent: TGroupBox;
TNameStudent: TEdit;
GGroupStudent: TGroupBox;
TGroupStudent: TEdit;
BBeginTest: TButton;
DOpen: TOpenDialog;
xmldoc: TXMLDocument;
btmp: TBitBtn;
btmp1: TBitBtn;
TStatusTest: TLabel;
PTesting: TPanel;
PFirstType: TRadioGroup;
LQSecondType: TListBox;
PSecondType: TGroupBox;
BNextQuestion: TBitBtn;
BFinishedTest: TBitBtn;
PThirdType: TGroupBox;
CThird1: TComboBox;
CThird2: TComboBox;
CThird3: TComboBox;
CThird4: TComboBox;
CThird5: TComboBox;
CThird6: TComboBox;
TextQuestion: TLabel;
LNumQuestShow: TLabel;
LNumQuestHidden: TLabel;
BCorrectUns: TLabel;
PResult: TPanel;
LTStudentName: TLabel;
LTTestTitle: TLabel;
LTStudentGroup: TLabel;
LTStudentResult: TLabel;
LTestTitle: TLabel;
LStudentName: TLabel;
LStudentGroup: TLabel;
LResult: TLabel;
BFinishTest: TButton;
LTCurrentUns: TLabel;
CThird7: TComboBox;
procedure BLoadTestClick(Sender: TObject);
procedure btmpClick(Sender: TObject);
procedure btmp1Click(Sender: TObject);
procedure BBeginTestClick(Sender: TObject);
procedure BNextQuestionClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BFinishTestClick(Sender: TObject);
procedure BFinishedTestClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TCTestController = class
private
public
// ôóíêöÿ îïðåäåëÿåò òåêóùèé íîìåð âîïðîñà
function detNumQuest() : Integer;
// ôóíêöèÿ îïðåäåëÿåò òèï âîïðîñà ïî íîìåðó
function detTypeQuest(numQuest : Integer) : Integer;
// ïðîöåäóðà ïîäãîòàâëèâàåò ïîëå äëÿ âîïðîñà
procedure prepQuestPanel(typeQuest : Byte);
// îáíîâèòü íîìåð âîïðîñà â ìåòêå
procedure updateNumQuestShow(numQuset : Byte);
// îáíîâèòü ñ÷åò÷èê âîïðîñà
procedure updateNumQuestHidden(numQuest : Byte);
// îáíîâèòü òåêñò âîïðîñà
procedure updateTextQuest(numQuest : Byte);
// ïîëó÷èòü íîìåð òåêóùåãî âîïðîñà
function geNumQuestNow() : Byte;
// ïðîâåðÿåì ðóçåëüòàò îòâåòà íà âîïðîñ
function controllQuest() : Boolean;
// ïîèñê âûáðàííîãî îòâåòà ïåðâîãî òèïà
function selectedFirst() : Byte;
// âûâîäèì ñïèñîê âàðèàíòîâ îòâåòîâ âîïðîñà 1 òèï
function showUnswersFirstType(numQuest : Byte) : Boolean;
// âûâîäèì ñïèñîê âàðèàíòîâ îòâåòà âîïðîñîâ 2 òèïà
function showUnswersSecondType(numQuest : Byte) : Boolean;
// âûâîäèì ñïèñîê âàðèíòîâ îòâåòîâ âîïðîñîâ 3 òèïà
function showUnswersThirdType(numQuest : Byte) : Boolean;
procedure showTestResult;
procedure finishTest;
end;
{ ÃËÀÂÍÛÅ ÒÈÏÛ }
TOption = record
id : Integer;
text : String;
correct : Boolean;
end;
TQuestion = record
id : Integer;
text : String;
qtype : Integer;
options : array [1..100] of TOption;
end;
TStudent = record
name : String;
sername : String;
group : String;
proc : Byte;
count_true : Byte;
count_fale : Byte;
proc_result : Byte;
end;
TTest = record
title : String;
questions : array [1..100] of TQuestion;
count_quest : Integer;
load_control: Boolean;
student : TStudent;
begin_time : String;
end_time : string;
end;
{ ÃËÀÂÍÛÅ ÒÈÏÛ ÊÎÍÅÖ }
{ ÎÒÄÅËÜÍÛÅ ÏÐÎÖÅÄÓÐÛ }
{ ÎÒÄÅËÜÍÛÅ ÏÐÎÖÅÄÓÐÛ ÊÎÍÅÖ}
var
FTesting : TFTesting;
OTestController : TCTestController;
password : String = 'szipdj13';
correct_login : Boolean = False;
ATest : TTest;
implementation
{$R *.dfm}
procedure TFTesting.BBeginTestClick(Sender: TObject);
var
control : Boolean;
count_questions , count_unswers : Integer;
i: Integer;
n: Integer;
begin
control := True;
if ATest.load_control <> False then
begin
if (TNameStudent.Text = '') or (TSernameStudent.Text = '') or (TGroupStudent.Text = '')
then control := False;
if control <> false then
begin
count_questions := xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Count;
ATest.count_quest := count_questions;
for i := 0 to count_questions - 1 do
begin
// êîëè÷åñòâî âàðèàíòîâ îòâåòîâ
count_unswers := xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['unswers'].ChildNodes.Count;
// ñîõðàíÿåì âîïðîñû
ATest.questions[i+1].id :=StrToInt(xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['id'].Text);
ATest.questions[i+1].text := xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['title'].text;
ATest.questions[i+1].qtype := StrToInt(xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['type'].text);
// ñîõðàíÿåì âàðèàíòû îòâåòîâ âîïðîñîâ
for n := 0 to count_unswers - 1 do
begin
ATest.questions[i+1].options[n+1].id := StrToInt(xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['unswers'].ChildNodes.Nodes[n].ChildNodes['id'].Text);
ATest.questions[i+1].options[n+1].text := xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['unswers'].ChildNodes.Nodes[n].ChildNodes['title'].Text;
ATest.questions[i+1].options[n+1].correct := StrToBool(xmldoc.DocumentElement.ChildNodes['questions'].ChildNodes.Nodes[i].ChildNodes['unswers'].ChildNodes.Nodes[n].ChildNodes['correct'].Text);
end;
end;
// Ñîõðàíÿåì äàííûå î ñòóäåíòå
ATest.student.name := FTesting.TNameStudent.Text;
ATest.student.sername := FTesting.TSernameStudent.Text;
ATest.student.group := FTesting.TGroupStudent.Text;
// ñêðûâàåì ïàíåëü
FTesting.GInfoStudent.Visible := false;
// Íà÷èíàåì òåñò
PTesting.Visible := True;
// ïîêàçûâàåì 1 âïîðîñ èç ...
OTestController.updateNumQuestShow(1);
// ñòàðòóåì ñ÷åòöèê âïîðîñîâ
OTestController.updateNumQuestHidden(1);
// âûâîäèì ïåðâûé âîïðîñ
OTestController.updateTextQuest(1);
// ïîäãîòàâëèâàåì ïîëå
OTestController.prepQuestPanel(ATest.questions[1].qtype);
// âûâîäèì âàðèàíòû îòâåòîâ
OTestController.showUnswersFirstType(1);
// Îáíóëÿåì ñ÷åò÷èê ïðàâèëüíûõ îòâåòîâ ñòóäåíòà
ATest.student.count_true := 0;
ATest.student.count_fale := 0;
// ìåíÿåì ñòàòóñ òåñòà
TStatusTest.Caption := '֏!';
end
else TStatusTest.Caption :='Çàïîëíèòå âñå ïîëÿ!';
end
else TStatusTest.Caption := 'Çàãðóçèòå òåñò! Ïàðîëü ó ïðåïîäàâàòåëÿ';
end;
procedure TFTesting.BFinishedTestClick(Sender: TObject);
begin
if MessageDlg('Âû óâåðåíû, ÷òî õîòèòå çàâåðøèòü òåñòèðîâàíèå?',mtError, mbOKCancel, 0) = mrOk then
begin
OTestController.showTestResult;
end;
end;
procedure TFTesting.BFinishTestClick(Sender: TObject);
begin
OTestController.finishTest;
end;
procedure TFTesting.BLoadTestClick(Sender: TObject);
var
pass : String;
xmlt : TXMLDocument;
control : Boolean;
begin
// äåëàòü ëè ïðîâåðêó ïàðîëÿ
control := True;
if control = True then pass := InputBox('Àâòîðèçàöèÿ' , 'Ââåäèòå ïàðîëü' , '')
else pass := password;
if pass = password then
begin
//correct_login := True;
if DOpen.Execute then
begin
xmldoc.LoadFromFile(DOpen.FileName);
xmldoc.Active := True;
LTestStatus.Caption := xmldoc.DocumentElement.ChildNodes['title'].Text;
ATest.title := LTestStatus.Caption;
ATest.load_control := True;
end
else
begin
LTestStatus.Caption := 'Çàãðóçêà ïðåðâàëàñü';
ATest.load_control := false;
end;
end
else LTestStatus.Caption := 'Íåâåðíûé ïàðîëü';
end;
procedure TFTesting.BNextQuestionClick(Sender: TObject);
var
confirmNext , nowQuest : Integer;
begin
// ïðîâåðÿåì íå çàêîí÷èë ëè ñòóäåíò òåñò
if OTestController.geNumQuestNow <= ATest.count_quest - 1 then
begin
confirmNext := MessageDlg('Ïåðåéòè ê ñëåäóþùåìó âîïðîñó?' , mtConfirmation , mbOKCancel , 0);
if confirmNext = mrOk then
begin
nowQuest := OTestController.geNumQuestNow;
// Ïðîâåðÿåì îòâåò ñòóäåíòà íà âîïðîñà
OTestController.controllQuest;
// îáíîâëÿåì ñ÷åò÷èê íîìåðà âîïðîñà ...
OTestController.updateNumQuestShow(nowQuest + 1);
// ñòàðòóåì ñ÷åòöèê âïîðîñîâ
OTestController.updateNumQuestHidden(nowQuest + 1);
// âûâîäèì âûâîäèì ñëåäóþé âîïðîñ
OTestController.updateTextQuest(nowQuest + 1);
// ïîäãîòàâëèâàåì ïîëå è âûâîäèì âàðèíòû îòâåòîâ
OTestController.prepQuestPanel(ATest.questions[nowQuest + 1].qtype);
end
else if confirmNext = mrCancel then
begin
//ShowMessage('Áûëà íàæàòà êíîïêà Cancel');
end;
end
else
begin
nowQuest := OTestController.geNumQuestNow;
// Ïðîâåðÿåì îòâåò ñòóäåíòà íà âîïðîñà
OTestController.controllQuest;
// Ïîëó÷àåì ðåçóëüòàò
OTestController.showTestResult;
end;
end;
// òåñòîâàÿ êíîïêà
procedure TFTesting.btmp1Click(Sender: TObject);
begin
xmldoc.Active := True;
ShowMessage(xmldoc.DocumentElement.ChildNodes['title'].Text);
xmldoc.Active := False;
end;
// òåñòîâàÿ êíîïêà
procedure TFTesting.btmpClick(Sender: TObject);
begin
xmldoc.Active := True;
ShowMessage(xmldoc.DocumentElement.ChildNodes['title'].Text);
xmldoc.Active := False;
end;
procedure TFTesting.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
{ TTestController }
// Ïðîâåðÿåì îòâåòû íà âîïðîñ
function TCTestController.controllQuest: Boolean;
var
nowQuest , typeQuest , i , countOptions , val : Integer;
control : Boolean;
begin
nowQuest := geNumQuestNow();
typeQuest := detTypeQuest(nowQuest);
case typeQuest of
// 1 true unswer
0 : begin
if ATest.questions[nowQuest].options[selectedFirst()].correct = true then
begin
// Ïîêàçûâàåì êîëè÷åñòâî ïðàâèëüíûõ îòâåòîâ
FTesting.BCorrectUns.Caption := IntToStr(StrToInt(FTesting.BCorrectUns.Caption) + 1);
// Ïîïîëíÿåì ñ÷åò÷èê ïðàâèëüíûõ îòâåòîâ
ATest.student.count_true := ATest.student.count_true + 1;
Result := True;
end
else
begin
//ShowMessage('Uncurrect unswer!');
ATest.student.count_fale := ATest.student.count_fale + 1;
Result := False;
end;
end;
// some true unswers
1 : begin
control := True;
// Ïðîâåðÿåì âûäåëåííûå ýåëåìåíòû
for i:=0 to FTesting.LQSecondType.Items.Count-1 do
begin
If FTesting.LQSecondType.Selected[i] then
begin
if ATest.questions[nowQuest].options[i+1].correct <> True then
control := False;
end
else
begin
if ATest.questions[nowQuest].options[i+1].correct = True then
control := False;
end;
end;
if control = false then
begin
ATest.student.count_fale := ATest.student.count_fale + 1;
Result := False;
end
else
begin
// Ïîêàçûâàåì êîëè÷åñòâî ïðàâèëüíûõ îòâåòîâ
ATest.student.count_true := ATest.student.count_true + 1;
// Ïîêàçûâàåì êîëè÷åñòâî ïðàâèëüíûõ îòâåòîâ
FTesting.BCorrectUns.Caption := IntToStr(StrToInt(FTesting.BCorrectUns.Caption) + 1);
Result := True;
end;
end;
// correct order
2 : begin
control := True;
// Ñ÷èòàåì êîëè÷åñòâî âàðèàíòîâ îòâåòîâ òåêóùåãî âîïðîñà
countOptions := 0;
for i := 1 to Length(ATest.questions[nowQuest].options) do
if ATest.questions[nowQuest].options[i].id <> 0 then
countOptions := countOptions + 1;
case countOptions of
2 : begin
val := Integer(FTesting.CThird1.Items.Objects[FTesting.CThird1.ItemIndex]);
if val <> 1 then control := False;
val := Integer(FTesting.CThird2.Items.Objects[FTesting.CThird2.ItemIndex]);
if val <> 2 then control := False;
end;
3 : begin
val := Integer(FTesting.CThird1.Items.Objects[FTesting.CThird1.ItemIndex]);
if val <> 1 then control := False;
val := Integer(FTesting.CThird2.Items.Objects[FTesting.CThird2.ItemIndex]);
if val <> 2 then control := False;
val := Integer(FTesting.CThird3.Items.Objects[FTesting.CThird3.ItemIndex]);
if val <> 3 then control := False;
end;
4 : begin
val := Integer(FTesting.CThird1.Items.Objects[FTesting.CThird1.ItemIndex]);
if val <> 1 then control := False;
val := Integer(FTesting.CThird2.Items.Objects[FTesting.CThird2.ItemIndex]);
if val <> 2 then control := False;
val := Integer(FTesting.CThird3.Items.Objects[FTesting.CThird3.ItemIndex]);
if val <> 3 then control := False;
val := Integer(FTesting.CThird4.Items.Objects[FTesting.CThird4.ItemIndex]);
if val <> 4 then control := False;
end;
5 : begin
val := Integer(FTesting.CThird1.Items.Objects[FTesting.CThird1.ItemIndex]);
if val <> 1 then control := False;
val := Integer(FTesting.CThird2.Items.Objects[FTesting.CThird2.ItemIndex]);
if val <> 2 then control := False;
val := Integer(FTesting.CThird3.Items.Objects[FTesting.CThird3.ItemIndex]);
if val <> 3 then control := False;
val := Integer(FTesting.CThird4.Items.Objects[FTesting.CThird4.ItemIndex]);
if val <> 4 then control := False;
val := Integer(FTesting.CThird5.Items.Objects[FTesting.CThird5.ItemIndex]);
if val <> 5 then control := False;
end;
6 : begin
val := Integer(FTesting.CThird1.Items.Objects[FTesting.CThird1.ItemIndex]);
if val <> 1 then control := False;
val := Integer(FTesting.CThird2.Items.Objects[FTesting.CThird2.ItemIndex]);
if val <> 2 then control := False;
val := Integer(FTesting.CThird3.Items.Objects[FTesting.CThird3.ItemIndex]);
if val <> 3 then control := False;
val := Integer(FTesting.CThird4.Items.Objects[FTesting.CThird4.ItemIndex]);
if val <> 4 then control := False;
val := Integer(FTesting.CThird5.Items.Objects[FTesting.CThird5.ItemIndex]);
if val <> 5 then control := False;
val := Integer(FTesting.CThird6.Items.Objects[FTesting.CThird6.ItemIndex]);
if val <> 6 then control := False;
end;
end;
if control <> false then
begin
// Ïîêàçûâàåì êîëè÷åñòâî ïðàâèëüíûõ îòâåòîâ
ATest.student.count_true := ATest.student.count_true + 1;
// Ïîêàçûâàåì êîëè÷åñòâî ïðàâèëüíûõ îòâåòîâ
FTesting.BCorrectUns.Caption := IntToStr(StrToInt(FTesting.BCorrectUns.Caption) + 1);
Result := True;
end
else begin
ATest.student.count_fale := ATest.student.count_fale + 1;
Result := False;
end;
end;
end;
end;
function TCTestController.detNumQuest: Integer;
begin
Result := StrToInt(FTesting.LNumQuestHidden.Caption);
end;
function TCTestController.detTypeQuest(numQuest: Integer): Integer;
begin
Result := ATest.questions[numQuest].qtype;
end;
// ïðîñåäóðà ñîõðàíÿåò ðåçóëüòàòû è çàïóñêàåò çàíîâî òåñò
procedure TCTestController.finishTest;
var
fileData , fileName : string;
logFile : TextFile;
i , n : Integer;
begin
fileName := 'C:\log.txt';
fileData := DateToStr(Now) + ' ' + TimeToStr(Now)+ ' ' +ATest.student.group+ ' ' +ATest.student.name+ ' ' +ATest.student.sername+ ' '+IntToStr(ATest.student.proc_result)+'%'+ ' ' + ATest.title;
if FileExists(fileName) then
begin
AssignFile(logFile , fileName);
Append(logFile);
Writeln(logFile , fileData);
CloseFile(logFile);
end
else
begin
AssignFile(logFile , fileName);
Rewrite(logFile);
Writeln(logFile , fileData);
CloseFile(logFile);
end;
// ñêðûâàåì ïàíåëè âîïðîñîâ
FTesting.PFirstType.Visible := False;
FTesting.PSecondType.Visible := False;
FTesting.PThirdType.Visible := False;
// è ðåçóëüòàòà
FTesting.PResult.Visible := False;
// ïîêàçûâàåì ïàíåëü çàïîëíåíèÿ äàííûõ
FTesting.GInfoStudent.Visible := True;
// î÷èùàåì äàííûå ïðåäûäóùåãî ñòóäåíòà
FTesting.TSernameStudent.Text := '';
FTesting.TNameStudent.Text := '';
FTesting.TGroupStudent.Text := '';
for i := 1 to 100 do
begin
ATest.questions[i].id := 0;
ATest.questions[i].text := '';
ATest.questions[i].qtype := 0;
for n := 1 to 100 do
begin
ATest.questions[i].options[n].id := 0;
ATest.questions[i].options[n].text:= '';
ATest.questions[i].options[n].correct := false;
end;
end;
// ñ÷åò÷èê ïðàâèëüíûõ îòâåòîâ ñòàâèì íà íîëü
FTesting.BCorrectUns.Caption := '0';
//ATest.title := '';
//ATest.count_quest := 0;
//ATest.begin_time := '';
//ATest.end_time := '';
ATest.student.name := '';
ATest.student.sername := '';
ATest.student.group := '';
ATest.student.proc := 0;
ATest.student.count_true := 0;
ATest.student.count_fale := 0;
ATest.student.proc_result := 0;
end;
function TCTestController.geNumQuestNow: Byte;
begin
Result := StrToInt(FTesting.LNumQuestHidden.Caption);
end;
procedure TCTestController.prepQuestPanel(typeQuest : Byte);
begin
case typeQuest of
0 : begin
FTesting.PFirstType.Visible := True;
FTesting.PSecondType.Visible := False;
FTesting.PThirdType.Visible := False;
// âûâîäèì âàðèàíòû îòâåòîâ
OTestController.showUnswersFirstType(geNumQuestNow);
end;
1 : begin
FTesting.PFirstType.Visible := False;
FTesting.PSecondType.Visible := True;
FTesting.PThirdType.Visible := False;
// âûâîäèì âàðèàíòû îòâåòîâ
OTestController.showUnswersSecondType(geNumQuestNow);
end;
2 : begin
FTesting.PFirstType.Visible := False;
FTesting.PSecondType.Visible := False;
FTesting.PThirdType.Visible := True;
// âûâîäèì âàðèàíòû îòâåòîâ
OTestController.showUnswersThirdType(geNumQuestNow);
end;
end;
end;
function TCTestController.selectedFirst: Byte;
begin
Result := FTesting.PFirstType.ItemIndex + 1;
end;
procedure TCTestController.showTestResult;
var
resultProc : Real;
begin
resultProc := 100/ATest.count_quest*ATest.student.count_true;
// ñîõðàíÿåì ðåçóëüòàò â ïðîöåíòàõ
ATest.student.proc_result := Round(resultProc);
FTesting.PTesting.Visible := False;
FTesting.PResult.Visible := True;
FTesting.LTestTitle.Caption := ATest.title;
FTesting.LStudentName.Caption := ATest.student.name + ' ' + ATest.student.sername;
FTesting.LStudentGroup.Caption := ATest.student.group;
FTesting.LResult.Caption := IntToStr(ATest.student.count_true) + '/' + IntToStr(ATest.count_quest) + ' ' + IntToStr(Round(resultProc)) + '%';
end;
function TCTestController.showUnswersFirstType(numQuest: Byte): Boolean;
var
countOptions , i : Byte;
begin
countOptions := 0;
// Óäàëÿåì ïðåäûäóþùèå ýëåìåíòû
for i := 0 to FTesting.PFirstType.Items.Count - 1 do
FTesting.PFirstType.Items.Delete(0);
// Ñ÷èòàåì êîëè÷åñòâî âàðèàíòîâ îòâåòîâ
for i := 1 to Length(ATest.questions[numQuest].options) do
if ATest.questions[numQuest].options[i].id <> 0 then
countOptions := countOptions + 1;
// Âûâîäèì âàðèàíòû îòâåòîâ
for i := 0 to countOptions - 1 do
FTesting.PFirstType.Items.Add(ATest.questions[numQuest].options[i+1].text);
end;
function TCTestController.showUnswersSecondType(numQuest: Byte): Boolean;
var
countOptions , i : Byte;
begin
countOptions := 0;
// Óäàëÿåì ïðåäûäóùèå âàðèàíòû îòâåòîâ
for i := 0 to FTesting.LQSecondType.Items.Count -1 do
FTesting.LQSecondType.Items.Delete(0);
// Ñ÷èòàåì êîëè÷åñòâî âàðèàíòîâ îòâåòîâ òåêóùåãî âîïðîñà
for i := 1 to Length(ATest.questions[numQuest].options) do
if ATest.questions[numQuest].options[i].id <> 0 then
countOptions := countOptions + 1;
// Âûâîäèì âàðèàíòû îòâåòîâ
for i := 0 to countOptions - 1 do
FTesting.LQSecondType.Items.Add(ATest.questions[numQuest].options[i+1].text);
end;
function TCTestController.showUnswersThirdType(numQuest: Byte): Boolean;
var
countOptions , i , tmpId , rnd : Byte;
options : TStringList;
tmpText : string;
begin
// Ñ÷èòàåì êîëè÷åñòâî âàðèàíòîâ îòâåòîâ òåêóùåãî âîïðîñà
countOptions := 0;
rnd := 0;
for i := 1 to Length(ATest.questions[numQuest].options) do
if ATest.questions[numQuest].options[i].id <> 0 then
countOptions := countOptions + 1;
// ïåðåìåøèâàåì ýëåìåíòû îïöèé 5 ðàç
for i := 1 to 5 do
begin
// èçáåãàåì íåñóùåñòâóþùåãî ýëåìåíòà ìàññèâà
while rnd = 0 do rnd := Random(countOptions);
// ñîõðàíÿåì ïðîìåæóòî÷íûå äàííûå
tmpId := ATest.questions[numQuest].options[1].id;
tmpText := ATest.questions[numQuest].options[1].text;
// äåëàåì çàìåíó äàííûõ ýëåìåíòîâ ìàññèâà
ATest.questions[numQuest].options[1].id := ATest.questions[numQuest].options[rnd].id;
ATest.questions[numQuest].options[1].text := ATest.questions[numQuest].options[rnd].text;
ATest.questions[numQuest].options[rnd].id := tmpId;
ATest.questions[numQuest].options[rnd].text := tmpText;
end;
case countOptions of
2 : begin
// Çàïîëíÿåì îáúåêò âàðèàíòàìè îòâåòîâ è èõ èäåíòèôèêàòîðîâ
for i := 1 to countOptions do options.AddObject(ATest.questions[numQuest].options[i].text , TObject(ATest.questions[numQuest].options[i].id));
// Çàíîñèì â combobox
// 1 combobox
FTesting.CThird1.Items.Assign(options);
FTesting.CThird1.ItemIndex := 0;
// 2 combobox
FTesting.CThird2.Items.Assign(options);
FTesting.CThird2.ItemIndex := 0;
// ÷èñòèì
options.Clear;
// óáèðàåì string list
FreeAndNil(options);
// äåëàåì íåâèäèìûìè îñòàëüíûå combobox
FTesting.CThird3.Visible := false;
FTesting.CThird4.Visible := false;
FTesting.CThird5.Visible := false;
FTesting.CThird6.Visible := false;
FTesting.CThird7.Visible := false;
end;
3 : begin
options := TStringList.Create;
// Çàïîëíÿåì îáúåêò âàðèàíòàìè îòâåòîâ è èõ èäåíòèôèêàòîðîâ
for i := 1 to countOptions do options.AddObject(ATest.questions[numQuest].options[i].text , TObject(ATest.questions[numQuest].options[i].id));
// Çàíîñèì â combobox
// 1 combobox
FTesting.CThird1.Items.Assign(options);
FTesting.CThird1.ItemIndex := 0;
// 2 combobox
FTesting.CThird2.Items.Assign(options);
FTesting.CThird2.ItemIndex := 0;
// 3 combobox
FTesting.CThird3.Items.Assign(options);
FTesting.CThird3.ItemIndex := 0;
// ÷èñòèì
options.Clear;
// óáèðàåì string list
FreeAndNil(options);
// äåëàåì íåâèäèìûìè îñòàëüíûå combobox
FTesting.CThird4.Visible := false;
FTesting.CThird5.Visible := false;
FTesting.CThird6.Visible := false;
FTesting.CThird7.Visible := false;
end;
4 : begin
options := TStringList.Create;
// Çàïîëíÿåì îáúåêò âàðèàíòàìè îòâåòîâ è èõ èäåíòèôèêàòîðîâ
for i := 1 to countOptions do options.AddObject(ATest.questions[numQuest].options[i].text , TObject(ATest.questions[numQuest].options[i].id));
// Çàíîñèì â combobox
// 1 combobox
FTesting.CThird1.Items.Assign(options);
FTesting.CThird1.ItemIndex := 0;
// 2 combobox
FTesting.CThird2.Items.Assign(options);
FTesting.CThird2.ItemIndex := 0;
// 3 combobox
FTesting.CThird3.Items.Assign(options);
FTesting.CThird3.ItemIndex := 0;
// 4 combobox
FTesting.CThird4.Items.Assign(options);
FTesting.CThird4.ItemIndex := 0;
// ÷èñòèì
options.Clear;
// óáèðàåì string list
FreeAndNil(options);
FTesting.CThird4.Visible := true;
// äåëàåì íåâèäèìûìè îñòàëüíûå combobox
FTesting.CThird5.Visible := false;
end;
5 : begin
options := TStringList.Create;
// Çàïîëíÿåì îáúåêò âàðèàíòàìè îòâåòîâ è èõ èäåíòèôèêàòîðîâ
for i := 1 to countOptions do options.AddObject(ATest.questions[numQuest].options[i].text , TObject(ATest.questions[numQuest].options[i].id));
// Çàíîñèì â combobox
// 1 combobox
FTesting.CThird1.Items.Assign(options);
FTesting.CThird1.ItemIndex := 0;
// 2 combobox
FTesting.CThird2.Items.Assign(options);
FTesting.CThird2.ItemIndex := 0;
// 3 combobox
FTesting.CThird3.Items.Assign(options);
FTesting.CThird3.ItemIndex := 0;
// 4 combobox
FTesting.CThird4.Items.Assign(options);
FTesting.CThird4.ItemIndex := 0;
// 5 combobox
FTesting.CThird5.Items.Assign(options);
FTesting.CThird5.ItemIndex := 0;
// ÷èñòèì
options.Clear;
// óáèðàåì string list
FreeAndNil(options);
FTesting.CThird5.Visible := true;
end;
6 : begin
options := TStringList.Create;
// Çàïîëíÿåì îáúåêò âàðèàíòàìè îòâåòîâ è èõ èäåíòèôèêàòîðîâ
for i := 1 to countOptions do options.AddObject(ATest.questions[numQuest].options[i].text , TObject(ATest.questions[numQuest].options[i].id));
// Çàíîñèì â combobox
// 1 combobox
FTesting.CThird1.Items.Assign(options);
FTesting.CThird1.ItemIndex := 0;
// 2 combobox
FTesting.CThird2.Items.Assign(options);
FTesting.CThird2.ItemIndex := 0;
// 3 combobox
FTesting.CThird3.Items.Assign(options);
FTesting.CThird3.ItemIndex := 0;
// 4 combobox
FTesting.CThird4.Items.Assign(options);
FTesting.CThird4.ItemIndex := 0;
// 5 combobox
FTesting.CThird5.Items.Assign(options);
FTesting.CThird5.ItemIndex := 0;
// 6 combobox
FTesting.CThird6.Items.Assign(options);
FTesting.CThird6.ItemIndex := 0;
// ÷èñòèì
options.Clear;
// óáèðàåì string list
FreeAndNil(options);
FTesting.CThird5.Visible := true;
FTesting.CThird6.Visible := true;
end;
end;
end;
procedure TCTestController.updateNumQuestHidden(numQuest: Byte);
begin
FTesting.LNumQuestHidden.Caption := IntToStr(numQuest);
end;
procedure TCTestController.updateNumQuestShow(numQuset : Byte);
begin
FTesting.LNumQuestShow.Caption := 'Âîïðîñ ¹ ' + IntToStr(numQuset) + ' èç ' + IntToStr(ATest.count_quest);
end;
procedure TCTestController.updateTextQuest(numQuest: Byte);
begin
FTesting.TextQuestion.Caption := ATest.questions[numQuest].text;
end;
end.