コード例 #1
0
 /// <summary>
 /// Quiz load event
 /// </summary>
 private void Quiz_Load()
 {
     if (!PageContext.Current.IsPreviewMode)
     {
         BusinessServices.Toolbook objToolbook = new BusinessServices.Toolbook();
         if (!objToolbook.StartQuiz(PageContext.Current.SessionID))
         {
             Response.Write(ResourceManager.GetString("QuizLesson_Error"));
             Response.End();
             //throw new Exception("Quiz has already been started");
         }
     }
 }
コード例 #2
0
        }        //Lesson_OnExit

        /// <summary>
        /// This method is called when a Quiz is Loaded.
        /// It looks up various pieces of data from the Salt tables
        /// before returning them to the Toolbook application
        /// </summary>
        /// <param name="sessionID">This is the session id that maps to the lesson that is currently loading</param>
        /// <param name="postData">This is the collection of http post data variables</param>
        private void Quiz_OnLoad(string sessionID, NameValueCollection postData)
        {
            string strToolbookID;               // the toolbook ID as per the toolbook application
            string strUserName;                 // the username
            int    intUserID;                   // User ID of the current User
            int    intModuleID;                 // Module ID that this quiz belongs to
            int    intQuizID;                   // QuizID that the user is currently sitting
            int    intPassMark;                 // The passmark for the quiz that the user is currently sitting
            int    intUnitID;                   // The unit ID of the current user
            bool   blnError;                    // Boolean flag indicating the presence of an error

            // Verify the necessary post parameters have been supplied
            strToolbookID = postData.Get("ToolbookID");
            if (strToolbookID.Length == 0)
            {
                OutputToToolBook(
                    cm_strReturnCodeCriticalError                                                        // paramater 1 - ReturnCode
                    + cm_strDelimiter + "TBListener Error 1. Missing required parameter: ToolbookID"     // paramater 2 - Error Message
                    );
                return;
            }

            // toolbook object used to return necessary information below..
            BusinessServices.Toolbook objToolBook = new BusinessServices.Toolbook();

            // Get UserName and ID
            strUserName = objToolBook.GetUser(sessionID);
            intUserID   = objToolBook.GetUserIDBySessionID(sessionID);

            // Get Module ID and UserID to determine Access
            intModuleID = objToolBook.GetModuleIDBySessionID(sessionID);
            intUnitID   = objToolBook.GetUnitIDByUserID(intUserID);

            // Get Quiz ID, Number of Quiz Questions and PassMark
            intQuizID   = objToolBook.GetQuizIDBySessionID(sessionID);
            intPassMark = objToolBook.GetQuizPassMark(intUnitID, intModuleID);

            // Assume no errors to start with.
            blnError = false;

            // If no username
            if (strUserName.Length == 0)
            {
                OutputToToolBook(
                    cm_strReturnCodeCriticalError
                    + cm_strDelimiter
                    + "TBListener Error 5. The User Name could not be found"
                    + cm_strDelimiter
                    + m_strRootURL + cm_strErrorLocation
                    + "?errnum=5"
                    );
                blnError = true;
            }

            // If no Quiz ID
            if (intQuizID <= 0)
            {
                OutputToToolBook(
                    cm_strReturnCodeCriticalError
                    + cm_strDelimiter
                    + "TBListener Error 6. The Quiz ID could not be found"
                    + cm_strDelimiter
                    + m_strRootURL + cm_strErrorLocation
                    + "?errnum=6"
                    );
                blnError = true;
            }

            // If no module ID
            if (intModuleID <= 0)
            {
                OutputToToolBook(
                    cm_strReturnCodeCriticalError
                    + cm_strDelimiter
                    + "TBListener Error 8. The Module ID Could not be found"
                    + cm_strDelimiter
                    + m_strRootURL + cm_strErrorLocation
                    + "?errnum=8"
                    );
                blnError = true;
            }

            // If no Unit ID
            if (intUnitID <= 0)
            {
                OutputToToolBook(
                    cm_strReturnCodeCriticalError
                    + cm_strDelimiter
                    + "TBListener Error 9. The Unit ID Could not be found"
                    + cm_strDelimiter
                    + m_strRootURL + cm_strErrorLocation
                    + "?errnum=9"
                    );
                blnError = true;
            }
            // If no error has occurred
            if (!blnError)
            {
                // Start the quiz
                if (objToolBook.StartQuiz(sessionID))
                {
                    // Let Toolbook know that we have successfully started the quiz
                    OutputToToolBook(
                        cm_strReturnCodeOK                                                                      // paramater 1 - ReturnCode
                        + cm_strDelimiter + intPassMark                                                         // paramater 3 - PassMark
                        + cm_strDelimiter + strUserName                                                         // paramater 4 - User Name
                        + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?SessionID=" + sessionID       // paramater 5 - Exit Home URL
                        + cm_strDelimiter + m_strRootURL + cm_strReportLocation + "?QuizSessionID=" + sessionID // paramater 6 - Exit Report URL
                        + cm_strDelimiter + m_strRootURL + cm_strErrorLocation                                  // paramater 7 - Error URL
                        + cm_strDelimiter + ""                                                                  // paramater 8 - Error Message
                        );
                    return;
                }
                else
                {
                    OutputToToolBook(
                        cm_strReturnCodeCriticalError
                        + cm_strDelimiter + ResourceManager.GetString("Error1")                         //"Please make sure you do not use your browser's backwards and forwards buttons. Navigate lessons and quizzes using the buttons in the bottom right hand corner."
                        + cm_strDelimiter + m_strRootURL + cm_strHomeLocation + "?errnum=2"             //cm_strErrorLocation
                        );
                    return;
                }
            }
        }         // Quiz_OnLoad