Example #1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var _examDao = new ExamDAO();
            var _exam    = _examDao.GetExamById(id);

            if (_exam == null)
            {
                return(HttpNotFound());
            }
            var _listClass = _examDao.GetClassSelected(_exam);

            int[] _selectedClassID = new int[_listClass.Count];
            for (int i = 0; i < _listClass.Count; i++)
            {
                _selectedClassID[i] = _listClass[i].Id;
            }
            _exam.SelectedClassID = _selectedClassID;

            SetClassViewBag(_exam.SelectedClassID);
            SetGradeViewBag(_exam.Subject.GradeID);
            SetSubjectViewBag(_exam.SubjectID);
            SetSchoolYearViewBag(_exam.Subject.Grade.SchoolYearID);
            SetUserViewBag(_exam.UserID);

            return(View(_exam));
        }
Example #2
0
        // GET: admin/exams
        public ActionResult Index(string searchString, int page = 1, int pageSize = 10)
        {
            var _dao   = new ExamDAO();
            var _model = _dao.GetAllExamPageList(searchString, page, pageSize);

            return(View(_model));
        }
        public Result ExamEntry(Exam oExam)
        {
            //new CLogger("Start ExamEntry ExamBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Start ExamEntry ExamBO+BO", ELogLevel.Debug);

            Result oResult = new Result();

            try
            {
                ExamDAO oExamDAO = new ExamDAO();

                oResult = oExamDAO.ExamEntry(oExam);
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultException = oEx;
                oResult.ResultMessage = "Exception occured during Exam Entry..";

                //new CLogger("Exception ExamEntry ExamBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Exception ExamEntry ExamBO+BO", ELogLevel.Debug, oEx);
            }

            //new CLogger("Out ExamEntry ExamBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Out ExamEntry ExamBO+BO", ELogLevel.Debug);

            return oResult;
        }
        public ActionResult Active(string searchString, int page = 1, int pageSize = 10)
        {
            var testModel = new ExamDAO().GetAllExamActivePageList(searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            return(View(testModel));
        }
        public ActionResult Index()
        {
            var _userDao = new UserDAO();
            var _examDao = new ExamDAO();
            var _testDao = new TestDAO();
            var _quizDao = new QuizDAO();

            ViewBag.User = _userDao.GetAllUserActive().Count.ToString();
            ViewBag.Exam = _examDao.GetAllExamActive().Count.ToString();
            ViewBag.Test = _testDao.GetAllTest().Count.ToString();
            ViewBag.Quiz = _quizDao.GetAllQuizActive().Count.ToString();
            return(View());
        }
Example #6
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Exam exam = new ExamDAO().GetExamById(id);

            if (exam == null)
            {
                return(HttpNotFound());
            }
            return(View(exam));
        }
