0 / 0 / 0
Регистрация: 17.12.2015
Сообщений: 12
|
|
1
|
Не считывает файл
23.12.2015, 19:24. Показов 689. Ответов 0
Помогите пожалуйста. Есть код, он по идее привязан к форме. Должен считывать данные .txt файла, на форме менять вопрос и варианты ответов. По почему то это не делает. Подскажите как исправит. Вот код:
C# | 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
| namespace Test2
{
public partial class Form1 : Form
{
int schetVoprosov;
int pravilOtvetov;
int nePravilOtvetov;
string[] nePravilOtveti;
int nomerPravilOtveta;
int vibranOtvet;
System.IO.StreamReader Chitatel;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "Следующий вопрос";
button2.Text = "Выход";
radioButton1.CheckedChanged += new EventHandler(IzmSostPerecl);
radioButton2.CheckedChanged += new EventHandler(IzmSostPerecl);
radioButton3.CheckedChanged += new EventHandler(IzmSostPerecl);
radioButton4.CheckedChanged += new EventHandler(IzmSostPerecl);
NachaloTesta();
}
void NachaloTesta()
{
var Codirovka = System.Text.Encoding.GetEncoding(1251);
try
{
Chitatel = new System.IO.StreamReader(
System.IO.Directory.GetCurrentDirectory() +
(@"\Test.txt"), Codirovka);
this.Text = Chitatel.ReadLine();
schetVoprosov = 0; pravilOtvetov = 0; nePravilOtvetov = 0;
nePravilOtveti = new String[100];
}
catch (Exception Situaciya)
{
MessageBox.Show(Situaciya.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
ChitatSledVopros();
}
void ChitatSledVopros()
{
label1.Text = Chitatel.ReadLine();
radioButton1.Text = Chitatel.ReadLine();
radioButton2.Text = Chitatel.ReadLine();
radioButton3.Text = Chitatel.ReadLine();
radioButton4.Text = Chitatel.ReadLine();
nomerPravilOtveta = int.Parse(Chitatel.ReadLine());
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
button1.Enabled = false;
schetVoprosov = schetVoprosov + 1;
if (Chitatel.EndOfStream == true) button1.Text = "Завершить";
}
void IzmSostPerecl(Object sender, EventArgs e)
{
button1.Enabled = true; button1.Focus();
RadioButton Perecluchatel = (RadioButton) sender;
var tmp = Perecluchatel.Name;
vibranOtvet = int.Parse (tmp.Substring(11));
}
private void button1_Click_1(object sender, EventArgs e)
{
if (vibranOtvet == nomerPravilOtveta) pravilOtvetov =
pravilOtvetov +1;
if(vibranOtvet!=nomerPravilOtveta)
{
nePravilOtvetov = nePravilOtvetov +1;
nePravilOtveti[nePravilOtvetov] = label1.Text;
}
if (button1.Text == "Начать тест сначала")
{
button1.Text = "Следующий вопрос";
radioButton1.Visible = true;
radioButton2.Visible = true;
radioButton3.Visible = true;
radioButton4.Visible = true;
NachaloTesta();return;
}
if (button1.Text == "Завершить")
{
Chitatel.Close();
radioButton1.Visible = false;
radioButton2.Visible = false;
radioButton3.Visible = false;
radioButton4.Visible = false;
label1.Text = String.Format("Тестирование завершено.\n"+"Правильных ответов: {0} из {1}.\n"+"Оценка:{2:F2}.",pravilOtvetov,schetVoprosov,(pravilOtvetov*5.0F)/schetVoprosov);
button1.Text = "Начать тест сначала";
var Str = "Список вопросов, н которые выдали"+"Неправильный ответ:\n\n";
for(int i=1; i<= nePravilOtvetov; i++)
Str = Str +nePravilOtveti[i]+ "\n";
if (nePravilOtvetov != 0) MessageBox.Show(Str, "Тестирование завершено");
}
if (button1.Text == "Следующий вопрос") ChitatSledVopros();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
} |
|
0
|