Пример #1
0
        public void EndEdit()
        {
            if (!inEdit)
            {
                return;
            }
            inEdit = false;
            bakCode = null;
            bakLabel = null;

            StudyUnit.CompleteResponse();
            //            if (EndEditAction != null)
            //            {
            //                EndEditAction(this);
            //            }
            Memorize();
        }
Пример #2
0
 public CodeVM(Code code, CategoryVM category)
 {
     this.code = code;
     this.Category = category;
 }
Пример #3
0
 public void BeginEdit()
 {
     if (inEdit)
     {
         return;
     }
     inEdit = true;
     bakCode = code.Clone() as Code;
     bakLabel = this.Label;
 }
Пример #4
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;
        }
Пример #5
0
        public static CodeScheme CreateCodeScheme(XElement codeSchemeElem)
        {
            string id = (string)codeSchemeElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            CodeScheme codeSchemeModel = new CodeScheme();
            codeSchemeModel.Id = id;
            codeSchemeModel.Title = (string)codeSchemeElem.Element(r + TAG_LABEL);
            codeSchemeModel.Memo = (string)codeSchemeElem.Element(r + TAG_DESCRIPTION);

            IEnumerable<XElement> elements = codeSchemeElem.Elements(l + TAG_CODE);
            foreach (XElement codeElem in elements)
            {
                //string codeId = (string)codeElem.Attribute(ATTR_ID);
                //if (codeId == null)
                //{
                //    continue;
                //}
                Code codeModel = new Code();
                //codeModel.Id = codeId;
                codeModel.CategoryId = ReadReferenceID(codeElem, l + TAG_CATEGORY_REFERENCE);
                codeModel.Value = (string)codeElem.Element(l + TAG_VALUE);
                codeSchemeModel.Codes.Add(codeModel);
            }

            return codeSchemeModel;
        }
Пример #6
0
 private void AddCodes(ICollection<CategoryVM> categories)
 {
     foreach (CategoryVM category in categories)
     {
         Code codeModel = new Code();
         SelectedCodeScheme.Codes.Add(new CodeVM(codeModel, category));
     }
     Memorize();
 }
Пример #7
0
        private static CategorySchemeItem CreateCategorySchemeItem(XElement varElem, Variable variable)
        {
            XElement catgryGrpElem = varElem.Element(cb + TAG_CATGRY_GRP);
            if (catgryGrpElem == null)
            {
                return null;
            }
            string title = (string)catgryGrpElem.Element(cb + TAG_LABL);
            if (string.IsNullOrEmpty(title))
            {
                return null;
            }
            string memo = (string)catgryGrpElem.Element(cb + TAG_TXT);
            CategoryScheme categoryScheme = new CategoryScheme()
            {
                Title = title,
                Memo = memo
            };
            CodeScheme codeScheme = new CodeScheme()
            {
                Title = title,
                Memo = memo
            };
            IEnumerable<XElement> catgryElems = varElem.Elements(cb + TAG_CATGRY);
            foreach (XElement catgryElem in catgryElems)
            {
                title = (string)catgryElem.Element(cb + TAG_LABL);
                memo = (string)catgryElem.Element(cb + TAG_TXT);
                string v = (string)catgryElem.Element(cb + TAG_CAT_VALU);

                Category category = new Category() {
                    Title = title,
                    Memo = memo
                };
                category.CategorySchemeId = categoryScheme.Id;
                categoryScheme.Categories.Add(category);

                Code code = new Code()
                {
                    Value = v
                };
                code.CodeSchemeId = codeScheme.Id;
                code.CategoryId = category.Id;
                codeScheme.Codes.Add(code);
            }
            variable.Response.CodeSchemeId = codeScheme.Id;
            return new CategorySchemeItem(categoryScheme, codeScheme);
        }