/// <summary> /// Retrieves the theme 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 GetThemeList(Dictionary <string, bool> modules, int currentPage, string filter) { string retval = ""; string className = ""; int total = 0; string sql = "SELECT COUNT(IdTheme) AS HowMany FROM ExamTheme"; 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%'>"; //Table Header retval += "<tr><th>" + Text.Identifier + "</th><th>" + Text.Theme + "</th></tr>"; sql = "SELECT IdTheme, Theme FROM (SELECT IdTheme, Theme, ROW_NUMBER() OVER (ORDER BY IdTheme) AS RowNum FROM ExamTheme"; sql = Common.StrAdd(sql, " WHERE ", filter); sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")"; string[] idThemeList = Common.CSVToArray(Common.GetBDList("IdTheme", sql, false)); foreach (string idTheme in idThemeList) { try { ExamTheme theme = new ExamTheme(Convert.ToInt32(idTheme)); className = Common.SwitchClass(className); retval += "<tr class='" + className + "' onClick='showTheme(" + idTheme + ");'>"; retval += "<td width='10%' align='center'>" + theme.IdTheme + "</td>"; retval += "<td width='70%'>" + theme.Theme + "</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.Theme_s + "</div>"; retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString()); retval += " <a href='#' class='dark' onClick='firstPage();'><<</a>"; retval += " <a href='#' class='dark' onClick='prevPage();'><</a>"; retval += " <a href='#' class='dark' onClick='nextPage();'>></a>"; retval += " <a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>>></a>"; retval += "</div>"; retval += "</div>"; return(retval); }
/// <summary> /// Creates an exam given the selected configuration, also locks said exam. /// </summary> /// <returns>NO_ERROR if created successfully.</returns> public int Create() { string sql = "INSERT INTO UserExam(IdUser, IdExam, Status) VALUES(" + IdUser + ", " + IdExam + ", " + UserExamStatus.PENDING + ")"; Common.BDExecute(sql); IdUserExam = Common.GetBDNum("lastId", "SELECT MAX(IdUserExam) AS lastId FROM UserExam"); Exam exam = new Exam(IdExam); foreach (ExamContent examContent in exam.examContents) { if (examContent.IdTheme != 0) { ExamTheme theme = new ExamTheme(examContent.IdTheme); List <int> selectedIds = Common.GetIdList("IdQuestion", "SELECT TOP " + examContent.QuestionCount + " IdQuestion FROM ExamQuestion WHERE IdTheme IN (" + theme.GetChildrenThemes(examContent.IdTheme.ToString()) + ") ORDER BY newid();"); foreach (int selectedId in selectedIds) { UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, selectedId); examQuestion.Create(); } } else if (examContent.IdQuestion != 0) { UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, examContent.IdQuestion); examQuestion.QuestionSequence = examContent.QuestionSequence; examQuestion.Create(); } } return(ErrorCode.NO_ERROR); }
/// <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> </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 += " <a href='#' class='dark' onClick='firstPage();'><<</a>"; retval += " <a href='#' class='dark' onClick='prevPage();'><</a>"; retval += " <a href='#' class='dark' onClick='nextPage();'>></a>"; retval += " <a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>>></a>"; retval += "</div>"; retval += "</div>"; return(retval); }
/// <summary> /// Creates an exam given the selected configuration, also locks said exam. /// </summary> /// <returns>NO_ERROR if created successfully.</returns> public int Create() { string sql = "INSERT INTO UserExam(IdUser, IdExam, Status) VALUES(" + IdUser + ", " + IdExam + ", " + UserExamStatus.PENDING + ")"; Common.BDExecute(sql); IdUserExam = Common.GetBDNum("lastId", "SELECT MAX(IdUserExam) AS lastId FROM UserExam"); Exam exam = new Exam(IdExam); foreach (ExamContent examContent in exam.examContents) { if (examContent.IdTheme != 0) { ExamTheme theme = new ExamTheme(examContent.IdTheme); List<int> selectedIds = Common.GetIdList("IdQuestion", "SELECT TOP " + examContent.QuestionCount + " IdQuestion FROM ExamQuestion WHERE IdTheme IN (" + theme.GetChildrenThemes(examContent.IdTheme.ToString()) + ") ORDER BY newid();"); foreach (int selectedId in selectedIds) { UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, selectedId); examQuestion.Create(); } } else if(examContent.IdQuestion != 0) { UserExamQuestion examQuestion = new UserExamQuestion(IdUserExam, examContent.IdQuestion); examQuestion.QuestionSequence = examContent.QuestionSequence; examQuestion.Create(); } } return ErrorCode.NO_ERROR; }
/// <summary> /// Retrieves the theme 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 GetThemeList(Dictionary<string, bool> modules, int currentPage, string filter) { string retval = ""; string className = ""; int total = 0; string sql = "SELECT COUNT(IdTheme) AS HowMany FROM ExamTheme"; 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%'>"; //Table Header retval += "<tr><th>" + Text.Identifier + "</th><th>" + Text.Theme + "</th></tr>"; sql = "SELECT IdTheme, Theme FROM (SELECT IdTheme, Theme, ROW_NUMBER() OVER (ORDER BY IdTheme) AS RowNum FROM ExamTheme"; sql = Common.StrAdd(sql, " WHERE ", filter); sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")"; string[] idThemeList = Common.CSVToArray(Common.GetBDList("IdTheme", sql, false)); foreach (string idTheme in idThemeList) { try { ExamTheme theme = new ExamTheme(Convert.ToInt32(idTheme)); className = Common.SwitchClass(className); retval += "<tr class='" + className + "' onClick='showTheme(" + idTheme + ");'>"; retval += "<td width='10%' align='center'>" + theme.IdTheme + "</td>"; retval += "<td width='70%'>" + theme.Theme + "</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.Theme_s + "</div>"; retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString()); retval += " <a href='#' class='dark' onClick='firstPage();'><<</a>"; retval += " <a href='#' class='dark' onClick='prevPage();'><</a>"; retval += " <a href='#' class='dark' onClick='nextPage();'>></a>"; retval += " <a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>>></a>"; retval += "</div>"; retval += "</div>"; return retval; }
/// <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> </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 += " <a href='#' class='dark' onClick='firstPage();'><<</a>"; retval += " <a href='#' class='dark' onClick='prevPage();'><</a>"; retval += " <a href='#' class='dark' onClick='nextPage();'>></a>"; retval += " <a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>>></a>"; retval += "</div>"; retval += "</div>"; return retval; }