public static bool Contains(List<QuestionGroup> questionGroups, Question question)
 {
     foreach (QuestionGroup questionGroup in questionGroups)
     {
         if (questionGroup.Contains(question.Id))
         {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
        private XElement CreateQuestionItem(Question questionModel)
        {
            //d:QuestionItem+(表示名、質問文は自動設定されるのでnullチェック不要)
            XElement questionItem = new XElement(d + TAG_QUESTION_ITEM,
                CreateIDAttribute(questionModel.Id),
                new XElement(d + TAG_QUESTION_ITEM_NAME, questionModel.Title), //QuestionItemName*
                new XElement(d + TAG_QUESTION_TEXT, //QuestionText*
                    new XElement(d + TAG_LITERAL_TEXT, //LiteralTextText+
                        new XElement(d + TAG_TEXT, questionModel.Text))));//Text

            //d:ResponseDomain
            XElement response = null;
            Response responseModel = questionModel.Response;
            if (responseModel.IsTypeChoices)
            {
                response = CreateCodeResponse(d + TAG_CODE_DOMAIN, responseModel);
                response.Add(new XElement(d + TAG_LABEL, responseModel.Title));
            }
            else if (responseModel.IsTypeNumber)
            {
                if (responseModel.DetailTypeCode == null)
                {
                    MenuItemVM menuItem = studyUnit.FindMenuItem(studyUnit.QuestionForm);
                    AddError(Resources.SelectNumberType, studyUnit.QuestionForm); //数値の型を選択してください
                }
                else if (responseModel.Min == null || responseModel.Max == null)
                {
                    AddError(Resources.InputMinAndMax, studyUnit.QuestionForm); //最大値・最小値を入力してください
                }
                else
                {
                    response = CreateNumberResponse(d + TAG_NUMERIC_DOMAIN, responseModel);
                    response.Add(new XElement(d + TAG_LABEL, responseModel.Title));
                }
            }
            else if (responseModel.IsTypeFree)
            {
                if (responseModel.Min == null || responseModel.Max == null)
                {
                    AddError(Resources.InputMinAndMax, studyUnit.QuestionForm); //最大値・最小値を入力してください
                }
                else
                {
                    response = CreateTextResponse(d + TAG_TEXT_DOMAIN, responseModel);
                    response.Add(new XElement(r + TAG_LABEL, responseModel.Title));
                }
            }
            else if (responseModel.IsTypeDateTime)
            {
                if (responseModel.DetailTypeCode == null)
                {
                    AddError(Resources.SelectDateType, studyUnit.QuestionForm); //日付の型を選択してください
                }
                else
                {
                    response = CreateDateTimeResponse(d + TAG_DATE_TIME_DOMAIN, responseModel);
                    response.Add(new XElement(d + TAG_LABEL, responseModel.Title));
                }
            }
            questionItem.Add(response);
            //ConceptReference*
            XElement conceptReference = CreateReferenceID(d + TAG_CONCEPT_REFERENCE, questionModel.ConceptId, ConceptSchemeId(questionModel.ConceptId));
            questionItem.Add(conceptReference);

            return questionItem;
        }
Beispiel #3
0
 // 読み込み用のコンストラクタとデフォルトコンストラクタで処理が異なるので
 // コンストラクタのオーバーロードは利用していない.
 public QuestionVM()
 {
     //新規データ追加用のコンストラクタ
     this.question = new Question();
     this.Response = new ResponseVM(question.Response);
 }
Beispiel #4
0
 public QuestionVM(Question question)
 {
     //データ読み込み用のコンストラクタ
     //Responseは後でセットするので引数としては渡さない
     this.question = question;
 }
Beispiel #5
0
        public void BeginEdit()
        {
            if (inEdit)
            {
                return;
            }
            inEdit = true;

            bakQuestion = question.Clone() as Question;
            bakResponseTypeCode = response.TypeCode;
        }
Beispiel #6
0
        public void EndEdit()
        {
            if (!inEdit)
            {
                return;
            }
            inEdit = false;

            bakQuestion = null;
            bakResponseTypeCode = null;
            Memorize();
        }
Beispiel #7
0
        public bool Read(string path, StudyUnitVM studyUnit)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));
            StudyUnit studyUnitModel = studyUnit.StudyUnitModel;
            FileStream stream = File.OpenRead(path);
            SavFileParser parser = new SavFileParser(stream);
            List<Variable> variables = new List<Variable>();
            foreach (SpssLib.SpssDataset.Variable v in parser.Variables)
            {
                Variable variable = new Variable();
                variable.Title = v.Name;
                variable.Label = v.Label;
                variables.Add(variable);
                if (v.Type == SpssLib.SpssDataset.DataType.Text)
                {
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                }
                else
                {
                    if (v.ValueLabels.Count > 0)
                    {
                        CategoryScheme categoryScheme = new CategoryScheme();
                        categoryScheme.Title = v.Label;
                        studyUnitModel.CategorySchemes.Add(categoryScheme);
                        CodeScheme codeScheme = new CodeScheme();
                        codeScheme.Title = v.Label; ;
                        studyUnitModel.CodeSchemes.Add(codeScheme);

                        variable.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variable.Response.CodeSchemeId = codeScheme.Id;
                        // 選択肢の作成
                        foreach (KeyValuePair<double, string> pair in v.ValueLabels)
                        {
                            Category category = new Category();
                            categoryScheme.Categories.Add(category);
                            category.Title = pair.Value;
                            category.CategorySchemeId = categoryScheme.Id;

                            Code code = new Code();
                            codeScheme.Codes.Add(code);
                            code.CategoryId = category.Id;
                            code.CodeSchemeId = codeScheme.Id;
                            code.Value = pair.Key.ToString();
                        }
                        // 欠損値の追加
                        if (v.MissingValues.Count > 0)
                        {
                            foreach (double missingValue in v.MissingValues)
                            {
                                string missingValueStr = missingValue.ToString();
                                if (ExistValue(codeScheme, missingValueStr))
                                {
                                    continue;
                                }
                                Category category = new Category();
                                categoryScheme.Categories.Add(category);
                                category.Title = Resources.MissingValue; //欠損値
                                category.IsMissingValue = true;
                                category.CategorySchemeId = categoryScheme.Id;

                                Code code = new Code();
                                codeScheme.Codes.Add(code);
                                code.CategoryId = category.Id;
                                code.CodeSchemeId = codeScheme.Id;
                                code.Value = missingValueStr;
                            }
                        }
                    }
                    else
                    {
                        variable.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                    }
                }
            }

            if (variables.Count > 0)
            {
                ConceptScheme conceptScheme = new ConceptScheme();
                conceptScheme.Title = EDOUtils.UniqueLabel(ConceptScheme.GetTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable); //インポートした変数
                string name = Path.GetFileName(path);
                conceptScheme.Memo = EDOUtils.UniqueLabel(ConceptScheme.GetMemos(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name)); //{0}からインポートした変数

                Concept concept = new Concept();
                concept.Title = EDOUtils.UniqueLabel(ConceptScheme.GetConceptTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable);//インポートした変数
                concept.Content = EDOUtils.UniqueLabel(ConceptScheme.GetConceptContents(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name));//{0}からインポートした変数
                conceptScheme.Concepts.Add(concept);
                studyUnitModel.ConceptSchemes.Add(conceptScheme);

                foreach (Variable variable in variables)
                {
                    Question question = new Question();
                    question.Title = variable.Label;
                    question.ConceptId = concept.Id;
                    question.Response.TypeCode = variable.Response.TypeCode;
                    question.Response.CodeSchemeId = variable.Response.CodeSchemeId;
                    studyUnitModel.Questions.Add(question);

                    variable.ConceptId = concept.Id;
                    variable.QuestionId = question.Id;
                    studyUnitModel.Variables.Add(variable);

                }
            }
            return true;
        }
