Exemple #1
0
        public double Calculate(out ResultDictionary results)
        {
            var dataTable = new DataTable();

            foreach (var atributo in Parameters.Atributos)
            {
                string attributeName = GetAttributeName(atributo.AtributoId);
                var    type          = atributo.Valor?.GetType() ?? typeof(object);
                dataTable.Columns.Add(attributeName, type);
            }

            foreach (var regra in Parameters.Regras)
            {
                dataTable.Columns.Add("Regra_" + regra.Id, typeof(bool), GetCriteriosAsFormula(regra));
                dataTable.Columns.Add("Formula_" + regra.Id, typeof(double), regra.Formula);
            }

            var dataRow = dataTable.NewRow();

            foreach (var atributo in Parameters.Atributos)
            {
                string attributeName = GetAttributeName(atributo.AtributoId);
                dataRow[attributeName] = atributo.Valor;
            }
            dataTable.Rows.Add(dataRow);

            var    partialResults = new ResultDictionary();
            double result         = 0;

            foreach (var regra in Parameters.Regras)
            {
                var    objResult     = dataRow["Formula_" + regra.Id];
                double partialResult = 0;
                double.TryParse(objResult.ToString(), out partialResult);
                if (dataRow["Regra_" + regra.Id].Equals(true))
                {
                    result += partialResult;
                    partialResults.Add(dataTable.Columns["Formula_" + regra.Id].Expression, partialResult);
                }
            }
            results = partialResults;
            return(result);
        }
Exemple #2
0
        public double Calculate()
        {
            ResultDictionary results = null;

            return(Calculate(out results));
        }