コード例 #1
0
ファイル: BLLQuestion.cs プロジェクト: uvbs/mmp
 public bool CheckQuestionnaireSet(QuestionnaireSet nSet, out string msg)
 {
     msg = "";
     if (nSet == null)
     {
         msg = "未找到答题设置";
         return(false);
     }
     if (nSet.StartDate > DateTime.Now)
     {
         msg = "答题还未开始";
         return(false);
     }
     if (nSet.EndDate < DateTime.Now)
     {
         msg = "答题已结束";
         return(false);
     }
     if (nSet.ScoreNum > 0 && nSet.Score > 0)
     {
         BLLUser bllUser      = new BLLUser();
         int     UserScoreNum = bllUser.GetUserScoreNum(GetCurrUserID(), "QuestionnaireSet", false, nSet.AutoID.ToString());
         if (UserScoreNum >= nSet.ScoreNum)
         {
             msg = "您的答题次数已满";
             return(false);
         }
     }
     return(true);
 }
コード例 #2
0
 public QuestionnaireSetTO(QuestionnaireSet mdo)
 {
     this.name           = mdo.Name;
     this.title          = mdo.Title;
     this.description    = mdo.Description;
     this.questions      = new QuestionArray(mdo.Questions);
     this.questionnaires = new QuestionnaireArray(mdo.Questionnaires);
 }
コード例 #3
0
ファイル: BLLQuestion.cs プロジェクト: uvbs/mmp
        public bool GetQuestionListBySet(int setId, out List <Question> questions, out string msg)
        {
            questions = new List <Question>();
            msg       = "";
            QuestionnaireSet nSet = GetByKey <QuestionnaireSet>("AutoID", setId.ToString());

            if (!CheckQuestionnaireSet(nSet, out msg))
            {
                return(false);
            }
            return(GetQuestionList(nSet.QuestionnaireId.Value + "|" + nSet.QuestionCount.Value, "1", nSet.IsQuestionRandom.ToString(), nSet.IsOptionRandom.ToString(), "", WebsiteOwner, out questions, out msg));
        }
