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);
            }
        }
Exemplo n.º 2
0
        private static void CreateCondGroups(string code, BranchVM branch, ObservableCollection<QuestionConstructVM> questionConstructs)
        {
            CondParser parser = new CondParser(code);
            List<CondGroup> condGroupElems  = parser.Parse();

            foreach (CondGroup condGroupElem in condGroupElems)
            {
                CondGroupVM condGroup = new CondGroupVM()
                {
                    Parent = branch
                };
                condGroup.SelectedConnectionCode = Option.FindCodeByLabel(Options.Connections, condGroupElem.Connector);
                branch.CondGroups.Add(condGroup);

                foreach (Cond condElem in condGroupElem.Conds)
                {
                    CondVM cond = new CondVM()
                    {
                        Parent = condGroup
                    };
                    condGroup.Conds.Add(cond);
                    cond.SelectedQuestionConstruct = QuestionConstructVM.FindQuestionConstructByNo(questionConstructs, condElem.LeftValue);
                    cond.SelectedOperatorCode = Option.FindCodeByLabel(Options.Operators, condElem.Operator);
                    cond.CondValue = condElem.RightValue;
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public BranchVM DeepCopy()
        {
            BranchVM newBranch = new BranchVM(TypeCode);

            newBranch.Parent = Parent;
            newBranch.Init();
            newBranch.IsNew         = IsNew;
            newBranch.ThenConstruct = ThenConstruct;
            newBranch.CondGroups.Clear();
            foreach (CondGroupVM condGroup in condGroups)
            {
                CondGroupVM newGroup = condGroup.DeepCopy(newBranch);
                newBranch.CondGroups.Add(newGroup);
            }
            return(newBranch);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void SubmitEditingBranch()
        {
            if (selectedBranch == null || editingBranch == null)
            {
                return;
            }

            int index = branches.IndexOf(selectedBranch);

            branches.RemoveAt(index);
            branches.Insert(index, editingBranch);
            editingBranch.IsNew = false;

            selectedBranch = null;
            EditingBranch  = null;

            OnBranchOrderChanged(); // Necessary for displaying Add button of branch(Adding ELSE  clause)
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public bool CanChangeType(BranchVM branch)
 {
     if (!branch.IsNew)
     {
         return(false);
     }
     if (branch.IsTypeIf)
     {
         return(false);
     }
     foreach (BranchVM b in branches)
     {
         if (b.IsTypeElse)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 10
0
        public void AddBranch(BranchVM branch)
        {
            int index = Branches.IndexOf(branch);

            //Add ELSE IF ~ THEN ~
            BranchVM elseIfBranch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE)
            {
                Parent = this,
                IsNew  = true
            };

            elseIfBranch.Init();
            branches.Insert(index + 1, elseIfBranch);
            OnBranchOrderChanged();

            Editor.Dispatcher.BeginInvoke(
                DispatcherPriority.Background,
                new Action(() => { elseIfBranch.EditBranch(); }));
        }
Exemplo n.º 11
0
 public void CancelEditingBranch()
 {
     selectedBranch = null;
     EditingBranch = null;
 }
Exemplo n.º 12
0
 public bool CanRemoveBranch(BranchVM branch)
 {
     if (EditingBranch != null)
     {
         return false;
     }
     return !branch.IsTypeIf;
 }
Exemplo n.º 13
0
 public void EditBranch(BranchVM branch)
 {
     selectedBranch = branch;
     selectedBranch.OnEditStarted();
     EditingBranch = selectedBranch.DeepCopy();
 }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
0
 private static ElseIf CreateElseIf(BranchVM branch)
 {
     ElseIf elseIf = new ElseIf();
     elseIf.IfCondition = CreateIfCondition(branch.ValidCondGroups);
     elseIf.ThenConstructId = branch.ThenConstruct.Id;
     return elseIf;
 }
Exemplo n.º 16
0
 public bool CanChangeType(BranchVM branch)
 {
     if (!branch.IsNew)
     {
         return false;
     }
     if (branch.IsTypeIf)
     {
         return false;
     }
     foreach (BranchVM b in branches)
     {
         if (b.IsTypeElse)
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 17
0
        public void SubmitEditingBranch()
        {
            if (selectedBranch == null || editingBranch == null)
            {
                return;
            }

            int index = branches.IndexOf(selectedBranch);
            branches.RemoveAt(index);
            branches.Insert(index, editingBranch);
            editingBranch.IsNew = false;

            selectedBranch = null;
            EditingBranch = null;

            OnBranchOrderChanged(); // 分岐追加ボタンを表示するために必要(ELSE節の追加)
        }
Exemplo n.º 18
0
 public void RemoveBranch(BranchVM branch)
 {
     Branches.Remove(branch);
     OnBranchOrderChanged();
     if (editingBranch != null)
     {
         editingBranch.OnOrderChanged();
     }
 }
Exemplo n.º 19
0
 public void EditBranch(BranchVM branch)
 {
     selectedBranch = branch;
     selectedBranch.OnEditStarted();
     EditingBranch = selectedBranch.DeepCopy();
 }
Exemplo n.º 20
0
 public bool CanEditBranch(BranchVM branch)
 {
     return(EditingBranch == null);
 }
Exemplo n.º 21
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;
 }
Exemplo n.º 22
0
 public static CondGroupVM CreateDefault(BranchVM parent)
 {
     CondGroupVM condGroup = new CondGroupVM() { Parent = parent };
     CondVM cond = CondVM.CreateDefault(condGroup);
     condGroup.Conds.Add(cond);
     return condGroup;
 }
Exemplo n.º 23
0
 public bool CanAddBranch(BranchVM branch)
 {
     if (EditingBranch != null)
     {
         return false;
     }
     if (branch.IsTypeElse)
     {
         //ELSE節には追加できない
         return false;
     }
     if (branches.Count == 0)
     {
         return false;
     }
     // IF or ELSE IFの場合、最後のブランチか、ELSEの1つ前ならば良い
     if (branches.Last() == branch)
     {
         return true;
     }
     if (branches.Count < 2)
     {
         return false;
     }
     int size = branches.Count;
     if (branches.Last().IsTypeElse && branches[size - 2] == branch)
     {
         return true;
     }
     return false;
 }
Exemplo n.º 24
0
 public void CancelEditingBranch()
 {
     selectedBranch = null;
     EditingBranch  = null;
 }
Exemplo n.º 25
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;
 }
Exemplo n.º 26
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;
 }
Exemplo n.º 27
0
 public bool CanEditBranch(BranchVM branch)
 {
     return EditingBranch == null;
 }
Exemplo n.º 28
0
 public BranchVM DeepCopy()
 {
     BranchVM newBranch = new BranchVM(TypeCode);
     newBranch.Parent = Parent;
     newBranch.Init();
     newBranch.IsNew = IsNew;
     newBranch.ThenConstruct = ThenConstruct;
     newBranch.CondGroups.Clear();
     foreach (CondGroupVM condGroup in condGroups)
     {
         CondGroupVM newGroup = condGroup.DeepCopy(newBranch);
         newBranch.CondGroups.Add(newGroup);
     }
     return newBranch;
 }
Exemplo n.º 29
0
        public void AddBranch(BranchVM branch)
        {
            int index = Branches.IndexOf(branch);

            //ELSE IF~THEN~を追加
            BranchVM elseIfBranch = new BranchVM(BranchVM.TYPE_ELSE_IF_CODE)
            {
                Parent = this,
                IsNew = true
            };
            elseIfBranch.Init();
            branches.Insert(index + 1, elseIfBranch);
            OnBranchOrderChanged();

            Editor.Dispatcher.BeginInvoke(
                DispatcherPriority.Background,
                new Action(() => { elseIfBranch.EditBranch(); }));
        }