public CreateBranchWindowVM(ControlConstructSchemeVM controlConstructScheme, IfThenElse ifThenElse)
        {
            this.controlConstructScheme = controlConstructScheme;

            questionConstructs = new ObservableCollection<QuestionConstructVM>();
            questionConstructs.AddRange(controlConstructScheme.QuestionConstructs);

            thenConstructs = new ObservableCollection<ConstructVM>();
            thenConstructs.AddRange(controlConstructScheme.ThenConstructs);

            if (ifThenElse == null)
            {
                //新規作成の場合

                TargetQuestionConstruct = controlConstructScheme.SelectedConstruct as QuestionConstructVM;
                branches = new ObservableCollection<BranchVM>();
                //IF~THENを追加
                BranchVM ifBranch = new BranchVM(BranchVM.TYPE_IF_CODE)
                {
                    Parent = this,
                    No = 1,
                };
                ifBranch.Init();
                branches.Add(ifBranch);
            }
            else
            {
                // 編集の場合

                TargetQuestionConstruct = EDOUtils.Find(controlConstructScheme.QuestionConstructs, ifThenElse.IfCondition.QuestionId);
                branches = SequenceUtils.CreateBranches(ifThenElse, this);
            }
        }
Example #2
0
 public static ObservableCollection<BranchVM> CreateBranches(IfThenElse ifThenElse, CreateBranchWindowVM window)
 {
     ObservableCollection<BranchVM> branches = new ObservableCollection<BranchVM>();
     BranchVM ifBranch = CreateIfBranch(ifThenElse, window);
     branches.Add(ifBranch);
     List<BranchVM> elseIfBranches = CreateElseIfBranches(ifThenElse, window);
     branches.AddRange(elseIfBranches);
     BranchVM elseBranch = CreateElseBranch(ifThenElse, window);
     if (elseBranch != null)
     {
         branches.Add(elseBranch);
     }
     return branches;
 }
 public void InsertIfThenElseConstruct(IfThenElse ifThenElseModel)
 {
     if (ifThenElseModel == null)
     {
         return;
     }
     ifThenElseModel.No = ControlConstructScheme.IFTHENELSE_NO;
     IfThenElseVM ifThenElse = new IfThenElseVM(ifThenElseModel);
     ifThenElse.ThenConstructs = ThenConstructs;
     InsertConstruct(ifThenElse, true);
 }