Beispiel #8
0
        public static Question CreateQuestion(XElement questionElem)
        {
            string id = (string)questionElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            Question question = new Question();
            question.Id = id;

            //タイトル
            question.Title = (string)questionElem.Element(d + TAG_QUESTION_ITEM_NAME);
            //テキスト
            XElement questionTextElem = questionElem.Element(d + TAG_QUESTION_TEXT);
            if (questionTextElem != null)
            {
                XElement literalTextElem = questionTextElem.Descendants(d + TAG_TEXT).FirstOrDefault();
                if (literalTextElem != null)
                {
                    question.Text = literalTextElem.Value;
                }
            }
            //コンセプト
            string conceptId = ReadReferenceID(questionElem, d + TAG_CONCEPT_REFERENCE);
            question.ConceptId = conceptId;

            //種類
            XElement codeDomainElem = questionElem.Element(d + TAG_CODE_DOMAIN);
            XElement numericDomainElem = questionElem.Element(d + TAG_NUMERIC_DOMAIN);
            XElement textDomainElem = questionElem.Element(d + TAG_TEXT_DOMAIN);
            XElement dateTimeDomain = questionElem.Element(d + TAG_DATE_TIME_DOMAIN);
            if (codeDomainElem != null)
            {
                question.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
                question.Response.Title = (string)codeDomainElem.Element(d + TAG_LABEL);
                question.Response.CodeSchemeId = ReadReferenceID(codeDomainElem, r + TAG_CODE_SCHEME_REFERENCE);

            } else if (numericDomainElem != null)
            {
                //数値の場合の回答
                question.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                question.Response.Title = (string)numericDomainElem.Element(d + TAG_LABEL);
                string numericTypeLabel = (string)numericDomainElem.Attribute(ATTR_TYPE);
                question.Response.DetailTypeCode = Options.NumberTypeCode(numericTypeLabel);
                XElement numerRangeElem = numericDomainElem.Element(r + TAG_NUMBER_RANGE);
                if (numerRangeElem != null)
                {
                    question.Response.Min = (decimal?)numerRangeElem.Element(r + TAG_LOW);
                    question.Response.Max = (decimal?)numerRangeElem.Element(r + TAG_HIGH);
                }
                question.Response.MissingValues = CreateMissingValues(numericDomainElem);
            } else if (textDomainElem != null)
            {
                //自由テキストの回答
                question.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                question.Response.Title = (string)textDomainElem.Element(r + TAG_LABEL);
                question.Response.Min = (decimal?)textDomainElem.Attribute(ATTR_MIN_LENGTH);
                question.Response.Max = (decimal?)textDomainElem.Attribute(ATTR_MAX_LENGTH);
                question.Response.MissingValues = CreateMissingValues(textDomainElem);
            }
            else if (dateTimeDomain != null)
            {
                //日付の回答
                question.Response.TypeCode = Options.RESPONSE_TYPE_DATETIME_CODE;
                question.Response.Title = (string)dateTimeDomain.Element(d + TAG_LABEL);
                string typeLabel = (string)dateTimeDomain.Attribute(ATTR_TYPE);
                question.Response.DetailTypeCode = Options.DateTimeTypeCode(typeLabel);
                question.Response.MissingValues = CreateMissingValues(dateTimeDomain);
            }
            else
            {
                return null;
            }
            return question;
        }
