//При загрузке формы, создается коллекция вопросов, связанная с данным экзаменом и выводится первый вопрос на форму private void FormUserAnswer_Load(object sender, EventArgs e) { try { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { q = db.Questions.Where(i => i.Exam.Id == idExam).ToList(); ex = db.Exams.Where(i => i.Id == idExam).FirstOrDefault(); user = db.Users.Where(i => i.Id == idUser).FirstOrDefault(); TestAppLibrary.Question quest = q[count++]; textBox1.Text = quest.Challenge; Control ctrl; textBox1.ReadOnly = true; table = new TableLayoutPanel(); table.Parent = splitContainer2.Panel1; table.Dock = DockStyle.Fill; table.ColumnCount = 2; table.Padding = new Padding(20, 10, 10, 20); table.AutoScroll = true; int k = 0; ans = db.Answers.Where(i => i.Question.Id == quest.Id).ToList(); for (int j = 0; j < quest.AnswersNumber && j < ans.Count; j++) { if (quest.MultiChoice == false) { ctrl = new RadioButton(); } else { ctrl = new CheckBox(); } ctrl.Parent = table; TextBox t = new TextBox(); t.Parent = table; t.Multiline = true; t.WordWrap = true; t.Size = new Size { Width = 250, Height = 50 }; t.Text = ans[k++].Challenge; } table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20)); //Инициализация и запуск таймера t = new Timer(); t.Interval = 1000; t.Tick += OnTimer; time = new TimeSpan(ex.TimeToPass / 60, ex.TimeToPass % 60, 0); t.Start(); } } catch (Exception e1) { MessageBox.Show(e1.Message); } }
private void FormTestPass_Load(object sender, EventArgs e) { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { q = db.Questions.Where(i => i.Exam.Id == idExam).ToList(); ex = db.Exams.Where(i => i.Id == idExam).FirstOrDefault(); user = db.Users.Where(i => i.Id == idUser).FirstOrDefault(); } textBox1.Text = ex.Name; textBox2.Text = ex.QuestionNumber.ToString(); textBox3.Text = new TimeSpan(ex.TimeToPass / 60, ex.TimeToPass % 60, 0).ToString(); }
private void btnOk_Click(object sender, EventArgs e) { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { TestAppLibrary.Exam ex = new TestAppLibrary.Exam(); ex.Name = textBox1.Text; if (numericUpDown1.Value < numericUpDown2.Value) { MessageBox.Show("Количество вопросов не совпадает с количеством ответов"); return; } ex.QuestionNumber = (int)numericUpDown1.Value; ex.QuestionToPass = (int)numericUpDown2.Value; ex.TimeToPass = dateTimePicker1.Value.Hour * 60 + dateTimePicker1.Value.Minute; ex.Subject = db.Subjects.Where(i => i.Name == (string)comboBox1.SelectedItem).First(); db.Exams.Add(ex); db.SaveChanges(); form.TreeViewFill(); this.Close(); } }