コード例 #4
0
        public QuestionnaireSetTO getQuestionnaireSet(string name)
        {
            QuestionnaireSetTO result = new QuestionnaireSetTO();

            if (String.IsNullOrEmpty(name))
            {
                result.fault = new FaultTO("Missing set name");
                return(result);
            }
            try
            {
                QuestionnaireSet mdo = QuestionnaireSet.getSet(name);
                result = new QuestionnaireSetTO(mdo);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            return(result);
        }
コード例 #5
0
        public QuestionnaireSet getSet(string filepath)
        {
            if (String.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException("filename");
            }
            if (!File.Exists(filepath))
            {
                throw new ArgumentException("Missing XML questionnaire definition file");
            }

            QuestionnaireSet             qset             = null;
            List <QuestionnaireQuestion> currentQuestions = null;
            Questionnaire           currentQuestionnaire  = null;
            QuestionnaireQuestion   currentQuestion       = null;
            QuestionnaireSection    currentSection        = null;
            QuestionnairePage       currentPage           = null;
            QuestionnaireSubsection currentSubsection     = null;

            XmlReader reader = new XmlTextReader(filepath);

            while (reader.Read())
            {
                switch ((int)reader.NodeType)
                {
                case (int)XmlNodeType.Element:
                    string name = reader.Name;
                    if (name == "QuestionnaireSet")
                    {
                        qset                = new QuestionnaireSet();
                        qset.Name           = reader.GetAttribute("name");
                        qset.Title          = reader.GetAttribute("title");
                        qset.Description    = reader.GetAttribute("description");
                        qset.Questionnaires = new List <Questionnaire>();
                    }
                    else if (name == "Introduction")
                    {
                        currentQuestions = new List <QuestionnaireQuestion>();
                    }
                    else if (name == "Questionnaire")
                    {
                        currentQuestionnaire             = new Questionnaire();
                        currentQuestionnaire.Name        = reader.GetAttribute("name");
                        currentQuestionnaire.Title       = reader.GetAttribute("title");
                        currentQuestionnaire.Description = reader.GetAttribute("description");
                        currentQuestionnaire.Sections    = new List <QuestionnaireSection>();
                    }
                    else if (name == "Choices")
                    {
                        currentQuestion.Choices = new List <KeyValuePair <string, string> >();
                    }
                    else if (name == "Choice")
                    {
                        string nbr = reader.GetAttribute("number");
                        string txt = reader.GetAttribute("text");
                        currentQuestion.Choices.Add(new KeyValuePair <string, string>(nbr, txt));
                    }
                    else if (name == "Section")
                    {
                        currentSection       = new QuestionnaireSection();
                        currentSection.Name  = reader.GetAttribute("name");
                        currentSection.Title = reader.GetAttribute("title");
                        currentSection.Pages = new List <QuestionnairePage>();
                    }
                    else if (name == "Page")
                    {
                        currentPage          = new QuestionnairePage();
                        currentPage.Number   = reader.GetAttribute("number");
                        currentPage.Sections = new List <QuestionnaireSubsection>();
                    }
                    else if (name == "Subsection")
                    {
                        currentSubsection       = new QuestionnaireSubsection();
                        currentSubsection.Name  = reader.GetAttribute("name");
                        currentSubsection.Title = reader.GetAttribute("title");
                    }
                    else if (name == "Questions")
                    {
                        currentQuestions = new List <QuestionnaireQuestion>();
                    }
                    else if (name == "Question")
                    {
                        currentQuestion                    = new QuestionnaireQuestion();
                        currentQuestion.Number             = reader.GetAttribute("number");
                        currentQuestion.Text               = reader.GetAttribute("text");
                        currentQuestion.BranchFromQuestion = reader.GetAttribute("branchFrom");
                        currentQuestion.BranchCondition    = reader.GetAttribute("if");
                        currentQuestions.Add(currentQuestion);
                    }
                    break;

                case (int)XmlNodeType.EndElement:
                    name = reader.Name;
                    if (name == "Introduction")
                    {
                        qset.Questions   = currentQuestions;
                        currentQuestions = null;
                    }
                    else if (name == "Questionnaire")
                    {
                        qset.Questionnaires.Add(currentQuestionnaire);
                        currentQuestionnaire = null;
                    }
                    else if (name == "Choices")
                    {
                    }
                    else if (name == "Section")
                    {
                        currentQuestionnaire.Sections.Add(currentSection);
                        currentSection = null;
                    }
                    else if (name == "Page")
                    {
                        currentSection.Pages.Add(currentPage);
                        currentPage = null;
                    }
                    else if (name == "Subsection")
                    {
                        currentPage.Sections.Add(currentSubsection);
                        currentSubsection = null;
                    }
                    else if (name == "Questions")
                    {
                        currentSubsection.Questions = currentQuestions;
                        currentQuestions            = null;
                    }
                    break;
                }
            }
            return(qset);
        }
コード例 #6
0
        public void ProcessRequest(HttpContext context)
        {
            RequestModel requestModel = new RequestModel();

            try
            {
                requestModel = JsonConvert.DeserializeObject <RequestModel>(context.Request["data"]);
            }
            catch (Exception ex)
            {
                resp.errcode = (int)APIErrCode.OperateFail;
                resp.errmsg  = ex.Message;
                bllQuestion.ContextResponse(context, resp);
                return;
            }
            string msg    = "";
            bool   result = false;

            QuestionnaireSet nSet = bllQuestion.GetByKey <QuestionnaireSet>("AutoID", requestModel.set_id.ToString());

            result = bllQuestion.CheckQuestionnaireSet(nSet, out msg);
            if (!result)
            {
                apiResp.status = result;
                apiResp.msg    = msg;
                bllQuestion.ContextResponse(context, apiResp);
                return;
            }
            int    correctCount    = 0;
            string userHostAddress = context.Request.UserHostAddress;

            List <QuestionPostModel> postList = (from p in requestModel.answer_list
                                                 select new QuestionPostModel
            {
                QuestionID = p.question_id,
                Answer = p.option_ids
            }).ToList();

            int questionnaireId = nSet.QuestionnaireId.HasValue?nSet.QuestionnaireId.Value:0;

            result = bllQuestion.PostQuestion(postList, requestModel.set_id, CurrentUserInfo.UserID, bllQuestion.WebsiteOwner
                                              , userHostAddress, out correctCount, out msg, questionnaireId);

            bool have_score = correctCount >= nSet.WinCount;

            if (have_score && nSet.Score > 0 && nSet.ScoreNum > 0)
            {
                string msgscore = "";
                bllUser.AddUserScoreDetail(CurrentUserInfo.UserID, "QuestionnaireSet", bllQuestion.WebsiteOwner, out msgscore, nSet.Score, "答题获得积分", null, false, nSet.AutoID.ToString());
            }
            dynamic resultObj = new
            {
                have_score    = have_score,
                correct_count = correctCount
            };

            apiResp.code   = (int)(result ? APIErrCode.IsSuccess : APIErrCode.OperateFail);
            apiResp.status = result;
            apiResp.result = resultObj;
            apiResp.msg    = msg;
            bllQuestion.ContextResponse(context, apiResp);
        }
コード例 #7
0
ファイル: QuestionnaireDao.cs プロジェクト: OSEHRA/mdo
        public QuestionnaireSet getSet(string filepath)
        {
            if (String.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException("filename");
            }
            if (!File.Exists(filepath))
            {
                throw new ArgumentException("Missing XML questionnaire definition file");
            }

            QuestionnaireSet qset = null;
            List<QuestionnaireQuestion> currentQuestions = null;
            Questionnaire currentQuestionnaire = null;
            QuestionnaireQuestion currentQuestion = null;
            QuestionnaireSection currentSection = null;
            QuestionnairePage currentPage = null;
            QuestionnaireSubsection currentSubsection = null;

            XmlReader reader = new XmlTextReader(filepath);
            while (reader.Read())
            {
                switch ((int)reader.NodeType)
                {
                    case (int)XmlNodeType.Element:
                        string name = reader.Name;
                        if (name == "QuestionnaireSet")
                        {
                            qset = new QuestionnaireSet();
                            qset.Name = reader.GetAttribute("name");
                            qset.Title = reader.GetAttribute("title");
                            qset.Description = reader.GetAttribute("description");
                            qset.Questionnaires = new List<Questionnaire>();
                        }
                        else if (name == "Introduction")
                        {
                            currentQuestions = new List<QuestionnaireQuestion>();
                        }
                        else if (name == "Questionnaire")
                        {
                            currentQuestionnaire = new Questionnaire();
                            currentQuestionnaire.Name = reader.GetAttribute("name");
                            currentQuestionnaire.Title = reader.GetAttribute("title");
                            currentQuestionnaire.Description = reader.GetAttribute("description");
                            currentQuestionnaire.Sections = new List<QuestionnaireSection>();
                        }
                        else if (name == "Choices")
                        {
                            currentQuestion.Choices = new List<KeyValuePair<string, string>>();
                        }
                        else if (name == "Choice")
                        {
                            string nbr = reader.GetAttribute("number");
                            string txt = reader.GetAttribute("text");
                            currentQuestion.Choices.Add(new KeyValuePair<string, string>(nbr, txt));
                        }
                        else if (name == "Section")
                        {
                            currentSection = new QuestionnaireSection();
                            currentSection.Name = reader.GetAttribute("name");
                            currentSection.Title = reader.GetAttribute("title");
                            currentSection.Pages = new List<QuestionnairePage>();
                        }
                        else if (name == "Page")
                        {
                            currentPage = new QuestionnairePage();
                            currentPage.Number = reader.GetAttribute("number");
                            currentPage.Sections = new List<QuestionnaireSubsection>();
                        }
                        else if (name == "Subsection")
                        {
                            currentSubsection = new QuestionnaireSubsection();
                            currentSubsection.Name = reader.GetAttribute("name");
                            currentSubsection.Title = reader.GetAttribute("title");
                        }
                        else if (name == "Questions")
                        {
                            currentQuestions = new List<QuestionnaireQuestion>();
                        }
                        else if (name == "Question")
                        {
                            currentQuestion = new QuestionnaireQuestion();
                            currentQuestion.Number = reader.GetAttribute("number");
                            currentQuestion.Text = reader.GetAttribute("text");
                            currentQuestion.BranchFromQuestion = reader.GetAttribute("branchFrom");
                            currentQuestion.BranchCondition = reader.GetAttribute("if");
                            currentQuestions.Add(currentQuestion);
                        }
                        break;
                    case (int)XmlNodeType.EndElement:
                        name = reader.Name;
                        if (name == "Introduction")
                        {
                            qset.Questions = currentQuestions;
                            currentQuestions = null;
                        }
                        else if (name == "Questionnaire")
                        {
                            qset.Questionnaires.Add(currentQuestionnaire);
                            currentQuestionnaire = null;
                        }
                        else if (name == "Choices")
                        {
                        }
                        else if (name == "Section")
                        {
                            currentQuestionnaire.Sections.Add(currentSection);
                            currentSection = null;
                        }
                        else if (name == "Page")
                        {
                            currentSection.Pages.Add(currentPage);
                            currentPage = null;
                        }
                        else if (name == "Subsection")
                        {
                            currentPage.Sections.Add(currentSubsection);
                            currentSubsection = null;
                        }
                        else if (name == "Questions")
                        {
                            currentSubsection.Questions = currentQuestions;
                            currentQuestions = null;
                        }
                        break;
                }
            }
            return qset;
        }