Beispiel #9
0
 public bool ContainsInQuestionGroup(Question question)
 {
     return QuestionGroup.Contains(QuestionGroups, question);
 }
Beispiel #10
0
 private static Question CreateQuestion(XElement varElem)
 {
     string id = (string)varElem.Attribute(ATTR_ID);
     if (string.IsNullOrEmpty(id))
     {
         return null;
     }
     XElement qstnElem = varElem.Element(cb + TAG_QSTN);
     if (qstnElem == null)
     {
         return null;
     }
     string type = (string)qstnElem.Attribute(ATTR_RESPONSE_DOMAIN_TYPE);
     Question question = null;
     if (type == "category")
     {
         //選択肢
         question = new Question();
         question.Response.TypeCode = Options.RESPONSE_TYPE_CHOICES_CODE;
     }
     else if (type == "numeric")
     {
         question = new Question();
         question.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
     }
     else if (type == "text")
     {
         question = new Question();
         question.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
     }
     else if (type == "datetime")
     {
         question = new Question();
         question.Response.TypeCode = Options.RESPONSE_TYPE_DATETIME_CODE;
     }
     else
     {
         return null;
     }
     question.Id = id;
     question.Title = (string)qstnElem.Attribute(ATTR_NAME);
     question.Text = (string)qstnElem.Element(cb + TAG_QSTN_LIT);
     return question;
 }
Beispiel #11
0
 public VariableItem(Variable variable, Question question, CategorySchemeItem categorySchemeItem)
 {
     Variable = variable;
     Question = question;
     CategorySchemeItem = categorySchemeItem;
 }