Beispiel #1
0
        /// <summary>
        /// Clones the current question.
        /// </summary>
        /// <returns>The id of the cloned question.</returns>
        public int Clone()
        {
            ExamQuestion clonedQuestion = new ExamQuestion();

            clonedQuestion.Question           = Question;
            clonedQuestion.IdTheme            = IdTheme;
            clonedQuestion.Status             = Status;
            clonedQuestion.IdQuestionOriginal = IdQuestion;
            clonedQuestion.Create();
            foreach (ExamOption option in options)
            {
                option.Clone(clonedQuestion.IdQuestion);
            }
            return(clonedQuestion.IdQuestion);
        }
Beispiel #2
0
        /// <summary>
        /// Grades the user exam.
        /// </summary>
        public void Grade()
        {
            int totalQuestions = 0;
            int totalPoints    = 0;

            foreach (UserExamQuestion userExamQuestion in questions)
            {
                ExamQuestion question = new ExamQuestion(userExamQuestion.IdQuestion);
                foreach (ExamOption option in question.options)
                {
                    if (option.IdOption == userExamQuestion.IdOption)
                    {
                        totalPoints += option.Points;
                    }
                }
                totalQuestions++;
            }
            Score = ((double)totalPoints / (double)totalQuestions) * 100;
            Exam exam = new Exam(IdExam);

            if (exam.MasteryScore == 0)
            {
                Status = UserExamStatus.COMPLETE;
            }
            else if (Score >= exam.MasteryScore)
            {
                Status = UserExamStatus.PASSED;
            }
            else
            {
                Status = UserExamStatus.FAILED;
            }
            string sql = "UPDATE UserExam SET Status=" + Status + ", Score=" + Score + ", DateComplete=getdate() WHERE IdUserExam = " + IdUserExam;

            Common.BDExecute(sql);
            Log.Add(SessionHandler.Id, LogKind.GENERAL, Modules.EVALUATION, IdExam, Text.Exam + ": " + exam.ExamName + ", [IdU: " + IdUser + ", IdUE: " + IdUserExam + "]");
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves the question list as an HTML string.
        /// </summary>
        /// <param name="modules">The current user modules.</param>
        /// <param name="currentPage">The current page used.</param>
        /// <param name="filter">An SQL filter.</param>
        /// <returns>The HTML string with the question list.</returns>
        public static string GetQuestionList(Dictionary <string, bool> modules, int currentPage, string filter, bool forSelection)
        {
            string retval    = "";
            string className = "";
            int    total     = 0;
            string sql       = "SELECT COUNT(IdQuestion) AS HowMany FROM ExamQuestion";

            sql = Common.StrAdd(sql, " WHERE ", filter);
            double recordsPerPage = Config.RecordsPerPage();
            double totalRecords   = Common.GetBDNum("HowMany", sql);
            int    totalPages     = Convert.ToInt32(Math.Ceiling(totalRecords / recordsPerPage));

            if (currentPage > totalPages)
            {
                currentPage = totalPages;
            }
            if (currentPage == 0)
            {
                currentPage = 1;
            }

            retval  = "<table width='100%'>";
            retval += "<tr>";

            //Table Header
            if (forSelection)
            {
                retval += "<th>&nbsp;</th>";
            }
            retval += "<th>" + Text.Identifier + "</th><th>" + Text.Question + "</th>";
            if (!forSelection)
            {
                retval += "<th>" + Text.Theme + "</th><th>" + Text.Status + "</th>";
            }
            retval += "<th>" + Text.DifficultyIndex + "</th></tr>";

            sql  = "SELECT IdQuestion, Question FROM (SELECT IdQuestion, Question, ROW_NUMBER() OVER (ORDER BY IdQuestion) AS RowNum FROM ExamQuestion";
            sql  = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idQuestionList = Common.CSVToArray(Common.GetBDList("IdQuestion", sql, false));
            foreach (string idQuestion in idQuestionList)
            {
                try
                {
                    ExamQuestion question  = new ExamQuestion(Convert.ToInt32(idQuestion));
                    ExamTheme    theme     = new ExamTheme(question.IdTheme);
                    string       themeName = "";
                    if (String.IsNullOrEmpty(theme.Theme))
                    {
                        themeName = Text.None;
                    }
                    else
                    {
                        themeName = theme.Theme;
                    }
                    className = Common.SwitchClass(className);
                    string questionStatus = Text.Inactive;
                    if (question.Status == ExamQuestionStatus.ACTIVE)
                    {
                        questionStatus = Text.Active;
                    }
                    retval += "<tr class='" + className + "' id='q_" + idQuestion + "' onClick='showQuestion(" + idQuestion + ");'>";
                    if (forSelection)
                    {
                        retval += "<td width='5%' align='center'>" + DrawInput.InputCheckbox("q_chk_" + idQuestion, "", false, "questionChk", "", "", "") + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + question.IdQuestion + "</td>";
                    retval += "<td width='60%'>" + Common.BBCodeToHTML(question.Question) + "</td>";
                    if (!forSelection)
                    {
                        retval += "<td width='20%' align='center'>" + themeName + "</td>";
                        retval += "<td width='10%' align='center'>" + questionStatus + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + String.Format("{0:0.00}", question.DifficultyIndex("")) + "</td>";
                    retval += "</tr>";
                    total++;
                }
                catch (Exception ex) { }
            }

            retval += "</table>";

            //footer / pagination
            retval += "<div align='center' class='pagination'>";
            retval += "<div align='left' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.ShowingXofY, total.ToString() + "," + totalRecords.ToString()) + " " + Text.Question_s + "</div>";
            retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString());
            retval += "&nbsp;<a href='#' class='dark' onClick='firstPage();'>&lt;&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='prevPage();'>&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='nextPage();'>&gt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>&gt;&gt;</a>";
            retval += "</div>";
            retval += "</div>";

            return(retval);
        }
Beispiel #4
0
 /// <summary>
 /// Clones the current question.
 /// </summary>
 /// <returns>The id of the cloned question.</returns>
 public int Clone()
 {
     ExamQuestion clonedQuestion = new ExamQuestion();
     clonedQuestion.Question = Question;
     clonedQuestion.IdTheme = IdTheme;
     clonedQuestion.Status = Status;
     clonedQuestion.IdQuestionOriginal = IdQuestion;
     clonedQuestion.Create();
     foreach (ExamOption option in options)
     {
         option.Clone(clonedQuestion.IdQuestion);
     }
     return clonedQuestion.IdQuestion;
 }
Beispiel #5
0
 /// <summary>
 /// Grades the user exam.
 /// </summary>
 public void Grade()
 {
     int totalQuestions = 0;
     int totalPoints = 0;
     foreach (UserExamQuestion userExamQuestion in questions)
     {
         ExamQuestion question = new ExamQuestion(userExamQuestion.IdQuestion);
         foreach(ExamOption option in question.options)
         {
             if (option.IdOption == userExamQuestion.IdOption)
             {
                 totalPoints += option.Points;
             }
         }
         totalQuestions++;
     }
     Score = ((double)totalPoints / (double)totalQuestions) * 100;
     Exam exam = new Exam(IdExam);
     if (exam.MasteryScore == 0)
     {
         Status = UserExamStatus.COMPLETE;
     }
     else if (Score >= exam.MasteryScore)
     {
         Status = UserExamStatus.PASSED;
     }
     else
     {
         Status = UserExamStatus.FAILED;
     }
     string sql = "UPDATE UserExam SET Status=" + Status + ", Score=" + Score + ", DateComplete=getdate() WHERE IdUserExam = " + IdUserExam;
     Common.BDExecute(sql);
     Log.Add(SessionHandler.Id, LogKind.GENERAL, Modules.EVALUATION, IdExam, Text.Exam + ": " + exam.ExamName + ", [IdU: " + IdUser + ", IdUE: " + IdUserExam + "]");
 }
Beispiel #6
0
        /// <summary>
        /// Retrieves the question list as an HTML string.
        /// </summary>
        /// <param name="modules">The current user modules.</param>
        /// <param name="currentPage">The current page used.</param>
        /// <param name="filter">An SQL filter.</param>
        /// <returns>The HTML string with the question list.</returns>
        public static string GetQuestionList(Dictionary<string, bool> modules, int currentPage, string filter, bool forSelection)
        {
            string retval = "";
            string className = "";
            int total = 0;
            string sql = "SELECT COUNT(IdQuestion) AS HowMany FROM ExamQuestion";
            sql = Common.StrAdd(sql, " WHERE ", filter);
            double recordsPerPage = Config.RecordsPerPage();
            double totalRecords = Common.GetBDNum("HowMany", sql);
            int totalPages = Convert.ToInt32(Math.Ceiling(totalRecords / recordsPerPage));

            if (currentPage > totalPages)
            {
                currentPage = totalPages;
            }
            if (currentPage == 0)
            {
                currentPage = 1;
            }

            retval = "<table width='100%'>";
            retval += "<tr>";

            //Table Header
            if (forSelection)
            {
                retval += "<th>&nbsp;</th>";
            }
            retval += "<th>" + Text.Identifier + "</th><th>" + Text.Question + "</th>";
            if(!forSelection)
            {
                retval += "<th>" + Text.Theme +"</th><th>" + Text.Status + "</th>";
            }
            retval += "<th>" + Text.DifficultyIndex + "</th></tr>";

            sql = "SELECT IdQuestion, Question FROM (SELECT IdQuestion, Question, ROW_NUMBER() OVER (ORDER BY IdQuestion) AS RowNum FROM ExamQuestion";
            sql = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idQuestionList = Common.CSVToArray(Common.GetBDList("IdQuestion", sql, false));
            foreach (string idQuestion in idQuestionList)
            {
                try
                {
                    ExamQuestion question = new ExamQuestion(Convert.ToInt32(idQuestion));
                    ExamTheme theme = new ExamTheme(question.IdTheme);
                    string themeName = "";
                    if (String.IsNullOrEmpty(theme.Theme))
                    {
                        themeName = Text.None;
                    }
                    else
                    {
                        themeName = theme.Theme;
                    }
                    className = Common.SwitchClass(className);
                    string questionStatus = Text.Inactive;
                    if (question.Status == ExamQuestionStatus.ACTIVE)
                    {
                        questionStatus = Text.Active;
                    }
                    retval += "<tr class='" + className + "' id='q_" + idQuestion + "' onClick='showQuestion(" + idQuestion + ");'>";
                    if(forSelection)
                    {
                        retval += "<td width='5%' align='center'>" + DrawInput.InputCheckbox("q_chk_" + idQuestion, "", false, "questionChk", "", "", "") + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + question.IdQuestion + "</td>";
                    retval += "<td width='60%'>" + Common.BBCodeToHTML(question.Question) + "</td>";
                    if(!forSelection)
                    {
                        retval += "<td width='20%' align='center'>" + themeName + "</td>";
                        retval += "<td width='10%' align='center'>" + questionStatus + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + String.Format("{0:0.00}", question.DifficultyIndex("")) + "</td>";
                    retval += "</tr>";
                    total++;
                }
                catch (Exception ex) { }
            }

            retval += "</table>";

            //footer / pagination
            retval += "<div align='center' class='pagination'>";
            retval += "<div align='left' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.ShowingXofY, total.ToString() + "," + totalRecords.ToString()) + " " + Text.Question_s + "</div>";
            retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString());
            retval += "&nbsp;<a href='#' class='dark' onClick='firstPage();'>&lt;&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='prevPage();'>&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='nextPage();'>&gt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>&gt;&gt;</a>";
            retval += "</div>";
            retval += "</div>";

            return retval;
        }