Example #4
0
        public static ControlConstructScheme CreateControlConstructScheme(XElement controlConstructSchemeElem, StudyUnit studyUnit)
        {
            string id = (string)controlConstructSchemeElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            ControlConstructScheme controlConstructSchemeModel = new ControlConstructScheme();
            controlConstructSchemeModel.Title = (string)controlConstructSchemeElem.Element(d + TAG_CONTROL_CONSTRUCT_SCHEME_NAME);
            IEnumerable<XElement> questionConstructElems = controlConstructSchemeElem.Elements(d + TAG_QUESTION_CONSTRUCT);
            foreach (XElement questionConstructElem in questionConstructElems)
            {
                string questionConstructId = (string)questionConstructElem.Attribute(ATTR_ID);
                if (questionConstructId == null)
                {
                    continue;
                }
                string questionId = ReadReferenceID(questionConstructElem, d + TAG_QUESTION_REFERENCE);
                if (questionId == null)
                {
                    continue;
                }
                string no = (string)questionConstructElem.Element(r + TAG_LABEL);
                if (no == null)
                {
                    continue;
                }
                if (studyUnit.FindQuestion(questionId) != null)
                {
                    QuestionConstruct questionConstruct = new QuestionConstruct();
                    questionConstruct.Id = questionConstructId;
                    questionConstruct.No = no;
                    questionConstruct.QuestionId = questionId;
                    controlConstructSchemeModel.QuestionConstructs.Add(questionConstruct);

                }
                else if (studyUnit.FindQuestionGroup(questionId) != null)
                {
                    QuestionGroupConstruct questionGroupConstruct = new QuestionGroupConstruct();
                    questionGroupConstruct.Id = questionConstructId;
                    questionGroupConstruct.No = no;
                    questionGroupConstruct.QuestionGroupId = questionId;
                    controlConstructSchemeModel.QuestionGroupConstructs.Add(questionGroupConstruct);
                }

            }

            IEnumerable<XElement> statementItemElems = controlConstructSchemeElem.Elements(d + TAG_STATEMENT_ITEM);
            foreach (XElement statementItemElem in statementItemElems)
            {
                string statementId = (string)statementItemElem.Attribute(ATTR_ID);
                if (statementId == null)
                {
                    continue;
                }
                string no = (string)statementItemElem.Attribute(r + TAG_LABEL);
                if (no == null)
                {
                    continue;
                }
                Statement statement = new Statement();
                statement.Id = statementId;
                statement.No = no;
                XElement textElem = statementItemElem.Descendants(d + TAG_TEXT).FirstOrDefault();
                if (textElem != null)
                {
                    statement.Text = textElem.Value;
                }
                controlConstructSchemeModel.Statements.Add(statement);
            }

            IEnumerable<XElement> ifThenElseElems = controlConstructSchemeElem.Elements(d + TAG_IF_THEN_ELSE);
            foreach (XElement ifThenElseElem in ifThenElseElems)
            {
                string ifThenElseId = (string)ifThenElseElem.Attribute(ATTR_ID);
                if (ifThenElseId == null)
                {
                    continue;
                }
                XElement ifConditionElem = ifThenElseElem.Element(d + TAG_IF_CONDITION);
                if (ifConditionElem == null)
                {
                    continue;
                }
                string thenConstructId = ReadReferenceID(ifThenElseElem, d + TAG_THEN_CONSTRUCT_REFERENCE);
                if (thenConstructId == null)
                {
                    continue;
                }

                IfThenElse ifThenElse = new IfThenElse();
                ifThenElse.Id = ifThenElseId;
                ifThenElse.No = ControlConstructScheme.IFTHENELSE_NO;
                ifThenElse.IfCondition.Code = (string)ifConditionElem.Element(r + TAG_CODE);
                ifThenElse.IfCondition.QuestionId = ReadReferenceID(ifConditionElem, r + TAG_SOURCE_QUESTION_REFERENCE);
                ifThenElse.ThenConstructId = thenConstructId;
                controlConstructSchemeModel.IfThenElses.Add(ifThenElse);

                IEnumerable<XElement> elseIfElems = ifThenElseElem.Elements(d + TAG_ELSE_IF);
                foreach (XElement elseIfElem in elseIfElems)
                {
                    XElement ifConditionElem2 = elseIfElem.Element(d + TAG_IF_CONDITION);
                    if (ifConditionElem2 == null)
                    {
                        continue;
                    }
                    string thenConstructId2 = ReadReferenceID(elseIfElem, d + TAG_THEN_CONSTRUCT_REFERENCE);
                    if (thenConstructId2 == null)
                    {
                        continue;
                    }
                    ElseIf elseIf = new ElseIf();
                    elseIf.IfCondition.Code = (string)ifConditionElem2.Element(r + TAG_CODE);
                    elseIf.IfCondition.QuestionId = ReadReferenceID(ifConditionElem2, r + TAG_SOURCE_QUESTION_REFERENCE);
                    elseIf.ThenConstructId = thenConstructId2;
                    ifThenElse.ElseIfs.Add(elseIf);
                }
            }

            XElement sequenceElem = controlConstructSchemeElem.Element(d + TAG_SEQUENCE);
            if (sequenceElem != null)
            {
                controlConstructSchemeModel.Sequence.Id = (string)sequenceElem.Attribute(ATTR_ID);
                IEnumerable<XElement> controlConstructReferenceElems = sequenceElem.Elements(d + TAG_CONTROL_CONSTRUCT_REFERENCE);
                foreach (XElement controlConstructReferenceElem in controlConstructReferenceElems)
                {
                    string controlConstructId = (string)controlConstructReferenceElem.Element(r + TAG_ID);
                    if (controlConstructId != null)
                    {
                        controlConstructSchemeModel.Sequence.ControlConstructIds.Add(controlConstructId);
                    }
                }
            }
            return controlConstructSchemeModel;
        }
Example #5
0
 public IfThenElseVM(IfThenElse ifThenElse)
     : base(ifThenElse)
 {
     this.ifThenElse = ifThenElse;
 }
Example #6
0
 private static BranchVM CreateElseBranch(IfThenElse ifThenElse, CreateBranchWindowVM window)
 {
     if (ifThenElse.ElseConstructId == null)
     {
         return null;
     }
     BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_CODE)
     {
         Parent = window
     };
     branch.Init();
     branch.CondGroups.Clear();
     branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ElseConstructId);
     return branch;
 }
Example #7
0
 private static IfThenElse CreateIfThenElse(BranchVM branch)
 {
     IfThenElse ifThenElse = new IfThenElse();
     ifThenElse.No = "-";
     ifThenElse.IfCondition = CreateIfCondition(branch.ValidCondGroups);
     ifThenElse.ThenConstructId = branch.ThenConstruct.Id;
     return ifThenElse;
 }
Example #8
0
 private static BranchVM CreateIfBranch(IfThenElse ifThenElse, CreateBranchWindowVM window)
 {
     BranchVM branch = new BranchVM(BranchVM.TYPE_IF_CODE)
     {
         Parent = window
     };
     branch.Init();
     branch.CondGroups.Clear();
     IfCondition ifCondition = ifThenElse.IfCondition;
     CreateCondGroups(ifCondition.Code, branch, window.QuestionConstructs);
     branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, ifThenElse.ThenConstructId);
     return branch;
 }
Example #9
0
 private static List<BranchVM> CreateElseIfBranches(IfThenElse ifThenElse, CreateBranchWindowVM window)
 {
     List<BranchVM> branches = new List<BranchVM>();
     List<ElseIf> elseIfs = ifThenElse.ElseIfs;
     foreach (ElseIf elseIf in elseIfs)
     {
         BranchVM branch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE)
         {
             Parent = window
         };
         branch.Init();
         branch.CondGroups.Clear();
         CreateCondGroups(elseIf.IfCondition.Code, branch, window.QuestionConstructs);
         branch.ThenConstruct = EDOUtils.Find(window.ThenConstructs, elseIf.ThenConstructId);
         branches.Add(branch);
     }
     return branches;
 }