示例#1
0
        private bool CheckCond(Field field)
        {
            if (string.IsNullOrEmpty(field.Cond))
            {
                return(true);
            }
            var jsInterpreter = new Javascript.Interpreter();

            return(jsInterpreter.GetCondResult(field.Cond, answers));
        }
示例#2
0
        public List <string> AddAnswer(string fieldName, string answer)
        {
            var info = new List <string>();

            //dodaj odpowiedz
            if (answers.ContainsKey(fieldName))
            {
                answers.Remove(fieldName);
            }
            answers.Add(fieldName, answer);

            //znajdz pole
            var form  = filesForms[currentFile].First(w => w.Id == currentForm);
            var field = form.Fields.First(f => f.Name == fieldName);

            //uruchom ify jeśli są
            if (field.FilledIfs != null)
            {
                var jsInterpreter = new Javascript.Interpreter();
                var ifsToRun      = field.FilledIfs.Where(w => jsInterpreter.GetCondResult(w.Cond, answers));

                //Jak dojdą kolejne ify to trzeba dodać obsługe, dla other nic nie robimy?
                var exitIf = ifsToRun.FirstOrDefault(a => a.Type == FilledIfType.ExitIf);
                if (exitIf != null)
                {
                    IsDialogFinished = true;
                    return(info);
                }

                foreach (var assignIf in ifsToRun.Where(w => w.Type == FilledIfType.Assign))
                {
                    var newValue = jsInterpreter.GetAssignScriptResult(assignIf.Expr, assignIf.Name, answers);
                    answers.Remove(assignIf.Name);
                    if (newValue != null)
                    {
                        answers.Add(assignIf.Name, newValue);
                    }
                    info.Add(assignIf.Prompt);
                }
            }

            //ustaw następne pole
            var nextFieldInForm = GetNextField();

            if (nextFieldInForm is null)
            {
                IsDialogFinished = true;
            }
            return(info);
        }