Example #7
0
        public JsonResult GetClassSelected(int?id)
        {
            var _examDao  = new ExamDAO();
            var _classDao = new ClassDAO();

            var _exam      = _examDao.GetExamById(id);
            var _listClass = _examDao.GetClassSelected(_exam);

            int[] _selectedClassID = new int[_listClass.Count];
            for (int i = 0; i < _listClass.Count; i++)
            {
                _selectedClassID[i] = _listClass[i].Id;
            }
            _exam.SelectedClassID = _selectedClassID;
            return(Json(_exam.SelectedClassID, JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public ActionResult Edit(Exam exam)
        {
            if (String.IsNullOrEmpty(exam.Titile))
            {
                ModelState.AddModelError("", "Tiêu đề kỳ thi không được để trống.");
            }

            if (exam.SelectedClassID == null)
            {
                ModelState.AddModelError("", "Vui lòng chọn thí sinh cho kỳ thi này.");
            }
            if (ModelState.IsValid)
            {
                var _session = Session[ConstantVariable.USER_SESSION] as UserLogin;
                var _userDao = new UserDAO();
                var _examDao = new ExamDAO();

                if (_session != null)
                {
                    exam.ModifiedBy = _session.UserName;
                }

                exam.ModifiedDate = DateTime.Now;

                var _result = _examDao.Update(exam, exam.SelectedClassID);
                if (_result)
                {
                    SetAlert("Cập nhật thông tin kỳ thi thành công", "success");
                    new SystemLogDAO().Insert("Cập nhật kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                    return(Redirect("/admin/exams/details/" + exam.Id));
                }
                else
                {
                    SetAlert("Sửa kỳ thi không thành công", "warning");
                    return(RedirectToAction("Index"));
                }
            }

            SetGradeViewBag();
            SetSubjectViewBag(exam.SubjectID);
            SetSchoolYearViewBag();
            SetUserViewBag(exam.UserID);
            SetClassViewBag(exam.SelectedClassID);
            return(View(exam));
        }
        public ActionResult MyTest(string searchString, int page = 1, int pageSize = 10)
        {
            var session = Session[ConstantVariable.USER_SESSION] as UserLogin;

            if (session == null)
            {
                return(Redirect("/user/login"));
            }
            var testModel = new ExamDAO().GetAllExamUserPageList(session.UserID, searchString, page, pageSize);

            ViewBag.SearchString = searchString;
            if (testModel == null)
            {
                SetAlert("Vui lòng đăng nhập.", "error");
                return(Redirect("/"));
            }
            return(View(testModel));
        }
Example #10
0
        //r
        public Result ExamDeleteByStoredProcedure(Exam oExam, SystemUser oSystemUser)
        {
            Result oResult = new Result();

            try
            {
                ExamDAO oExamDAO = new ExamDAO();

                oResult = oExamDAO.ExamDeleteByStoredProcedure(oExam, oSystemUser);
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultException = oEx;
                oResult.ResultMessage = "Exception occured during Exam Delete..";
            }

            return oResult;
        }
Example #11
0
        public ActionResult Create(Exam exam)
        {
            if (CheckInputExam(exam))
            {
                if (ModelState.IsValid)
                {
                    var _session = Session[ConstantVariable.USER_SESSION] as Common.UserLogin;
                    var _userDao = new UserDAO();
                    var _examDao = new ExamDAO();

                    if (_session != null)
                    {
                        exam.UserID = _userDao.GetUserByUserName(_session.UserName).Id;
                    }
                    if (!String.IsNullOrEmpty(exam.Note))
                    {
                        exam.NoteEncode = Encode.StripHTML(exam.Note);
                    }
                    exam.CreatedDate = DateTime.Now;

                    var _result = _examDao.Insert(exam, exam.SelectedClassID);
                    if (_result)
                    {
                        SetAlert("Thêm kỳ thi thành công", "success");
                        new SystemLogDAO().Insert("Thêm kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                        return(Redirect("/admin/exams/details/" + exam.Id));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm kỳ thi không thành công.");
                    }
                }
            }
            SetGradeViewBag();
            SetSubjectViewBag(exam.SubjectID);
            SetSchoolYearViewBag();
            SetUserViewBag(exam.UserID);
            SetClassViewBag(exam.SelectedClassID);
            return(View(exam));
        }
Example #12
0
        //disable window key

        public ExamFrom(Login login)
        {
            Disible d = new Disible();

            InitializeComponent();

            //full screen
            this.TopMost         = true;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState     = FormWindowState.Maximized;
            this.login           = login;
            QuestionDAO qDao = new QuestionDAO();

            listQuestion = qDao.getAllQuestion(login.ExamCode);
            ExamDAO edao = new ExamDAO();

            e = edao.getExam(login.ExamCode);
            //show information
            showInformation();
            //show button to from
            Showbuton();
            display(listQuestionForms[0]);
        }
Example #13
0
        public ActionResult DeleteConfirmed(int id)
        {
            Exam exam     = new ExamDAO().GetExamById(id);
            var  _session = Session[ConstantVariable.USER_SESSION] as UserLogin;

            if (_session != null)
            {
                if (_session.UserID != exam.UserID && _session.UserID != 1)
                {
                    ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: bạn không có quyền xóa kỳ thi này");
                }
            }
            if (exam.TestResultDetails.Count > 0)
            {
                ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: kỳ thi này đã có người thi không thể xóa");
            }
            if (exam.Tests.Count > 0)
            {
                ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: kỳ thi này có đề thi tham chiếu đến");
            }
            if (ModelState.IsValid)
            {
                var result = new ExamDAO().Delete(exam);
                if (result)
                {
                    SetAlert("Xóa kỳ thi thành công", "success");
                    new SystemLogDAO().Insert("Xóa kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                    RedirectToAction("Index", "exams");
                }
                else
                {
                    SetAlert("Xóa kỳ thi không thành công", "warning");
                    RedirectToAction("Index", "exams");
                }
            }
            return(RedirectToAction("Index"));
        }
Example #14
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var _examDao = new ExamDAO();
            var _exam    = _examDao.GetExamById(id);

            if (_exam == null)
            {
                return(HttpNotFound());
            }
            SetUserViewBag(_exam.UserID);
            var _listClass = _examDao.GetClassSelected(_exam);

            int[] _selectedClassID = new int[_listClass.Count];
            for (int i = 0; i < _listClass.Count; i++)
            {
                _selectedClassID[i] = _listClass[i].Id;
            }
            SetClassViewBag(_selectedClassID);
            return(View(_exam));
        }
Example #15
0
        // Chọn câu hỏi
        private bool SelectQuiz(Test test)
        {
            var _exam = new ExamDAO().GetExamById(test.ExamID);

            // Chọn câu hỏi theo kiểu ngẫu nhiên (random)
            if (test.QuizSelection == ConstantVariable.RandomQuiz)
            {
                //Lấy tất cả câu hỏi theo môn học từ kỳ thi đã chọn
                var _quizList    = new QuizDAO().GetAllQuizBySubject(_exam.SubjectID);
                var _codeTestArr = Regex.Split(test.CodeTestArr, ",");                  //Trả về mảng mã đề
                var _session     = Session[ConstantVariable.USER_SESSION] as UserLogin; // Thông tin user đăng nhập

                //Hình thức: không cố định câu hỏi / khác nhau ở mỗi đề
                if (test.FixedOrChanged == ConstantVariable.ChangedQuiz)
                {
                    //Kiểm tra số câu hỏi có đủ hay không
                    if ((test.NumberOfQuestions * _codeTestArr.Length) > _quizList.Count)
                    {
                        ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này.");
                        return(false);
                    }
                    List <int> _quizIdList = new List <int>();
                    for (int i = 0; i < _codeTestArr.Length; i++)
                    {
                        if (!String.IsNullOrEmpty(_codeTestArr[i]))
                        {
                            test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề
                            Random     random = new Random();
                            List <int> _quizIdListByCodeTest = new List <int>();
                            for (int j = 0; j < test.NumberOfQuestions; j++)
                            {
                                int quizId;
                                do
                                {
                                    quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id;
                                } while (_quizIdList.Contains(quizId));
                                _quizIdListByCodeTest.Add(quizId);
                            }

                            test.CreatedBy    = _session.UserID; //Người tạo
                            test.CreatedDate  = DateTime.Now;
                            test.ModifiedDate = DateTime.Now;

                            var r = new TestDAO().Insert(test, _quizIdListByCodeTest);
                            if (r == false)
                            {
                                return(r);
                            }

                            new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                        }
                    }//end:For
                }
                // Hình thức: cố định câu hỏi
                else if (test.FixedOrChanged == ConstantVariable.FixedQuiz)
                {
                    // Kiểm tra số câu hỏi có đủ hay không
                    if (test.NumberOfQuestions > _quizList.Count)
                    {
                        ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này.");
                        return(false);
                    }

                    // Trộn câu hỏi
                    if (test.Mix == ConstantVariable.MixQuiz)
                    {
                        List <int> _quizIdList  = new List <int>();
                        List <int> _quizIdList0 = new List <int>();
                        bool       r            = false;

                        for (int i = 0; i < _codeTestArr.Length; i++)
                        {
                            if (!String.IsNullOrEmpty(_codeTestArr[i]))
                            {
                                test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề
                                Random random = new Random();

                                if (i == 0)
                                {
                                    for (int j = 0; j < test.NumberOfQuestions; j++)
                                    {
                                        int quizId;
                                        do
                                        {
                                            quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id;
                                        } while (_quizIdList.Contains(quizId));
                                        _quizIdList.Add(quizId);

                                        var _quiz = new QuizDAO().GetById(quizId);

                                        _quiz.MixQuiz += "<" + test.CodeTest + ">" + j + "</" + test.CodeTest + ">";

                                        new QuizDAO().UpdateMixQuiz(_quiz);
                                    }

                                    test.CreatedBy    = _session.UserID; //Người tạo
                                    test.CreatedDate  = DateTime.Now;
                                    test.ModifiedDate = DateTime.Now;

                                    r = new TestDAO().Insert(test, _quizIdList);
                                    if (r == false)
                                    {
                                        return(r);
                                    }
                                    _quizIdList0 = _quizIdList.ToList();
                                    new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                                }
                                else
                                {
                                    List <int> _quizIdListMixQuiz = new List <int>();
                                    List <int> _temp = _quizIdList0.ToList();
                                    for (int j = 0; j < test.NumberOfQuestions; j++)
                                    {
                                        int quizId;
                                        int index;
                                        do
                                        {
                                            index  = random.Next(0, _temp.Count - 1);
                                            quizId = _temp[index];
                                        } while (_quizIdListMixQuiz.Contains(quizId));

                                        _quizIdListMixQuiz.Add(quizId);
                                        _temp.RemoveAt(index);
                                        if (j == test.NumberOfQuestions - 1)
                                        {
                                            int _count = 0;
                                            for (int k = 0; k < test.NumberOfQuestions; k++)
                                            {
                                                if (_quizIdListMixQuiz[k] == _quizIdList0[k])
                                                {
                                                    _count++;
                                                }
                                            }
                                            if (_count >= test.NumberOfQuestions)
                                            {
                                                j = -1;
                                                _temp.Clear();
                                                _temp = _quizIdListMixQuiz.ToList();
                                                _quizIdListMixQuiz.Clear();
                                            }
                                        }
                                    }
                                    for (int p = 0; p < _quizIdListMixQuiz.Count; p++)
                                    {
                                        var _quiz = new QuizDAO().GetById(_quizIdListMixQuiz[p]);

                                        _quiz.MixQuiz += "<" + test.CodeTest + ">" + p + "</" + test.CodeTest + ">";

                                        new QuizDAO().UpdateMixQuiz(_quiz);
                                    }
                                    test.CreatedBy    = _session.UserID; //Người tạo
                                    test.CreatedDate  = DateTime.Now;
                                    test.ModifiedDate = DateTime.Now;
                                    r = new TestDAO().Insert(test, _quizIdListMixQuiz);
                                    if (r == false)
                                    {
                                        return(r);
                                    }
                                    test.MixQuiz = true;
                                    new TestDAO().UpdateMixQuiz(test);
                                    new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                                }
                            }
                        } //end:For
                    }     //end-if: trộn câu hỏi

                    //Trộn đáp án
                    else if (test.Mix == ConstantVariable.MixAnswer)
                    {
                        char[]     Alphabet     = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
                        List <int> _quizIdList  = new List <int>();
                        List <int> _quizIdList0 = new List <int>();
                        bool       r            = false;

                        for (int i = 0; i < _codeTestArr.Length; i++)
                        {
                            if (!String.IsNullOrEmpty(_codeTestArr[i]))
                            {
                                test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề
                                Random random = new Random();

                                if (i == 0)
                                {
                                    for (int j = 0; j < test.NumberOfQuestions; j++)
                                    {
                                        int quizId;
                                        do
                                        {
                                            quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id;
                                        } while (_quizIdList.Contains(quizId));
                                        _quizIdList.Add(quizId);
                                        var _quiz = new QuizDAO().GetById(quizId);

                                        _quiz.MixAnswer    += "<" + test.CodeTest + ">" + _quiz.AnswerText + "</" + test.CodeTest + ">";
                                        _quiz.MixKeyAnswer += "<" + test.CodeTest + ">" + _quiz.KeyAnswer + "</" + test.CodeTest + ">";

                                        new QuizDAO().UpdateMixAnswer(_quiz);
                                    }



                                    test.CreatedBy    = _session.UserID; //Người tạo
                                    test.CreatedDate  = DateTime.Now;
                                    test.ModifiedDate = DateTime.Now;

                                    r = new TestDAO().Insert(test, _quizIdList);
                                    if (r == false)
                                    {
                                        return(r);
                                    }
                                    _quizIdList0 = _quizIdList;
                                    new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                                }
                                else //Mix: Answer
                                {
                                    List <int> _temp = _quizIdList0;
                                    for (int j = 0; j < _temp.Count; j++)
                                    {
                                        var           _quiz      = new QuizDAO().GetById(_temp[j]);
                                        var           _answer    = Regex.Split(_quiz.AnswerText, "\r\n").ToList();
                                        List <string> _answerArr = new List <string>();
                                        int           alpha      = 0;
                                        // Remove các giá trị null  hoặc ""
                                        for (int k = 0; k < _answer.Count; k++)
                                        {
                                            if (!String.IsNullOrEmpty(_answer[k]))
                                            {
                                                var strPattern = "" + Alphabet[alpha] + ". ";
                                                _answerArr.Add(Encode.StripAnswerLabel(Encode.StripPTag(_answer[k]), strPattern));
                                                alpha++;
                                            }
                                        }
                                        _quiz.MixAnswer += "<" + test.CodeTest + ">";
                                        int _numChoice = _answerArr.Count;
                                        int indexKey   = 0;
                                        // Lấy index của đáp án
                                        for (int p = 0; p < Alphabet.Length; p++)
                                        {
                                            if (Alphabet[p].ToString() == _quiz.KeyAnswer.ToString())
                                            {
                                                indexKey = p;
                                                break;
                                            }
                                        }
                                        // Trộn đáp án của câu hỏi
                                        for (int k = 0; k < _numChoice; k++)
                                        {
                                            var indexRandom = random.Next(0, _answerArr.Count - 1);
                                            if (!String.IsNullOrEmpty(_answerArr[indexRandom]))
                                            {
                                                _quiz.MixAnswer += "<p>" + Alphabet[k] + ". " + Encode.StripPTag(_answerArr[indexRandom]) + "\r\n</p>";
                                                if (indexKey != -1)
                                                {
                                                    if (indexRandom < indexKey)
                                                    {
                                                        indexKey--;
                                                    }
                                                    else if (indexRandom == indexKey)
                                                    {
                                                        _quiz.MixKeyAnswer += "<" + test.CodeTest + ">" + Alphabet[k].ToString() + "</" + test.CodeTest + ">";
                                                        indexKey            = -1;
                                                    }
                                                }
                                                _answerArr.RemoveAt(indexRandom);
                                            }
                                        }
                                        _quiz.MixAnswer += "</" + test.CodeTest + ">";
                                        test.MixAnswer   = true;
                                        new QuizDAO().UpdateMixAnswer(_quiz);
                                        new TestDAO().UpdateMixAnswer(test);
                                    }//end-for

                                    test.CreatedBy    = _session.UserID; //Người tạo
                                    test.CreatedDate  = DateTime.Now;
                                    test.ModifiedDate = DateTime.Now;
                                    r = new TestDAO().Insert(test, _temp);
                                    if (r == false)
                                    {
                                        return(r);
                                    }
                                    new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress());
                                }
                            }
                        }
                    }

                    // Trộn câu hỏi và đáp án
                    else if (test.Mix == ConstantVariable.MixAll)
                    {
                        // Trộn câu hỏi
                        List <int> _quizIdList  = new List <int>(); //Chứa câu hỏi của đề đầu tiên
                        List <int> _quizIdList0 = new List <int>(); //Chứa câu hỏi của các đề tiếp theo
                        bool       r            = false;
                        for (int i = 0; i < _codeTestArr.Length; i++)
                        {
                            if (!String.IsNullOrEmpty(_codeTestArr[i]))
                            {
                                test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề
                                Random random = new Random();

                                if (i == 0)
                                {
                                    for (int j = 0; j < test.NumberOfQuestions; j++)
                                    {
                                        int quizId;
                                        do
                                        {
                                            quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id;
                                        } while (_quizIdList.Contains(quizId));
                                        _quizIdList.Add(quizId);
                                    }
                                    _quizIdList0 = _quizIdList;
                                }//end-if (i == 0)
                                else
                                {
                                    List <int> _quizIdListMixQuiz = new List <int>();
                                    List <int> _temp = _quizIdList0;
                                    for (int j = 0; j < test.NumberOfQuestions; j++)
                                    {
                                        int quizId;
                                        int index;
                                        do
                                        {
                                            index  = random.Next(0, _temp.Count - 1);
                                            quizId = _temp[index];
                                        } while (_quizIdListMixQuiz.Contains(quizId));

                                        _quizIdListMixQuiz.Add(quizId);
                                        _temp.RemoveAt(index);
                                        if (j == test.NumberOfQuestions - 1)
                                        {
                                            int _count = 0;
                                            for (int k = 0; k < test.NumberOfQuestions; k++)
                                            {
                                                if (_quizIdListMixQuiz[k] == _quizIdList0[k])
                                                {
                                                    _count++;
                                                }
                                            }
                                            if (_count >= test.NumberOfQuestions)
                                            {
                                                j     = 0;
                                                _temp = null;
                                                _temp = _quizIdListMixQuiz;
                                                _quizIdListMixQuiz = null;
                                            }
                                        }
                                    }
                                } //end-else of if (i == 0)
                            }     //end-if (!String.IsNullOrEmpty(_codeTestArr[i]))
                        }         //end-for

                        // Trộn đáp án


                        // Insert dữ liệu
                    } //end-if (test.Mix == ConstantVariable.MixAll)
                }     //end-if (test.FixedOrChanged == ConstantVariable.FixedQuiz)
            }
            // Chọn câu hỏi theo kiểu câu hỏi mới nhất
            if (test.QuizSelection == ConstantVariable.NewQuiz)
            {
                var _quizList = new QuizDAO().GetAllQuizNewSubject(_exam.SubjectID);
                if (_quizList.Count < test.NumberOfQuestions)
                {
                    ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này.");
                    return(false);
                }
                else
                {
                    List <int> _quizIdList = new List <int>();
                    for (int i = 0; i < test.NumberOfQuestions; i++)
                    {
                        _quizIdList.Add(_quizList[i].Id);
                    }
                    var _session = Session[ConstantVariable.USER_SESSION] as UserLogin;
                    test.CreatedBy    = _session.UserID;
                    test.CreatedDate  = DateTime.Now;
                    test.ModifiedDate = DateTime.Now;
                    return(new TestDAO().Insert(test, _quizIdList));
                }
            }
            return(true);
        }
Example #16
0
        private bool CheckInputTest(Test test)
        {
            if (test.ExamID <= 0 || test.ExamID == null)
            {
                ModelState.AddModelError("", "Vui lòng chọn kỳ thi");
                return(false);
            }
            if (String.IsNullOrEmpty(test.CodeTestArr))
            {
                ModelState.AddModelError("", "Vui lòng nhập vào mã đề của đề thi. Nếu muốn tạo nhiều đề thi cùng một lúc, mỗi mã đề cách nhau dấu phẩy.");
                return(false);
            }
            else
            {
                var _regex    = new Regex(@"[0-9,]");
                var _codeTest = test.CodeTestArr.Replace(" ", string.Empty);
                if (_regex.IsMatch(_codeTest) == false)
                {
                    ModelState.AddModelError("", "Mã đề không hợp lệ. Chú ý: Nếu muốn tạo nhiều đề thi cùng một lúc, mỗi mã đề cách nhau dấu phẩy.");
                    return(false);
                }
                else
                {
                    var    _codeTestArr = Regex.Split(_codeTest, ",");
                    var    _exam        = new ExamDAO().GetExamById(test.ExamID);
                    var    _testList    = new TestDAO().GetAllTestByExam(_exam);
                    string temp         = null;
                    for (int i = 0; i < _codeTestArr.Length; i++)
                    {
                        if (_codeTestArr[i] == temp)
                        {
                            ModelState.AddModelError("", "Mã đề không hợp lệ. Chú ý: Nếu muốn tạo nhiều đề thi cùng một lúc, mỗi mã đề cách nhau dấu phẩy, mã đề phải khác nhau.");
                            return(false);
                        }
                        else
                        {
                            for (int j = 0; j < _testList.Count; j++)
                            {
                                if (_testList[j].CodeTest.ToString() == _codeTestArr[i])
                                {
                                    ModelState.AddModelError("", "Mã đề không hợp lệ. Mã đề phải khác nhau.");
                                    return(false);
                                }
                            }
                        }
                        temp = _codeTestArr[i];
                    }
                    test.CodeTestArr = _codeTest;
                }
            }
            if (test.NumberOfQuestions <= 0 || test.NumberOfQuestions == null)
            {
                ModelState.AddModelError("", "Số câu hỏi không hợp lệ");
                return(false);
            }
            if (test.Time <= 0)
            {
                ModelState.AddModelError("", "Thời gian làm bài không hợp lệ");
                return(false);
            }


            return(true);
        }
Example #17
0
        public ActionResult StartTheTest(int?id)
        {
            var _exam    = new ExamDAO().GetExamById(id);
            var _session = Session[ConstantVariable.USER_SESSION] as UserLogin;

            if (_session == null)
            {
                SetAlert("Vui lòng đăng nhập để bắt đầu thi", "error");
                return(Redirect("/"));
            }
            else
            {
                var _user     = new UserDAO().GetUserById(_session.UserID);
                var listClass = new ClassDAO().GetAllByExams(_exam.Id);
                if (!listClass.Exists(x => x.Id == _user.ClassID))
                {
                    SetAlert("Bạn không phải là thí sinh của kỳ thi này.", "error");
                    return(Redirect("/"));
                }
            }
            // Kiểm tra số lượt làm bài
            var _timeToTakeUser = new TestResultDetailDAO().GetTimeToTake(_session.UserID, _exam.Id);

            if (_timeToTakeUser >= _exam.NumberOfTurns)
            {
                SetAlert("Bạn đã hết lượt làm bài của kỳ thi này.", "error");
                return(Redirect("/"));
            }

            if (_exam.ToDate < DateTime.Now)
            {
                SetAlert("Kỳ thi đã hết hạn.", "error");
                _exam.Status = false;
                new ExamDAO().UpdateStatus(_exam);

                return(Redirect("/"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (_exam == null)
            {
                return(HttpNotFound());
            }
            int[] _codeTestID = new int[_exam.Tests.Count]; // Danh sách các mã đề thi của kỳ thi
            var   _tests      = _exam.Tests.ToList();

            for (int i = 0; i < _exam.Tests.Count; i++)
            {
                _codeTestID[i] = (int)_tests[i].CodeTest;
            }
            if (_codeTestID != null)
            {
                Random random         = new Random();
                int    selectCodeTest = random.Next(0, _codeTestID.Length); // Chọn ngẫu nhiên một mã đề
                return(View(_tests[selectCodeTest]));
            }

            return(View(_exam));
        }