示例#1
0
        public void Save(DataSet ds, DbTransaction transaction, Enumaration.PageMode pageMode)
        {
            DataSet            dataToSave = ds;
            DataRow            drQp       = ds.Tables[Entities.QuestionsPool.TABLE_NAME].Rows[0];
            DataTable          dtQpCatOne = null;
            DataTable          dtQpCatTwo = null;
            DAQuestionsPool    oDAQp      = new DAQuestionsPool();
            DACultureResources oDACr      = new DACultureResources();
            //Saving culture resources for questions:Start
            DataTable dtQpCr = ds.Tables[Enumaration.ManageQuestionKeys.DT_QuestionTextCultureRes];

            oDACr.PersistCultureResource(dtQpCr, transaction);

            //Saving culture resources for questions:Finish
            if (Convert.ToInt16(drQp[Entities.QuestionsPool.TYPE_ID]).Equals((int)Enumaration.QuestionType.Categorybased))
            {
                //Saving culture resources for CATEGORIES:Start
                dtQpCatOne = ds.Tables[Enumaration.ManageQuestionKeys.DT_QuestionCatOneCultureRes];
                oDACr.PersistCultureResource(dtQpCatOne, transaction);

                dtQpCatTwo = ds.Tables[Enumaration.ManageQuestionKeys.DT_QuestionCatTwoCultureRes];
                oDACr.PersistCultureResource(dtQpCatTwo, transaction);
            }
            //Saving culture resources for CATEGORIES:Finish
            //Saving questions Start


            drQp[Entities.QuestionsPool.QUESTION_TEXT] = (Int64)dtQpCr.Rows[0][Entities.CultureResources.ID];
            if (dtQpCatOne != null && dtQpCatTwo != null)
            {
                drQp[Entities.QuestionsPool.CATEGORY_ONE] = (Int64)dtQpCatOne.Rows[0][Entities.CultureResources.ID];
                drQp[Entities.QuestionsPool.CATEGORY_TWO] = (Int64)dtQpCatTwo.Rows[0][Entities.CultureResources.ID];
            }

            oDAQp.SaveQuestionsPool(transaction, drQp, pageMode);

            //Saving questions Finish

            DAAnswersPool ODaAp = new DAAnswersPool();

            DataRow[] answersToPersist = ds.Tables[Entities.AnswersPool.TABLE_NAME].Select(
                Entities.AnswersPool.IS_NEW + "   =1 OR " +
                Entities.AnswersPool.IS_CHANGED + "   =1 OR " +
                Entities.AnswersPool.IS_DELETED + "    =1   "

                );
            foreach (DataRow drAp in answersToPersist)
            {
                DataRow[] drApCrs = ds.Tables[Enumaration.ManageQuestionKeys.DT_AnswerTextCultureRes].
                                    Select(Entities.CultureResources.ID + "=" + drAp[Entities.AnswersPool.ANSWER_TEXT]);

                DataRow drApCr = drApCrs[0];
                if (drAp[Entities.AnswersPool.IS_NEW] != DBNull.Value && drAp[Entities.AnswersPool.IS_NEW].ToString().Equals("1"))
                {
                    drApCr[Entities.CultureResources.ID] = DBNull.Value;
                    drAp[Entities.AnswersPool.ID]        = DBNull.Value;
                }

                //Saving culture resources for answer:Start

                oDACr.PersistCultureResource(drApCr, transaction);

                //Saving culture resources for answer:Finish

                //Saving answers Start

                drAp[Entities.AnswersPool.QUESTION_ID] = (Int64)drQp[Entities.QuestionsPool.ID];
                drAp[Entities.AnswersPool.ANSWER_TEXT] = (Int64)drApCr[Entities.CultureResources.ID];

                if (drAp[Entities.AnswersPool.IS_NEW].Equals("1") && drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE] != DBNull.Value)
                {
                    String tempIdWithImage = drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE].ToString();
                    if (drQp.Table.Columns.Contains(Entities.QuestionsPool.TEMP_ID))
                    {
                        drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE] = drQp[Entities.QuestionsPool.TEMP_ID].ToString() + "/" +
                                                                       drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE].ToString();
                    }
                    else
                    {
                        drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE] = drQp[Entities.QuestionsPool.ID].ToString() + "/" +
                                                                       drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE].ToString();
                    }
                    ODaAp.SaveAnswers(transaction, drAp);
                    drAp[Entities.AnswersPool.TEMP_ID_FOR_IMAGE] = tempIdWithImage;
                }
                else
                {
                    ODaAp.SaveAnswers(transaction, drAp);
                }
                //Saving answers Finish
            }
            //Generate Questions XML It should be the last item int the function
            oDAQp.PersistXML(transaction, drQp[Entities.QuestionsPool.ID].ToString());
        }
