Пример #1
0
        protected void btnImportIQTestQuestionsSet_Click(object sender, EventArgs e)
        {
            List <IQTestQuestionsSet> questionsSetList = new List <IQTestQuestionsSet>();

            string dataDirectoryPath = MapPath("~/App_Data/IQTest");

            string[] dataFilePaths = Directory.GetFiles(dataDirectoryPath, "IQTestQuestionsSet*.xml");

            foreach (string dataFilePath in dataFilePaths)
            {
                XmlDocument xd = new XmlDocument();
                xd.Load(dataFilePath);

                XmlElement xeQuestionsSet   = (XmlElement)xd.SelectSingleNode("QuestionsSet");
                string     questionsSetCode = xeQuestionsSet.GetAttribute("Code");

                IQTestQuestionsSet questionsSet = new IQTestQuestionsSet(questionsSetCode);

                foreach (XmlNode xnQuestion in xeQuestionsSet.SelectNodes("Question"))
                {
                    XmlElement xeQuestion = (XmlElement)xnQuestion;

                    string group         = xeQuestion.GetAttribute("Group");
                    int    code          = int.Parse(xeQuestion.GetAttribute("Code"));
                    string correctChoice = xeQuestion.GetAttribute("CorrectChoice");

                    IQTestQuestion question = new IQTestQuestion(group, code, correctChoice);
                    questionsSet.Questions.Add(question);
                }

                questionsSetList.Add(questionsSet);
            }

            if (questionsSetList.Count > 0)
            {
                using (var context = new ComputingServicesContext())
                {
                    foreach (var questionsSet in questionsSetList)
                    {
                        var oldQuestionsSet = context.IQTestQuestionsSets.Where(item => item.Code == questionsSet.Code).SingleOrDefault();
                        if (oldQuestionsSet != null)
                        {
                            context.IQTestQuestionsSets.Remove(oldQuestionsSet);
                        }
                        context.IQTestQuestionsSets.Add(questionsSet);
                    }
                    context.SaveChanges();
                }

                ltlLog.Text = "成功完成。";
            }
            else
            {
                ltlLog.Text = "没有数据。";
            }
        }
        private IQTestStandardResult GetIQTestStandardResult(IQTestPaperResult paperResult, IQTestQuestionsSet questionsSet, IQTestStandardParametersSet standardParametersSet)
        {
            int originalValue = 0;

            foreach (var questionAnswer in paperResult.QuestionAnswers)
            {
                var question = questionsSet.Questions.Single(item => item.Group == questionAnswer.QuestionGroup && item.Code == questionAnswer.QuestionCode);

                if (question.CorrectChoice == questionAnswer.Answer)
                {
                    originalValue += 1;
                }
            }

            IQTestStandardParameter standardParameter = standardParametersSet.Parameters.Where(item => originalValue >= item.OriginalScore).OrderByDescending(item => item.IQ).FirstOrDefault();

            if (standardParameter == null)
            {
                standardParameter = standardParametersSet.Parameters.OrderBy(item => item.IQ).First();
            }

            int IQ = standardParameter.IQ;

            IQLevel Level;

            if (IQ >= 130)
            {
                Level = IQLevel.EXCELLENT;
            }
            else if (IQ >= 120)
            {
                Level = IQLevel.GREAT;
            }
            else if (IQ >= 110)
            {
                Level = IQLevel.MEDIUM1;
            }
            else if (IQ >= 90)
            {
                Level = IQLevel.MEDIUM2;
            }
            else if (IQ >= 80)
            {
                Level = IQLevel.MEDIUM3;
            }
            else if (IQ >= 70)
            {
                Level = IQLevel.EDGE;
            }
            else if (IQ >= 55)
            {
                Level = IQLevel.BAD1;
            }
            else if (IQ >= 40)
            {
                Level = IQLevel.BAD2;
            }
            else if (IQ >= 25)
            {
                Level = IQLevel.BAD3;
            }
            else
            {
                Level = IQLevel.BAD4;
            }

            IQTestStandardResult standardResult = new IQTestStandardResult();

            standardResult.OriginalValue = originalValue;
            standardResult.Value         = IQ;
            standardResult.Level         = Level;
            standardResult.RefId         = paperResult.RefId;

            return(standardResult);
        }