private void оТкрытьТестДляРедактированияToolStripMenuItem_Click(object sender, EventArgs e) { this.Controls.Clear(); panel1.Controls.Clear(); creating(); openFileDialog1.Filter = "Файлы txt|*.txt|Файлы dat|*.dat"; if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string filename = openFileDialog1.FileName; string[] str = System.IO.File.ReadAllLines(filename); int s = int.Parse(str[1]), s2 = int.Parse(str[2]); n1 = s; n2 = s2; theTask = new tasker[s + 1]; theTask[0] = new tasker(); theTask[0].qwest = str[0]; theTask[0].ansTrue = new int[2]; theTask[0].ansTrue[0] = s; theTask[0].ansTrue[1] = s2; textBox1.Text = theTask[0].qwest; textBox2.Text = theTask[0].ansTrue[0].ToString(); textBox3.Text = theTask[0].ansTrue[1].ToString(); for (int i = 0; i < s; ++i) { theTask[i + 1] = new tasker(); theTask[i + 1].qwest = str[i * 2 * s2 + i + 3]; theTask[i + 1].ans = new string[s2]; theTask[i + 1].ansTrue = new int[s2]; for (int j = 0; j < s2 * 2; ++j) { if (j % 2 == 0) { theTask[i + 1].ans[j / 2] = str[i + i * 2 * s2 + j + 4]; } else { theTask[i + 1].ansTrue[j / 2] = int.Parse(str[i + i * 2 * s2 + j + 4]); } } } createTask(s, s2); for (int i = 0; i < s; ++i) { T[i].Text = theTask[i + 1].qwest; for (int j = 0; j < s2; j++) { t[i * s2 + j].Text = theTask[i + 1].ans[j]; if (theTask[i + 1].ansTrue[j] == 1) { C[i * s2 + j].Checked = true; } } } MessageBox.Show("Файл открыт"); checkd = true; }
private void сохранитьТестToolStripMenuItem_Click(object sender, EventArgs e) { checkd = true; checkd = checker(textBox2.Text, checkd); checkd = checker(textBox3.Text, checkd); if (checkd && n1 == int.Parse(textBox2.Text) && n2 == int.Parse(textBox3.Text)) { int s = int.Parse(textBox2.Text); int s2 = int.Parse(textBox3.Text); int summ = 0; for (int i = 0; i < s; ++i) { for (int j = 0; j < s2; ++j) { if (C[i * s2 + j].Checked == true) { summ++; break; } } } if (summ == s) { saveFileDialog1.InitialDirectory = ""; saveFileDialog1.Filter = "Файлы txt|*.txt|Файлы dat|*.dat"; if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } string filename = saveFileDialog1.FileName; saveFileDialog1.FileName = filename; theTask = new tasker[s + 1]; theTask[0] = new tasker(); if (T[0].Text == "") { theTask[0].qwest = "NoName"; } else { theTask[0].qwest = textBox1.Text; } theTask[0].ansTrue = new int[2]; theTask[0].ansTrue[0] = s; theTask[0].ansTrue[1] = s2; System.IO.File.WriteAllText(filename, theTask[0].qwest + '\n'); System.IO.File.AppendAllText(filename, theTask[0].ansTrue[0].ToString() + '\n'); System.IO.File.AppendAllText(filename, theTask[0].ansTrue[1].ToString() + '\n'); for (int i = 0; i < s; ++i) { theTask[i + 1] = new tasker(); theTask[i + 1].qwest = T[i].Text; System.IO.File.AppendAllText(filename, theTask[i + 1].qwest + '\n'); theTask[i + 1].ansTrue = new int[s2]; theTask[i + 1].ans = new string[s2]; for (int j = 0; j < s2; ++j) { theTask[i + 1].ans[j] = t[i * s2 + j].Text; theTask[i + 1].ansTrue[j] = 0; if (C[i * s2 + j].Checked == true) { theTask[i + 1].ansTrue[j] = 1; } System.IO.File.AppendAllText(filename, theTask[i + 1].ans[j] + '\n'); System.IO.File.AppendAllText(filename, theTask[i + 1].ansTrue[j].ToString() + '\n'); } } MessageBox.Show("Файл сохранен"); checkd = false; } else { MessageBox.Show("Варианты правильных ответов указаны не везде"); } } else { MessageBox.Show("Файл пустой"); } }
public void createTest() { string filename = button2.Text; string[] s = System.IO.File.ReadAllLines(filename); textBox1.Text = s[0]; textBox2.Text = s[1]; N = int.Parse(s[1]); N2 = int.Parse(s[2]); Tsz = new Size(panel1.Width - con * 4, 100); sz = new Size(panel1.Width - con * 4, 60); t = new TextBox[N * N2 + 1]; T = new TextBox[N + 1]; C = new CheckBox[N * N2 + 1]; t[0] = new TextBox(); T[0] = new TextBox(); t[0].Size = sz; T[0].Size = Tsz; int u = (panel1.Size.Width - 2 * con) / (t[0].Size.Width + con / 2); for (int i = 0; i < N; ++i) { int l = 0; T[i] = new TextBox(); T[i].Size = Tsz; T[i].Multiline = true; T[i].Location = new Point(con * 2, i * T[i].Size.Height + i * (N2 * (t[0].Size.Height + 5) + 2 * con) + con); for (int j = 0; j < N2; ++j) { if (j % u == 0) { l = 0; } t[j + i * N2] = new TextBox(); C[j + i * N2] = new CheckBox(); t[j + i * N2].Size = sz; t[j + i * N2].Location = new Point(l * (t[j + i * N2].Size.Width + con / 2) + con * 2, j * (t[j + i * N2].Size.Height + 5) + con + T[i].Size.Height + T[i].Location.Y); C[j + i * N2].Location = new Point(con, j * (t[j + i * N2].Size.Height + 5) + con + T[i].Size.Height + T[i].Location.Y); l++; } } panel1.AutoScroll = true; theTask = new tasker[N]; for (int i = 0; i < N; ++i) { theTask[i] = new tasker(); theTask[i].qwest = s[i * 2 * N2 + i + 3]; theTask[i].ans = new string[N2]; theTask[i].ansTrue = new int[N2]; for (int j = 0; j < N2 * 2; ++j) { if (j % 2 == 0) { theTask[i].ans[j / 2] = s[i + i * 2 * N2 + j + 4]; } else { theTask[i].ansTrue[j / 2] = int.Parse(s[i + i * 2 * N2 + j + 4]); } } } for (int i = 0; i < N; ++i) { T[i].Text = theTask[i].qwest; for (int j = 0; j < N2; j++) { t[i * N2 + j].Text = theTask[i].ans[j]; } } for (int i = 0; i < N; ++i) { panel1.Controls.Add(T[i]); for (int j = 0; j < N2; ++j) { if (theTask[i].ans[j] != "") { panel1.Controls.Add(t[j + i * N2]); panel1.Controls.Add(C[j + i * N2]); } } } }