/
Form1.cs
488 lines (451 loc) · 21.6 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Experiment.Screens;
namespace Experiment
{
public delegate void NextScreenDelegate();
public delegate void KeyDownPressed(KeyEventArgs e);
public partial class Form1 : Form
{
private UserControl[] Screens;
private int[] currentUserScreensIndexes;
//private int[] group1ScreenOrder = { 1, 2, 5, 6, 7, 6, 8, 9, 10, 11 }; // Guy: removed group 1 screen order
private int[] group2ScreenOrder = { 1, 3, 4, 12, 5, 6, 13, 3, 4, 12, 6, 8, 9, 10, 11 }; // 12 = HatramaEnd Guy: added screen 13 - Thunot
// private int[] group2ScreenOrder = { 1, 3, 4, 12, 13 , 8, 9, 10, 11 }; // Guy: for version without math part
private KeyDownPressed currentKeyDownReceiver;
private ResultsLogger oResultsLogger;
private int iScreenIndex;
private Tester oCurrentTester;
private int iCurrentMathTestNum;
private int iCurrentHatrama;
private string sMath1XmlPath = "xml/Math1.xml"; //"C:\\Users\\Lior\\documents\\visual studio 2010\\Projects\\Experiment\\Experiment\\xml\\Math1.xml";
private string sMath2XmlPath = "xml/Math2.xml"; //"C:\\Users\\Lior\\documents\\visual studio 2010\\Projects\\Experiment\\Experiment\\xml\\Math2.xml";
private int[] mathTestMinutes = { 20, 15 }; // is set again from preferences in loaddata()
private bool bWroteFile = false;
private int iHatramaNumber = 1;
public Form1()
{
InitializeComponent();
LoadData();
Properties.Settings.Default.Folder_saveResults = "results/";
}
private void LoadData()
{
try
{
TextsGlobal.PathToXml = "xml/TextsGlobal.xml"; //"C:\\Users\\Lior\\documents\\visual studio 2010\\Projects\\Experiment\\Experiment\\xml\\TextsGlobal.xml";
Testers.PathToXml = "xml/testers.xml"; //"C:\\Users\\Lior\\documents\\visual studio 2010\\Projects\\Experiment\\Experiment\\xml\\testers.xml";
Preferences.PathToXml = "xml/Preferences.xml";
mathTestMinutes[0] = int.Parse(Preferences.GetPreference("math1TimeMinuts"));
mathTestMinutes[1] = int.Parse(Preferences.GetPreference("math2TimeMinuts"));
oResultsLogger = new ResultsLogger();
iScreenIndex = 0;
iCurrentMathTestNum = 1;
iCurrentHatrama = 1;
// initialize screens
Screen1Opening Screen1 = new Screen1Opening();
Screen2KtivaAlArachim Screen2 = new Screen2KtivaAlArachim();
Screen3HatramaIntro Screen3 = new Screen3HatramaIntro();
Screen4Hatrama Screen4 = new Screen4Hatrama();
Screen5MathIntro Screen5 = new Screen5MathIntro();
Screen6Math Screen6 = new Screen6Math();
Screen7Arachim2 Screen7 = new Screen7Arachim2();
Screen8SheelonZminut Screen8 = new Screen8SheelonZminut();
Screen9LexicalDecision Screen9 = new Screen9LexicalDecision();
ScreenLastQuestion ScreenLastQuestion = new Experiment.Screens.ScreenLastQuestion();
Screen10End Screen10 = new Screen10End();
Screen11Thunot Screen11 = new Screen11Thunot();
ScreenHatramaEnd Screen12 = new ScreenHatramaEnd();
Screen1.Dock = DockStyle.Fill;
Screen2.Dock = DockStyle.Fill;
Screen3.Dock = DockStyle.Fill;
Screen4.Dock = DockStyle.Fill;
Screen5.Dock = DockStyle.Fill;
Screen6.Dock = DockStyle.Fill;
Screen7.Dock = DockStyle.Fill;
Screen8.Dock = DockStyle.Fill;
Screen9.Dock = DockStyle.Fill;
ScreenLastQuestion.Dock = DockStyle.Fill;
Screen10.Dock = DockStyle.Fill;
Screen11.Dock = DockStyle.Fill;
Screen12.Dock = DockStyle.Fill;
Screen1.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen2.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen3.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen4.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen5.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen6.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen7.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen8.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen9.NextScreen += new NextScreenDelegate(GotoNextScreen);
ScreenLastQuestion.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen10.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen11.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screen12.NextScreen += new NextScreenDelegate(GotoNextScreen);
Screens = new UserControl[] { Screen1, Screen2, Screen3, Screen4, Screen5, Screen6, Screen7, Screen8, Screen9, ScreenLastQuestion, Screen10, Screen12, Screen11 };
// insert all to main form
foreach (UserControl uc in Screens)
{
this.Controls.Add(uc);
}
// show first screen
LoadScreen(1);
}
catch (Exception ex)
{
MessageBox.Show("Problem loading form:" + Environment.NewLine + ex.Message);
}
}
private void ResetApplication() // not in use
{
try
{
oResultsLogger = new ResultsLogger();
iScreenIndex = 0;
iCurrentMathTestNum = 1;
iCurrentHatrama = 1;
// reset all screens
((Screen1Opening)Screens[0]).ResetScreen();
((Screen2KtivaAlArachim)Screens[1]).ResetScreen();
((Screen3HatramaIntro)Screens[2]).ResetScreen();
((Screen4Hatrama)Screens[3]).ResetScreen();
((Screen5MathIntro)Screens[4]).ResetScreen();
((Screen6Math)Screens[5]).ResetScreen();
((Screen7Arachim2)Screens[6]).ResetScreen();
((Screen8SheelonZminut)Screens[7]).ResetScreen();
((Screen9LexicalDecision)Screens[8]).ResetScreen();
((Screen11Thunot)Screens[10]).ResetScreen();
// show first screen
LoadScreen(1);
}
catch { }
}
private void ShowScreen(int iScreenNum)
{
// hide all screens
foreach (UserControl oUC in Screens)
{
oUC.Visible = false;
}
// show the Screen
Screens[iScreenNum - 1].Visible = true;
}
private void LoadScreen(int iScreenNum)
{
// set keydown to no action
currentKeyDownReceiver = new KeyDownPressed(OnKeyDownPressedNoAction);
Cursor.Current = Cursors.WaitCursor;
switch (iScreenNum)
{
case 1:
((Screen1Opening)Screens[0]).LoadScreen();
break;
case 2:
((Screen2KtivaAlArachim)Screens[1]).LoadScreen();
break;
case 3:
Screen3HatramaIntro oScreen3HatramaIntro = (Screen3HatramaIntro)Screens[2];
if (iHatramaNumber == 1)
{
oScreen3HatramaIntro.TheText = Texts.GetScreenText(2, 0);
}
else
{
oScreen3HatramaIntro.TheText = Texts.GetScreenText(2, 1);
}
oScreen3HatramaIntro.LoadScreen();
break;
case 4:
// Guy: general: the veriable HatramaWord is used as a sign for Screen4Hatrama, whether to use the Person veriable or an array of words/
((Screen4Hatrama)Screens[3]).Person = oCurrentTester.familiar_name;
((Screen4Hatrama)Screens[3]).HatramaWord = "noWord";
// Guy: group 4 gets unfamiliar_name for hatrama
if (oCurrentTester.Group == 4)
{
((Screen4Hatrama)Screens[3]).Person = oCurrentTester.unfamiliar_name;
}
//Guy: set the number of tests according to group
if (oCurrentTester.Group == 1)
{
((Screen4Hatrama)Screens[3]).numOfTests = int.Parse(Preferences.GetPreference("hatramaNumberOfTestsGroup1and2"));
((Screen4Hatrama)Screens[3]).HatramaWord = "group1array"; // array of words for group1
}
else if (oCurrentTester.Group == 2)
{
((Screen4Hatrama)Screens[3]).numOfTests = int.Parse(Preferences.GetPreference("hatramaNumberOfTestsGroup1and2"));
((Screen4Hatrama)Screens[3]).HatramaWord = "group2array"; // array of words for group2
}
else if (oCurrentTester.Group == 3 || oCurrentTester.Group == 4)// groups 3 & 4 only 20 hatrama steps
{
((Screen4Hatrama)Screens[3]).numOfTests = int.Parse(Preferences.GetPreference("hatramaNumberOfTestsGroup3and4"));
}
//else if (oCurrentTester.Group == 3) // gets only unfamiliar_name, the hatrama will choose between Person and HatramaWord but it will always be unfamiliar_name
//{
// ((Screen4Hatrama)Screens[3]).Person = oCurrentTester.unfamiliar_name;
// ((Screen4Hatrama)Screens[3]).HatramaWord = oCurrentTester.unfamiliar_name;
//}
//else if (oCurrentTester.Group == 4) // gets only familiar_name, the hatrama will choose between Person and HatramaWord but it will always be familiar_name
//{
// ((Screen4Hatrama)Screens[3]).Person = oCurrentTester.familiar_name;
// ((Screen4Hatrama)Screens[3]).HatramaWord = oCurrentTester.familiar_name;
//}
//else
//{
// ((Screen4Hatrama)Screens[3]).Person = oCurrentTester.familiar_name;
// ((Screen4Hatrama)Screens[3]).HatramaWord = TextsGlobal.GetText("HatramaSafeBase");
//}
currentKeyDownReceiver = new KeyDownPressed(((Screen4Hatrama)Screens[3]).OnKeyDownPressed);
((Screen4Hatrama)Screens[3]).LoadScreen();
break;
case 5:
((Screen5MathIntro)Screens[4]).IsHard = false;
if (oCurrentTester.Group == 1 || oCurrentTester.Group == 5)
{
((Screen5MathIntro)Screens[4]).IsHard = true;
}
((Screen5MathIntro)Screens[4]).LoadScreen();
break;
case 6:
((Screen6Math)Screens[5]).LoadScreen();
if (iCurrentMathTestNum == 1)
{
((Screen6Math)Screens[5]).LoadTest(sMath1XmlPath, mathTestMinutes[0]);
}
else if (iCurrentMathTestNum == 2)
{
((Screen6Math)Screens[5]).LoadTest(sMath2XmlPath, mathTestMinutes[1]);
}
break;
case 7:
((Screen7Arachim2)Screens[6]).Logger = oResultsLogger;
((Screen7Arachim2)Screens[6]).LoadScreen();
break;
case 8:
((Screen8SheelonZminut)Screens[7]).LoadScreen();
break;
case 9:
currentKeyDownReceiver = new KeyDownPressed(((Screen9LexicalDecision)Screens[8]).OnKeyDownPressed);
((Screen9LexicalDecision)Screens[8]).LoadScreen();
break;
case 10:
((ScreenLastQuestion)Screens[9]).LoadScreen();
break;
case 11:
((Screen10End)Screens[10]).LoadScreen();
break;
case 12:
((ScreenHatramaEnd)Screens[11]).LoadScreen();
break;
case 13:
((Screen11Thunot)Screens[12]).LoadScreen();
break;
}
ShowScreen(iScreenNum);
Cursor.Current = Cursors.Default;
}
/// <summary>
/// this function is being called when we are out of a screen, and want to go to the next one
/// </summary>
private void GotoNextScreen()
{
if (iScreenIndex == 0)
{
// get id, search for it.
try
{
oCurrentTester = Testers.GetTester(((Screen1Opening)Screens[0]).IdNumber);
if (oCurrentTester == null)
{
MessageBox.Show(TextsGlobal.GetText("ErrorIdNotExist"));
}
else
{
/*if (oCurrentTester.Group == 1)
{
currentUserScreensIndexes = group1ScreenOrder;
}
else
{
currentUserScreensIndexes = group2ScreenOrder;
}
*/
// Guy: removed group 1 screen order
currentUserScreensIndexes = group2ScreenOrder;
if (oCurrentTester.Gender == "female")
{
Texts.PathToXml = "xml/Texts_female.xml";
((Screen8SheelonZminut)Screens[7]).XMLPath = "xml/Sheelon_female.xml";
((Screen11Thunot)Screens[12]).XMLPath = "xml/Thunot_female.xml"; //Guy: set Thunot xml name
}
else
{
Texts.PathToXml = "xml/Texts_male.xml";
((Screen8SheelonZminut)Screens[7]).XMLPath = "xml/Sheelon_male.xml";
((Screen11Thunot)Screens[12]).XMLPath = "xml/Thunot_male.xml"; //Guy: set Thunot xml name
}
// add data to logger
oResultsLogger.familiar_name = oCurrentTester.familiar_name;
oResultsLogger.Gender = oCurrentTester.Gender;
oResultsLogger.Group = oCurrentTester.Group;
oResultsLogger.Id = oCurrentTester.Id;
oResultsLogger.unfamiliar_name = oCurrentTester.unfamiliar_name;
oResultsLogger.oTesterDatetime = DateTime.Now;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
}
catch (Exception ex)
{
}
}
else if (currentUserScreensIndexes[iScreenIndex] == 2)
{
oResultsLogger.screen2_ChosenArachim = ((Screen2KtivaAlArachim)Screens[1]).ChosenArachim;
oResultsLogger.screen2_notes = ((Screen2KtivaAlArachim)Screens[1]).Notes;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 3)
{
iHatramaNumber++;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 4)
{
if (iCurrentHatrama == 1)
{
oResultsLogger.screen4Hatrama_result = ((Screen4Hatrama)Screens[3]).Result;
}
else if (iCurrentHatrama == 2)
{
oResultsLogger.screen4Hatrama_again_result = ((Screen4Hatrama)Screens[3]).Result;
}
// goto next screen
iScreenIndex++;
iCurrentHatrama++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 12) // Hatrama end
{
if (iCurrentHatrama == 2) // after 1st hatrama
{
oResultsLogger.screenHatramaEnd_1_Answer1 = ((ScreenHatramaEnd)Screens[11]).Answer1;
oResultsLogger.screenHatramaEnd_1_Answer2 = ((ScreenHatramaEnd)Screens[11]).Answer2;
oResultsLogger.screenHatramaEnd_1_Answer3 = ((ScreenHatramaEnd)Screens[11]).Answer3;
}
if (iCurrentHatrama == 3) // after 2nd hatrama
{
oResultsLogger.screenHatramaEnd_2_Answer1 = ((ScreenHatramaEnd)Screens[11]).Answer1;
oResultsLogger.screenHatramaEnd_2_Answer2 = ((ScreenHatramaEnd)Screens[11]).Answer2;
oResultsLogger.screenHatramaEnd_2_Answer3 = ((ScreenHatramaEnd)Screens[11]).Answer3;
}
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 5)
{
oResultsLogger.screen5MathIntro_Gender = ((Screen5MathIntro)Screens[4]).Gender;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 6)
{
if (iCurrentMathTestNum == 1)
{
oResultsLogger.screen6Math_1_result = ((Screen6Math)Screens[5]).Result;
}
else if (iCurrentMathTestNum == 2)
{
oResultsLogger.screen6Math_2_result = ((Screen6Math)Screens[5]).Result;
}
// goto next screen
iScreenIndex++;
iCurrentMathTestNum++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 7)
{
oResultsLogger.screen2_notes_again = ((Screen7Arachim2)Screens[6]).Result;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 8)
{
oResultsLogger.screen8Sheelon_result = ((Screen8SheelonZminut)Screens[7]).Result;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 9)
{
oResultsLogger.screen9Lexical_result = ((Screen9LexicalDecision)Screens[8]).Result;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 10) // last question
{
oResultsLogger.screenLastQuestionYourLanguage = ((ScreenLastQuestion)Screens[9]).Result;
oResultsLogger.screenLastQuestionYesNo1 = ((ScreenLastQuestion)Screens[9]).YesNo1Result;
oResultsLogger.screenLastQuestionYesNo2 = ((ScreenLastQuestion)Screens[9]).YesNo2Result;
oResultsLogger.screenLastQuestionYesNo3 = ((ScreenLastQuestion)Screens[9]).YesNo3Result;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
else if (currentUserScreensIndexes[iScreenIndex] == 11)
{
try
{
oResultsLogger.WriteFile();
bWroteFile = true;
}
catch { }
this.Close();
}
//Guy: new screen number 13
else if (currentUserScreensIndexes[iScreenIndex] == 13)
{
oResultsLogger.screen13Sheelon_result = ((Screen11Thunot)Screens[12]).Result;
// goto next screen
iScreenIndex++;
LoadScreen(currentUserScreensIndexes[iScreenIndex]);
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
try
{
currentKeyDownReceiver(e);
}
catch { }
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (!bWroteFile)
{
oResultsLogger.WriteFile();
}
}
catch { }
}
public void OnKeyDownPressedNoAction(KeyEventArgs e)
{
}
}
}