private void SaveExamButton_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Enter exam name!"); } else { using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { Exam exam = new Exam() { ID_subjects = int.Parse(textBox2.Text), Name = textBox1.Text, Exam_date = DateTime.Now }; List <RelationExamsQuestion> relationExamsQuestions = new List <RelationExamsQuestion>(); foreach (int item in questionIdList) { relationExamsQuestions.Add(new RelationExamsQuestion() { ID_exam = exam.ID, ID_Question = item }); } ExamDB.Exams.Add(exam); ExamDB.RelationExamsQuestions.AddRange(relationExamsQuestions); ExamDB.SaveChanges(); } MessageBox.Show("Exam added!"); this.Owner.Show(); this.Close(); } }
private void button1_Click(object sender, EventArgs e) { using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { Question question = new Question() { Name = textBox1.Text, }; Answer answer1 = new Answer() { ID_question = question.ID, QuestionText = FirstAnswerTextBox.Text, CorrectAnswer = checkBox1.Checked }; Answer answer2 = new Answer() { ID_question = question.ID, QuestionText = SecondAnswerTextBox.Text, CorrectAnswer = checkBox2.Checked }; ExamDB.Questions.Add(question); ExamDB.Answers.Add(answer1); ExamDB.Answers.Add(answer2); ExamDB.SaveChanges(); } MessageBox.Show("Question Added!"); }
private void DeleteSubjectButton_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox .Show("Are you sure?", "Deleting group", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { Subject subject = new Subject(); foreach (Subject subject1 in ExamDB.Subjects) { if (subject1.ID == int.Parse(dataGridView1.CurrentRow.Cells["ID"] .Value.ToString())) { subject = subject1; } } ExamDB.RelationSubjectsGroups.RemoveRange(ExamDB.RelationSubjectsGroups .Where(r => r.ID_subject == subject.ID)); ExamDB.RelationTeacherSubjects.RemoveRange(ExamDB.RelationTeacherSubjects .Where(r => r.ID_Subject == subject.ID)); ExamDB.Subjects.Remove(subject); ExamDB.SaveChanges(); } MessageBox.Show("Subject deleted successfully!"); } }
private void button1_Click(object sender, EventArgs e) { using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { RelationTeacherSubject relationTeacherSubject = new RelationTeacherSubject() { ID_teacher = user.ID, ID_Subject = int.Parse(dataGridView1.CurrentRow.Cells["ID"].Value.ToString()) }; ExamDB.RelationTeacherSubjects.Add(relationTeacherSubject); ExamDB.SaveChanges(); } MessageBox.Show("Teacher assigned!"); this.Close(); }
private void RegisterUserButton_Click(object sender, EventArgs e) { foreach (TextBox item in groupBox1.Controls) { if (item.Text.Length == 0) { MessageBox.Show("All fields must be filled!"); return; } } using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { foreach (User user in ExamDB.Users) { if (user.ID == currentUser.ID) { user.Login = LoginTextBox.Text; user.Password = PasswordTextBox.Text; switch (RoleComboBox.SelectedItem) { case "Student": user.ID_roles = 3; break; case "Teacher": user.ID_roles = 2; break; case "Admin": user.ID_roles = 1; break; default: user.ID_roles = 3; break; } user.LName = LNameTextBox.Text; user.FName = FnameTextBox.Text; user.Arrival_date = DateTime.Now; user.Phone = PhoneTextBox.Text; if (dataGridView1.CurrentRow != null) { user.ID_group = Int32.Parse(dataGridView1.CurrentRow.Cells["ID"].Value.ToString()); } } } ExamDB.SaveChanges(); } MessageBox.Show("User edited successfully!"); this.Owner.Show(); this.Close(); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Enter group name!"); } else { using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { Group subject = new Group() { Name = textBox1.Text }; ExamDB.Groups.Add(subject); ExamDB.SaveChanges(); MessageBox.Show("Group added successfully!"); } this.Close(); } }
private void button5_Click(object sender, EventArgs e) { if (dataGridView1.DataSource == null) { MessageBox.Show("Select user to edit!"); } using (ExamTestSystemEntities ExamDB = new ExamTestSystemEntities()) { foreach (User user in ExamDB.Users) { if (user.Login == dataGridView1.CurrentRow.Cells["Login"].Value.ToString()) { ExamDB.Users.Remove(user); } } DialogResult dialogResult = MessageBox.Show("Are you sure?", "Deleting user", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { ExamDB.SaveChanges(); MessageBox.Show("User deleted!"); } } }