private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtExamID.Text == "")
            {
                MessageBox.Show("Mã kỳ thi rỗng !!!");
                return;
            }
            if (txtExamName.Text == "" || txtFacultyName.Text == "" || quantityQuiz.Value == 0 || quantityTime.Value == 0)
            {
                MessageBox.Show("Vui lòng nhập đủ các thông tin !!!");
                return;
            }
            if (txtNameTeacher.Text != acc.FullName)
            {
                MessageBox.Show("Bạn không có quyền sửa đề thi này!");
                return;
            }
            int idExam = int.Parse(txtExamID.Text.ToString());

            using (var _dbContext = new QuizContextDB())
            {
                Exam exam = _dbContext.Exams.FirstOrDefault(p => p.ExamID == idExam);
                if (exam != null)
                {
                    exam.ExamName  = txtExamName.Text;
                    exam.TotalQuiz = int.Parse(quantityQuiz.Value.ToString());
                    exam.TimeTotal = int.Parse(quantityTime.Value.ToString());
                    exam.SubjectID = cmbSubject.SelectedValue.ToString();
                    _dbContext.SaveChanges();
                }
                MessageBox.Show("Cập nhập thành công");
                ShowDgv();
            }
        }
        private void btnDone_Click(object sender, EventArgs e)
        {
            List <GroupBox>    listGrBox = new List <GroupBox>();
            List <RadioButton> listRdo   = new List <RadioButton>();

            foreach (GroupBox grBox in panelAllQuiz.Controls.OfType <GroupBox>())
            {
                foreach (RadioButton rdo in grBox.Controls.OfType <RadioButton>())
                {
                    if (rdo.Checked == true)
                    {
                        listRdo.Add(rdo);
                        listGrBox.Add(grBox);
                    }
                }
            }

            DialogResult dialogResult = MessageBox.Show("Xác nhận nộp bài ?", "Thông báo", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                using (var _dbContext = new QuizContextDB())
                {
                    foreach (GroupBox grBoxComplite in listGrBox)
                    {
                        foreach (RadioButton rdoBtn in listRdo)
                        {
                            foreach (Answer answer in _dbContext.Answers.ToList()
                                     .Where(p => p.QuizID == int.Parse(grBoxComplite.Name) && p.Correct == 1.ToString() && p.AnswerID == int.Parse(rdoBtn.Name)))
                            {
                                this.demCorrect++;
                            }
                        }
                    }
                    float quantityCorrect = float.Parse(demCorrect.ToString());
                    float pointPerQuiz    = (float)((float)10 / float.Parse(demQuantityQuiz.ToString()));

                    float pointResult = quantityCorrect * pointPerQuiz;

                    Result result = new Result();
                    result.AccountID = acc.AccountID;
                    result.ExamID    = this.examID;
                    result.DateExam  = DateTime.Now;
                    result.Scores    = pointResult;

                    _dbContext.Results.Add(result);
                    _dbContext.SaveChanges();
                    ShowFrmResultExam(result);
                    this.Close();
                }
            }
        }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (txtExamID.Text == "")
     {
         MessageBox.Show("Mã kỳ thi rỗng !!");
         return;
     }
     using (var _dbContext = new QuizContextDB())
     {
         DialogResult dialogResult = MessageBox.Show("Bạn có chắc muốn xóa kỳ thi này ?", "Thông báo", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             int  idExam = int.Parse(txtExamID.Text.ToString());
             Exam exam   = _dbContext.Exams.FirstOrDefault(p => p.ExamID == idExam);
             foreach (Result i in _dbContext.Results.Where(p => p.ExamID == idExam).ToList())
             {
                 _dbContext.Results.Remove(i);
             }
             //foreach (Quiz i in _dbContext.Quizs.Where(p => p.ExamID == idExam).ToList())
             //{
             //    _dbContext.Quizs.Remove(i);
             //}
             if (exam != null)
             {
                 Quiz quiz = _dbContext.Quizs.FirstOrDefault(p => p.ExamID == idExam);
                 if (quiz != null)
                 {
                     Answer answer = _dbContext.Answers.FirstOrDefault(p => p.QuizID == quiz.QuizID);
                     if (answer != null)
                     {
                         _dbContext.Answers.Remove(answer);
                     }
                 }
                 _dbContext.Exams.Remove(exam);
                 _dbContext.SaveChanges();
                 MessageBox.Show("Xóa thành công");
                 ShowDgv();
                 RestDataForm();
             }
         }
         else if (dialogResult == DialogResult.No)
         {
             //do something else
         }
     }
 }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtExamName.Text == "" || txtFacultyName.Text == "" || quantityQuiz.Value == 0 || quantityTime.Value == 0)
     {
         MessageBox.Show("Vui lòng điền đủ thông tin !");
         return;
     }
     if (txtExamID.Text != "")
     {
         this.examID = int.Parse(txtExamID.Text.ToString());
     }
     using (var _dbContext = new QuizContextDB())
     {
         Exam examFind = _dbContext.Exams.FirstOrDefault(p => p.ExamID == this.examID);
         if (examFind == null)
         {
             Exam exam = new Exam()
             {
                 SubjectID  = cmbSubject.SelectedValue.ToString(),
                 ExamName   = txtExamName.Text,
                 AccountID  = acc.AccountID,
                 TimeTotal  = int.Parse(quantityTime.Value.ToString()),
                 TotalQuiz  = int.Parse(quantityQuiz.Value.ToString()),
                 dateCreate = DateTime.Now
             };
             _dbContext.Exams.Add(exam);
             _dbContext.SaveChanges();
             ShowDgv();
             ShowFrmCreateQuiz(exam);
         }
         else
         {
             MessageBox.Show("Mã kỳ thi tồn tại!");
             return;
         }
     }
 }