示例#2
0
        public string CalculateResult(String request, String testTakerId)
        {
            string[]      responses             = request.Split('|');
            DAAnswersPool oDAAnswersPool        = new DAAnswersPool();
            DataSet       dsAnswers             = oDAAnswersPool.GetAnswersByTestTakerId(testTakerId);
            DataTable     dtAnswers             = dsAnswers.Tables[0];
            StringBuilder whereClause           = new StringBuilder(" WHERE TEST_TAKER_ID =" + testTakerId + " and  QUESTION_ID IN (");
            StringBuilder caseClauseForStatus   = new StringBuilder(" STATUS = CASE QUESTION_ID ");
            StringBuilder caseClauseForResponse = new StringBuilder(" SELECTED_ANSWER = CASE QUESTION_ID ");

            foreach (string response in responses)
            {
                if (string.IsNullOrEmpty(response) || response.Length <= 0)
                {
                    continue;
                }
                string[] subResponse = response.Split('_');
                string   questionId  = subResponse[1];
                whereClause.Append(questionId + ",");

                string caseTemplate            = " WHEN " + questionId + " THEN {0} ";
                string caseTemplateForResponse = " WHEN " + questionId + " THEN '{0}' ";
                int    catId = int.Parse(subResponse[0]);
                if (catId.Equals((int)Enumaration.QuestionType.SingleSelection))
                {
                    CompileSingleSelectionResult(dtAnswers, caseClauseForStatus, caseClauseForResponse, subResponse, questionId, caseTemplate, caseTemplateForResponse);
                }
                else if (catId.Equals((int)Enumaration.QuestionType.Categorybased))
                {
                    //TODO
                    CompileCategoryBasedResult(dtAnswers, caseClauseForStatus, caseClauseForResponse, subResponse, questionId, caseTemplate, caseTemplateForResponse);
                }
                else if (catId.Equals((int)Enumaration.QuestionType.MatchImagewithImage) ||
                         catId.Equals((int)Enumaration.QuestionType.MatchImagewithText) ||
                         catId.Equals((int)Enumaration.QuestionType.MapLocator)
                         )
                {
                    CompileMatchImageWithImageAndMatchImageWithTextResult(dtAnswers, caseClauseForStatus, caseClauseForResponse, subResponse, questionId, caseTemplate, caseTemplateForResponse);
                }
            }
            string where = whereClause.ToString();
            where        = where.Substring(0, (where.Length - 1)) + ")";
            DATestTakers oDATestTakers = new DATestTakers();

            caseClauseForStatus.Append(" END ");
            caseClauseForResponse.Append(" END ");
            DataSet ds = oDATestTakers.PostResult(testTakerId, caseClauseForStatus.ToString(), caseClauseForResponse.ToString(), where);

            if (ds != null && ds.Tables[0].Columns.Contains("STATUS"))
            {
                if (ds.Tables[0].Rows[0]["STATUS"].ToString().Equals("3"))
                {
                    return("3");
                }
                else if (ds.Tables[0].Rows[0]["STATUS"].ToString().Equals("4"))
                {
                    return("4");
                }
            }
            return(string.Empty);
        }