Example #1
0
        private bool isSatisfiesAllTheRulesSingleChoice(Regra regra, int page)
        {
            string operador = regra.Operador;

            int[]      ruleOptions     = regra.Opcoes;
            List <int> optionsSelected = GetRespostaSelected(page);

            if (ruleOptions.Count() <= 0)
            {
                return(false);
            }

            int value = (int)ruleOptions.GetValue(0);

            if (operador == "+")
            {
                return(optionsSelected.Contains(value));
            }

            if (operador == "-")
            {
                return(!optionsSelected.Contains(value));
            }
            else if (string.IsNullOrEmpty(operador))
            {
                return(optionsSelected.Count == 0);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        private bool isSatisfiesAllTheRulesMultipleChoice(Regra regra, int page)
        {
            string operador = regra.Operador;

            int[]      ruleOptions     = regra.Opcoes;
            List <int> optionsSelected = GetRespostaSelected(page);

            if (operador == "*")
            {
                return(optionsSelected.Count == _questoes[page].getResposta().Count);//((Question)this.surveyList.get(page)).getOptions().getValues().size();
            }
            else
            {
                if (operador == "+")
                {
                    return(optionsSelected.Except(ruleOptions).Any());
                }
                if (operador == "-")
                {
                    return(!optionsSelected.Except(ruleOptions).Any());
                }
                else if (string.IsNullOrEmpty(operador))
                {
                    return(optionsSelected.Count == 0);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #3
0
        private bool isSatisfiesAllTheRulesOpenChoice(Regra regra, int page)
        {
            bool satisfiesAllTheRules = false;

            try
            {
                string        operador          = regra.Operador;
                List <string> openOptionsValues = _openOptions[page];
                foreach (int opcao in regra.Opcoes)
                {
                    int pos  = opcao;
                    int type = _questoes[page].TipoQuestao;
                    if (type == 3)
                    {
                        satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(openOptionsValues[pos]), regra.Compativel);
                        continue;
                    }
                    else if (type == 1)
                    {
                        try
                        {
                            DateTime optionDate = convertToDate(openOptionsValues[pos]);
                            DateTime ruleDate   = convertToDate(regra.Compativel.ToString());
                            if (!(optionDate == null || ruleDate == null))
                            {
                                satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(optionDate.GetDateTimeFormats()), Convert.ToInt64(ruleDate.GetDateTimeFormats()));
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            continue;
                        }
                    }
                    else if (type == 2)
                    {
                        try
                        {
                            DateTime optionTime = convertToTime(openOptionsValues[pos]);
                            DateTime ruleTime   = convertToTime(regra.Compativel.ToString());
                            if (!(optionTime == null || ruleTime == null))
                            {
                                satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(optionTime.GetDateTimeFormats()), Convert.ToInt64(ruleTime.GetDateTimeFormats()));
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                    if (satisfiesAllTheRules)
                    {
                        return(satisfiesAllTheRules);
                    }
                }
                //for (int i = 0; i < regra.Opcoes.Count(); i++)
                //{
                //    int pos = i;
                //    int type = _questoes[page].TipoQuestao;
                //    if (type == 3)
                //    {
                //        satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(openOptionsValues[pos]), regra.Compativel);
                //        continue;
                //    }
                //    else if (type == 1)
                //    {
                //        try
                //        {
                //            DateTime optionDate = convertToDate(openOptionsValues[pos]);
                //            DateTime ruleDate = convertToDate(regra.Compativel.ToString());
                //            if (!(optionDate == null || ruleDate == null))
                //            {
                //                satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(optionDate.GetDateTimeFormats()), Convert.ToInt64(ruleDate.GetDateTimeFormats()));
                //                continue;
                //            }
                //        }
                //        catch (Exception e)
                //        {
                //            continue;
                //        }
                //    }
                //    else if (type == 2)
                //    {
                //        try
                //        {
                //            DateTime optionTime = convertToTime(openOptionsValues[pos]);
                //            DateTime ruleTime = convertToTime(regra.Compativel.ToString());
                //            if (!(optionTime == null || ruleTime == null))
                //            {
                //                satisfiesAllTheRules = compareValuesWithOperator(operador, Convert.ToInt64(optionTime.GetDateTimeFormats()), Convert.ToInt64(ruleTime.GetDateTimeFormats()));
                //                continue;
                //            }
                //        }
                //        catch (Exception e)
                //        {
                //            continue;
                //        }
                //    }
                //    else
                //    {
                //        continue;
                //    }
                //    if (satisfiesAllTheRules)
                //    {
                //        return satisfiesAllTheRules;
                //    }
                //}
                return(satisfiesAllTheRules);
            }
            catch (Exception e)
            {
                Log.Error(TAG, e.Message, e);
                return(false);
            }
        }
Example #4
0
        public int NextPage(int current, List <Logica> logica)
        {
            int jumpToPage = current + 1;

            if (logica == null || logica.Count <= 0)
            {
                return(jumpToPage);
            }

            IEnumerable <Logica> IELogica = logica;
            var ITLogica = IELogica.GetEnumerator();

            while (ITLogica.MoveNext())
            {
                Logica log  = ITLogica.Current;
                bool   temp = true;
                bool   containsCurrentPage = false;

                IEnumerable <Regra> IERegras = log.Regras;
                var ITRegra = IERegras.GetEnumerator();
                int page    = 0;
                while (ITRegra.MoveNext())
                {
                    Regra regra = ITRegra.Current;
                    page = pageFrom(regra.QuestaoId);
                    containsCurrentPage = page == current;
                    if (page > -1)
                    {
                        Questao questao = _questoes[page];
                        if (questao.TipoQuestao == 0)
                        {
                            temp &= true;
                            continue;
                        }
                        else if (questao.TipoQuestao == 1)
                        {
                            temp &= true;
                            continue;
                        }
                        else if (questao.TipoQuestao == 2)
                        {
                            temp &= true;
                            continue;
                        }
                        else if (questao.TipoQuestao == 3)
                        {
                            temp &= true;
                            continue;
                        }
                        else if (questao.TipoQuestao == 4)
                        {
                            temp &= true;
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (!temp)
                    {
                        break;
                    }
                }
                if (temp && containsCurrentPage)
                {
                    string action = log.Acao;
                    if (action == "finish")
                    {
                        return(int.MaxValue);
                    }
                    if (!action.StartsWith("jump_"))
                    {
                        return(jumpToPage);
                    }
                    page = pageFrom(Convert.ToInt16(action.Replace("jump_", "")));
                    if (page <= -1 || page <= current)
                    {
                        return(jumpToPage);
                    }
                    return(page);
                }
            }
            return(jumpToPage);
        }