private void button1_Click(object sender, EventArgs e) { foreach (var c in table.Controls) { if (c.GetType().Name == "TextBox") { if (((TextBox)c).Text == String.Empty) { MessageBox.Show("Заполните все поля"); return; } } } var radios = table.Controls.OfType <RadioButton>().ToList(); var checks = table.Controls.OfType <CheckBox>().ToList(); var texts = table.Controls.OfType <TextBox>().ToList(); using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { if (multiChoice == true) { for (int i = 0; i < texts.Count; i++) { TestAppLibrary.Answer ans = new TestAppLibrary.Answer { Challenge = texts[i].Text, IsRight = checks[i].Checked, Question = db.Questions.Where(k => k.Id == id).First() }; db.Answers.Add(ans); } } else if (multiChoice == false) { for (int i = 0; i < texts.Count; i++) { TestAppLibrary.Answer ans = new TestAppLibrary.Answer { Challenge = texts[i].Text, IsRight = radios[i].Checked, Question = db.Questions.Where(k => k.Id == id).First() }; db.Answers.Add(ans); } } db.SaveChanges(); form.TreeViewFill(); this.DialogResult = DialogResult.OK; this.Close(); } }
private void button1_Click(object sender, EventArgs e) { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { var exam = db.Exams.Where(i => i.Id == id).First(); if (numericUpDown1.Value < numericUpDown2.Value) { MessageBox.Show("Количество вопросов не совпадает с количеством ответов"); return; } exam.QuestionNumber = (int)numericUpDown1.Value; exam.QuestionToPass = (int)numericUpDown2.Value; exam.Name = textBox2.Text; exam.TimeToPass = dateTimePicker1.Value.Hour * 60 + dateTimePicker1.Value.Minute; db.SaveChanges(); form.TreeViewFill(); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { var subject = db.Subjects.Where(i => i.Id == id).First(); if (textBox1.Text == String.Empty) { MessageBox.Show("Введите название предмета"); return; } var temp = db.Subjects.Where(i => i.Name == textBox1.Text).FirstOrDefault(); if (temp == null) { subject.Name = textBox1.Text; db.SaveChanges(); form.TreeViewFill(); this.Close(); } } }
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(); } }
private void btnOk_Click(object sender, EventArgs e) { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { var temp = db.Subjects.Where(i => i.Name == textBox1.Text).FirstOrDefault(); if (temp == null) { TestAppLibrary.Subject sub = new TestAppLibrary.Subject { Name = textBox1.Text }; db.Subjects.Add(sub); db.SaveChanges(); form.TreeViewFill(); this.Close(); } else { MessageBox.Show("Такой предмет уже есть"); return; } } }