Beispiel #1
0
        /// <summary>
        /// get the calcuation with the given name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public TRptCalculation GetCalculation(string name)
        {
            if (rptGrpCalculation == null)
            {
                return(null);
            }

            if ((name.Length == 0) || name.StartsWith("{") || (name == "true") || (name == "false"))
            {
                return(null);
            }

            name = name.ToLower();

            for (int counter = 0; counter < rptGrpCalculation.Count; counter++)
            {
                TRptCalculation element = (TRptCalculation)rptGrpCalculation[counter];

                if (element.strId.ToLower() == name)
                {
                    return(element);
                }
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// this function is used for calculations that are based on a function, e.g. variance
        /// it returns true, if the calcution returns "functionresult", OR IF IT'S NOT FOUND
        /// </summary>
        /// <returns>void</returns>
        public Boolean IsFunctionCalculation(TRptReport report, string name)
        {
            if (name.Length == 0)
            {
                return(false);
            }

            Boolean         ReturnValue    = true;
            TRptCalculation rptCalculation = GetCalculation(report, name);

            if (rptCalculation != null)
            {
                ReturnValue = (rptCalculation.strReturns == "functionresult");
            }

            return(ReturnValue);
        }
Beispiel #3
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="cur2"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        protected TRptCalculation ParseCalculation(XmlNode cur2, int order)
        {
            XmlNode cur;
            Object rg;
            TRptCalculation element;

            cur = cur2;
            element = new TRptCalculation(order);
            element.strId = GetAttribute(cur, "id");
            element.strReturnsFormat = GetAttribute(cur, "returnsFormat");
            element.strReturns = GetAttribute(cur, "returns");
            element.strAlign = GetAttribute(cur, "align");
            cur = NextNotBlank(cur.FirstChild);

            if (cur.Name == "caption")
            {
                rg = ParseGroup(cur.FirstChild, ref report.valuesId, "value");

                if (rg != null)
                {
                    element.rptGrpCaption = ((List <TRptValue> )rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "shortcaption")
            {
                rg = ParseGroup(cur.FirstChild, ref report.valuesId, "value");

                if (rg != null)
                {
                    element.rptGrpShortCaption = ((List <TRptValue> )rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "template")
            {
                rg = ParseGroup(cur.FirstChild, ref report.queriesId, "queryDetail");

                if (rg != null)
                {
                    element.rptGrpTemplate = ((List <TRptQuery> )rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "query")
            {
                rg = ParseGroup(cur.FirstChild, ref report.queriesId, "queryDetail");

                if (rg != null)
                {
                    element.rptGrpQuery = ((List <TRptQuery> )rg);
                }

                cur = GetNextEntity(cur);
            }

            return element;
        }
Beispiel #4
0
        /// <summary>
        /// function selection
        /// </summary>
        /// <param name="f">function name</param>
        /// <param name="ops">if ops[1] is nil, and f cannot be evaluated, return nil; otherwise if ops is not nil, print an error if f cannot be evaluated</param>
        /// <returns>void</returns>
        private TVariant FunctionSelector(String f, TVariant[] ops)
        {
            TVariant          ReturnValue = null;
            TRptUserFunctions rptUserFunctions;
            String            s;
            String            s2;

            System.Int32 start;
            System.Int32 length;
            String       logMessage;
            bool         FunctionFound;
            int          counter;

            f = f.ToLower();
            TLogging.SetContext("call to function " + f);
            TParameterList myParams = GetParameters();

            if ((f == "eq") || (f == "ne"))
            {
                // check if at least one of the parameters is a variable; otherwise give warning
                if ((ops[1].ToString().IndexOf('{') == -1) && (ops[2].ToString().IndexOf('{') == -1))
                {
                    TLogging.Log(
                        "Warning: comparison should contain at least one variable: " + f.ToString() + '(' + ops[1].ToString() + ',' + ops[2].ToString(
                            ) +
                        ')', TLoggingType.ToLogfile | TLoggingType.ToConsole);
                }
            }

            if ((f == "isnull") || (f == "exists") || (f == "or") || (f == "and") || (f == "iif") || (f == "assign"))
            {
                // need to replace the variables manually
                // either because we don't want them replaced at all (isnull or exists needs the variable name),
                // or because we don't want to evaluate the second parameter if the first one already defines the result (e.g. or)
            }
            else
            {
                for (counter = 1; counter <= ReportingConsts.MAX_FUNCTION_PARAMETER; counter += 1)
                {
                    ops[counter] = EvaluateOperand(ops[counter]);
                }
            }

            if (f == "eq")
            {
                ReturnValue = new TVariant(ops[1].CompareToI(ops[2]) == 0);
            }
            else if (f == "ne")
            {
                ReturnValue = new TVariant(ops[1].CompareToI(ops[2]) != 0);
            }
            else if (f == "lt")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) < 0);
            }
            else if (f == "le")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) <= 0);
            }
            else if (f == "gt")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) > 0);
            }
            else if (f == "ge")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) >= 0);
            }
            else if (f == "sub")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() - ops[2].ToDecimal());
            }
            else if (f == "adddays")
            {
                ReturnValue = new TVariant(ops[1].ToDate().AddDays(ops[2].ToDouble()));
            }
            else if (f == "add")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() + ops[2].ToDecimal());
            }
            else if (f == "additems")
            {
                length = ops[1].ToInt() + 1;

                decimal result = 0.0M;

                for (counter = 2; counter <= length; ++counter)
                {
                    result += ops[counter].ToDecimal();
                }

                ReturnValue = new TVariant(result);
            }
            else if (f == "mul")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() * ops[2].ToDecimal());
            }
            else if (f == "div")
            {
                if (ops[2].ToDecimal() == 0)
                {
                    ReturnValue = new TVariant(0.0);
                }
                else
                {
                    ReturnValue = new TVariant(ops[1].ToDecimal() / ops[2].ToDecimal());
                }
            }
            else if (f == "mod")
            {
                if (ops[2].ToDecimal() == 0)
                {
                    ReturnValue = new TVariant(0.0);
                }
                else
                {
                    ReturnValue = new TVariant(ops[1].ToInt64() % ops[2].ToInt64());
                }
            }
            else if (f == "floor")
            {
                ReturnValue = new TVariant(Math.Floor(ops[1].ToDecimal()));
            }
            else if (f == "round")
            {
                ReturnValue = new TVariant(Math.Round(ops[1].ToDecimal()));
            }
            else if (f == "not")
            {
                ReturnValue = new TVariant(!ops[1].ToBool());
            }
            else if (f == "iif")
            {
                // iif ( condition, value_if_true, value_if_false )
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == true)
                {
                    ops[2]      = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2]);
                }
                else
                {
                    ops[3]      = EvaluateOperand(ops[3]);
                    ReturnValue = new TVariant(ops[3]);
                }
            }
            else if (f == "or")
            {
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == false)
                {
                    ops[2]      = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2].ToBool());
                }
                else
                {
                    ReturnValue = new TVariant(true);
                }
            }
            else if (f == "and")
            {
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == true)
                {
                    ops[2]      = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2].ToBool());
                }
                else
                {
                    ReturnValue = new TVariant(false);
                }
            }
            else if (f == "log")
            {
                if (ops[2] != null)
                {
                    ReturnValue = new TVariant(ops[1].ToString() + " " + ops[2].ToString());
                }
                else
                {
                    if (myParams.Exists(ops[1].ToString()))
                    {
                        myParams.Debug(ops[1].ToString());
                        ReturnValue = new TVariant();
                    }
                    else
                    {
                        ReturnValue = ops[1];
                    }
                }

                if (!ReturnValue.IsNil())
                {
                    TLogging.Log(ReturnValue.ToString());
                }
            }
            else if (f == "length")
            {
                ReturnValue = new TVariant(ops[1].ToString().Length);
            }
            else if (StringHelper.IsSame(f, "ContainsCSV"))
            {
                ReturnValue = new TVariant(StringHelper.ContainsCSV(ops[1].ToString(), ops[2].ToString()));
            }
            else if (f == "replace")
            {
                ReturnValue = new TVariant(ops[1].ToString().Replace(ops[2].ToString(), ops[3].ToString()));
            }
            else if ((f == "substring") || (f == "substr"))
            {
                s      = ops[1].ToString();
                start  = ops[2].ToInt();
                length = ops[3].ToInt();

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if ((f == "substringright") || (f == "substrright"))
            {
                s      = ops[1].ToString();
                length = ops[2].ToInt();
                start  = s.Length - length;

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if ((f == "substringwithoutright") || (f == "substrwithoutright"))
            {
                s      = ops[1].ToString();
                length = s.Length - ops[2].ToInt();
                start  = 0;

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if (f == "concatenate")
            {
                s = ops[1].ToString();

                s = s + ops[2].ToString();

                ReturnValue = new TVariant(s);
            }
            else if (f == "concatenateww")
            {
                s      = ops[1].ToString();
                length = ops[3].ToInt();

                s = s.PadRight(s.Length + length);

                s = s + ops[2].ToString();

                ReturnValue = new TVariant(s);
            }
            else if (f == "concatenatewithcomma")
            {
                s  = ops[1].ToString();
                s2 = ops[2].ToString();

                if ((s.Length > 0) &&
                    (s2.Length > 0))
                {
                    s = s + ", ";
                }

                s = s + s2;

                ReturnValue = new TVariant(s);
            }
            else if (f == "format")
            {
                ReturnValue = new TVariant(ops[1].ToFormattedString(ops[2].ToString()));
            }
            else if (f == "formattime")
            {
                String separator = ops[1].ToString();
                String hour      = ops[2].ToString();
                String min       = ops[3].ToString();
                String sec       = "";

                if ((ops.Length > 4) && (ops[4] != null))
                {
                    sec = ops[4].ToString();
                }

                if (hour.Length < 2)
                {
                    hour = "0" + hour;
                }

                if (min.Length < 2)
                {
                    min = "0" + min;
                }

                if ((sec.Length < 2) && (sec.Length > 0))
                {
                    sec = "0" + sec;
                }

                if (sec.Length > 0)
                {
                    ReturnValue = new TVariant(hour + separator + min + separator + sec);
                }
                else
                {
                    ReturnValue = new TVariant(hour + separator + min);
                }
            }
            else if (f == "assign")
            {
                string targetVariableName = ops[1].ToString();

                if (targetVariableName.StartsWith("{") && targetVariableName.EndsWith("}"))
                {
                    targetVariableName = targetVariableName.Substring(1, targetVariableName.Length - 2);
                }

                ops[2] = EvaluateOperand(ops[2]);

                if (myParams.Exists(targetVariableName))
                {
                    // we should overwrite the existing variable, not add on another level
                    TParameter origParameter = myParams.GetParameter(targetVariableName);
                    origParameter.value = ops[2];
                }
                else
                {
                    myParams.Add(targetVariableName, ops[2], -1, -1, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }

//              TLogging.Log("Assign: " + targetVariableName + "=" + ops[2].ToString());
                ReturnValue = ops[2];
            }
            else if (f == "exists")
            {
                ReturnValue = new TVariant(myParams.Exists(ops[1].ToString(), column, Depth));
            }
            else if (f == "isnull")
            {
                ReturnValue =
                    new TVariant((!myParams.Exists(ops[1].ToString(), column,
                                                   Depth) || myParams.Get(ops[1].ToString(), column, Depth).IsZeroOrNull()));
            }
            else if (f == "template")
            {
                TRptCalculation         rptTemplate        = ReportStore.GetCalculation(CurrentReport, ops[1].ToString());
                TRptDataCalcCalculation rptTempCalculation = new TRptDataCalcCalculation(this);
                ReturnValue = rptTempCalculation.Calculate(rptTemplate, null).VariantValue;
            }
            else if (f == "columnexist")
            {
                String ColumnID    = ops[1].ToString();
                bool   ColumnExist = false;

                System.Data.DataTable TempTable = myParams.ToDataTable();
                int numColumns = TempTable.Columns.Count;

                foreach (System.Data.DataRow Row in TempTable.Rows)
                {
                    for (int Counter = 0; Counter < numColumns; ++Counter)
                    {
                        if (Row[Counter].ToString() == ColumnID)
                        {
                            ColumnExist = true;
                            break;
                        }
                    }

                    if (ColumnExist)
                    {
                        break;
                    }
                }

                ReturnValue = new TVariant(ColumnExist);
            }
            else if (f == "conditionrow")
            {
                ReturnValue = new TVariant(ops[1]);

                if (ReturnValue.ToBool() == false)
                {
                    // clear this row, we don't want to display it
                    // set all parameters of this row to NULL
                    myParams.Add("DONTDISPLAYROW", new TVariant(true));
                }
                else
                {
                    myParams.Add("DONTDISPLAYROW", new TVariant(false), -1, -1, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }
            }
            else if (f == "column")
            {
                if ((ops[1].ToInt() >= 0) && (ops[1].ToInt() < CurrentColumns.Length))
                {
                    ReturnValue = new TVariant(CurrentColumns[ops[1].ToInt()]);
                }
                else
                {
                    TLogging.Log("referenced column does not exist: " + ops[1].ToString());
                    ReturnValue = new TVariant();
                }
            }
            else if (f == "HasColumns".ToLower())
            {
                ReturnValue = new TVariant(Results.HasColumns(this.LineId));
            }
            else if (f == "HasChildRows".ToLower())
            {
                ReturnValue = new TVariant(Results.HasChildRows(this.LineId));
            }
            else if (f == "CountChildRows".ToLower())
            {
                ReturnValue = new TVariant(Results.CountChildRows(this.LineId));
            }
            else if (f == "HasChildColumns".ToLower())
            {
                ReturnValue = new TVariant(Results.HasChildColumns(this.LineId));
            }
            else if (f == "invisible".ToLower())
            {
                // need to return true so that calculation happens.
                ReturnValue = new TVariant(true);
            }
            else if (f == "fatherColumn")
            {
                ReturnValue = GetParentValue(ParentRowId, ops[1].ToInt());
            }
            else if (f == "childColumn")
            {
                ReturnValue = GetChildValue(LineId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "SecondLevelColumn"))
            {
                ReturnValue = Get2ndLevelValue(ParentRowId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "FirstLevelColumn"))
            {
                ReturnValue = Get1stLevelValue(ParentRowId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "GetShortCaption"))
            {
                ReturnValue = new TVariant(GetShortCaption(ops[1].ToInt()));
            }
            else if (StringHelper.IsSame(f, "GetCaption"))
            {
                ReturnValue = new TVariant(GetCaption(ops[1].ToInt()));
            }
            else if (StringHelper.IsSame(f, "getSumLower2Report"))
            {
                if (ops[3] == null)
                {
                    ReturnValue = new TVariant(GetSumLower2Report(ops[1].ToInt(), ops[2].ToInt(), true), "currency");
                }
                else
                {
                    ReturnValue = new TVariant(GetSumLower2Report(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToBool()), "currency");
                }
            }
            else if (StringHelper.IsSame(f, "getSumLowerReport"))
            {
                if (ops[3] == null)
                {
                    ReturnValue = new TVariant(GetSumLowerReport(ops[1].ToInt(), ops[2].ToInt(), true), "currency");
                }
                else
                {
                    ReturnValue = new TVariant(GetSumLowerReport(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToBool()), "currency");
                }
            }
            else if (StringHelper.IsSame(f, "getSumLowerReportCredit"))
            {
                ReturnValue = new TVariant(GetSumLowerReportCredit(ops[1].ToInt(), ops[2].ToInt()), "currency");
            }
            else
            {
                FunctionFound = false;

                foreach (System.Type userFunctionsClass in FUserFunctions)
                {
                    if (!FunctionFound)
                    {
                        rptUserFunctions = (TRptUserFunctions)Activator.CreateInstance(userFunctionsClass);

                        if (rptUserFunctions.FunctionSelector(this, f, ops, out ReturnValue))
                        {
                            FunctionFound = true;
                            break;
                        }

                        rptUserFunctions = null;
                    }
                }

                if (!FunctionFound)
                {
                    TRptCalculation calculation = ReportStore.GetCalculation(CurrentReport, f);

                    if (calculation != null)
                    {
                        TRptDataCalcCalculation calc = new TRptDataCalcCalculation(this);
                        ReturnValue = calc.EvaluateCalculation(calculation, null, String.Empty, -1);
                    }
                    else if (ops[1] == null)
                    {
                        // don't print an error if ops[1] is null;
                        // just return f;
                        // this is needed e.g. for HasChildRows etc, called from TRptEvaluator.evaluateOperator
                        ReturnValue = null;
                    }
                    else
                    {
                        ReturnValue = new TVariant();
                        logMessage  = "unknown function " + f;

                        if (ops[1] != null)
                        {
                            logMessage = logMessage + ' ' + ops[1].ToString();
                        }

                        if (ops[2] != null)
                        {
                            logMessage = logMessage + ' ' + ops[2].ToString();
                        }

                        TLogging.Log(logMessage);
                    }
                }
            }

            TLogging.SetContext("");
            return(ReturnValue);
        }
Beispiel #5
0
        /// <summary>
        /// </summary>
        /// <param name="rptCalculation"></param>
        /// <param name="rptGrpParameter"></param>
        /// <returns></returns>
        public TVariant Calculate(TRptCalculation rptCalculation, List <TRptParameter>rptGrpParameter)
        {
            return EvaluateCalculationAll(rptCalculation, rptGrpParameter, rptCalculation.rptGrpTemplate, rptCalculation.rptGrpQuery);

            /*
             * //This is for logging the SQL string before it gets sent to the database
             * TLogging.Log(result.EncodeToString(), [tologfile]);
             */
        }
Beispiel #6
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptCalculation"></param>
        /// <param name="rptGrpParameter"></param>
        /// <param name="rptGrpTemplate"></param>
        /// <param name="rptGrpQuery"></param>
        /// <returns></returns>
        public TVariant EvaluateCalculationAll(TRptCalculation rptCalculation,
            List <TRptParameter>rptGrpParameter,
            List <TRptQuery>rptGrpTemplate,
            List <TRptQuery>rptGrpQuery)
        {
            TVariant ReturnValue;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;

            ReturnValue = new TVariant();

            if (rptGrpQuery == null)
            {
                return ReturnValue;
            }

            foreach (TRptQuery rptQuery in rptGrpQuery)
            {
                if (EvaluateCondition(rptQuery.strCondition))
                {
                    if (rptQuery.rptGrpValue != null)
                    {
                        rptDataCalcValue = new TRptDataCalcValue(this);

                        if (!ReturnValue.IsZeroOrNull())
                        {
                            ReturnValue.Add(new TVariant(" "));
                        }

                        ReturnValue.Add(rptDataCalcValue.Calculate(rptQuery.rptGrpValue, true));
                    }

                    if (rptQuery.rptGrpParameter != null)
                    {
                        // insert template with parameters
                        ReturnValue.Add(new TVariant(" "));
                        ReturnValue.Add(EvaluateCalculationAll(rptCalculation, rptQuery.rptGrpParameter, null, rptGrpTemplate));
                    }

                    if (rptQuery.rptGrpSwitch != null)
                    {
                        if (!ReturnValue.IsZeroOrNull())
                        {
                            ReturnValue.Add(new TVariant(" "));
                        }

                        rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                        ReturnValue.Add(new TVariant(rptDataCalcSwitch.Calculate(rptQuery.rptGrpSwitch)));
                    }
                }
            }

            if ((ReturnValue.TypeVariant == eVariantTypes.eString) || (ReturnValue.ToString().IndexOf("{") != -1))
            {
                ReturnValue = new TVariant(ApplyParametersToQuery(rptGrpParameter, ReturnValue.ToString()), true); // explicit string
                ReturnValue = ReplaceVariables(ReturnValue.ToString(), true);
            }

            // TLogging.log('Result of TRptDataCalcCalculation.evaluateCalculationAll: '+result.encodetostring());
            return ReturnValue;
        }
Beispiel #7
0
        /// <summary>
        /// execute sql query, or do any other calculation to get the result
        /// </summary>
        /// <param name="rptCalculation"></param>
        /// <param name="rptGrpParameter"></param>
        /// <param name="strLowerLevel">can be empty string if there is no lower level to be calculated depending on the result of this query</param>
        /// <param name="masterRow"></param>
        public TVariant EvaluateCalculation(TRptCalculation rptCalculation,
            List <TRptParameter>rptGrpParameter,
            string strLowerLevel,
            int masterRow)
        {
            // depending on existing lower level, we want the parameters on that level, otherwise on the current level
            int StoreResultsAtDepth = (strLowerLevel.Length == 0) ? Depth : Depth + 1;

            string strSql = this.Calculate(rptCalculation, rptGrpParameter).ToString();

            if (strSql.Length == 0)
            {
                return new TVariant();
            }

            // ShowMessage (query);
            if (strSql.StartsWith("CSV:"))
            {
                strSql = strSql.Substring(4);

                while (strSql.Length > 0)
                {
                    string strReturns = rptCalculation.strReturns;

                    while (strReturns.Length != 0)
                    {
                        string strName = StringHelper.GetNextCSV(ref strReturns).Trim();

                        // the parameters are stored first
                        Parameters.Add(strName, StringHelper.GetNextCSV(
                                ref strSql).Trim(), -1, Depth + 1, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                    }

                    if (strLowerLevel != String.Empty)
                    {
                        TRptDataCalcLevel rptDataCalcLevel = new TRptDataCalcLevel(this);
                        rptDataCalcLevel.Depth++;
                        rptDataCalcLevel.Calculate(CurrentReport.GetLevel(strLowerLevel), masterRow);
                    }
                }
            }
            else if (strSql.StartsWith("Ict.Petra.Server."))
            {
                DataTable tab = CalculateFromMethod(strSql);

                if (tab == null)
                {
                    throw new Exception("Error in " + strSql);
                }
                else if (tab.Rows.Count > 0)
                {
                    string strReturns = rptCalculation.strReturns;

                    if (strReturns.ToLower() == "automatic")
                    {
                        strReturns = string.Empty;

                        foreach (DataColumn col in tab.Columns)
                        {
                            strReturns = StringHelper.AddCSV(strReturns, col.ColumnName);
                        }
                    }

                    foreach (DataRow row in tab.Rows)
                    {
                        this.AddResultsToParameter(strReturns, rptCalculation.strReturnsFormat, row, StoreResultsAtDepth);

                        if (strLowerLevel != String.Empty)
                        {
                            TRptDataCalcLevel rptDataCalcLevel = new TRptDataCalcLevel(this);
                            rptDataCalcLevel.Depth++;
                            rptDataCalcLevel.Calculate(CurrentReport.GetLevel(strLowerLevel), masterRow);
                        }
                    }
                }
            }
            else
            {
                if (strSql.StartsWith("NO-SQL"))
                {
                    // Don't execute the result as SQL. This can be used to sequentially execute calculations/functions in a query.
                    // example: ap_payment_export, Select Payments by Batch Number
                    strSql = strSql.Substring(7);
                    Parameters.Add(rptCalculation.strId, strSql, -1, StoreResultsAtDepth, null, null, ReportingConsts.CALCULATIONPARAMETERS);

                    if (strLowerLevel != String.Empty)
                    {
                        TRptDataCalcLevel rptDataCalcLevel = new TRptDataCalcLevel(this);
                        rptDataCalcLevel.Depth++;
                        rptDataCalcLevel.Calculate(CurrentReport.GetLevel(strLowerLevel), masterRow);
                    }

                    return this.Parameters.Get(rptCalculation.strId, -1, StoreResultsAtDepth, eParameterFit.eBestFitEvenLowerLevel);
                }
                else if (strSql.Length > 0)
                {
                    strSql = ReplaceQuotesForSql(strSql, rptCalculation.strId);
                    DataTable tab = DatabaseConnection.SelectDT(strSql, "EvaluateCalculation_TempTable", DatabaseConnection.Transaction);
                    string strReturns = rptCalculation.strReturns;

                    if (strReturns.ToLower() == "automatic")
                    {
                        strReturns = "";

                        foreach (DataColumn col in tab.Columns)
                        {
                            strReturns = StringHelper.AddCSV(strReturns, col.ColumnName);
                        }
                    }

                    foreach (DataRow row in tab.Rows)
                    {
                        this.AddResultsToParameter(strReturns, rptCalculation.strReturnsFormat, row, StoreResultsAtDepth);

                        if (strLowerLevel != String.Empty)
                        {
                            TRptDataCalcLevel rptDataCalcLevel = new TRptDataCalcLevel(this);
                            rptDataCalcLevel.Depth++;
                            rptDataCalcLevel.Calculate(CurrentReport.GetLevel(strLowerLevel), masterRow);
                        }
                    }
                }
            } // else

            if (this.Parameters.Exists(rptCalculation.strReturns, -1, StoreResultsAtDepth, eParameterFit.eBestFitEvenLowerLevel))
            {
                return this.Parameters.Get(rptCalculation.strReturns, -1, StoreResultsAtDepth, eParameterFit.eBestFitEvenLowerLevel);
            }

            return new TVariant();
        }
Beispiel #8
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="cur2"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        protected TRptCalculation ParseCalculation(XmlNode cur2, int order)
        {
            XmlNode         cur;
            Object          rg;
            TRptCalculation element;

            cur                      = cur2;
            element                  = new TRptCalculation(order);
            element.strId            = GetAttribute(cur, "id");
            element.strReturnsFormat = GetAttribute(cur, "returnsFormat");
            element.strReturns       = GetAttribute(cur, "returns");
            element.strAlign         = GetAttribute(cur, "align");
            cur                      = NextNotBlank(cur.FirstChild);

            if (cur.Name == "caption")
            {
                rg = ParseGroup(cur.FirstChild, ref report.valuesId, "value");

                if (rg != null)
                {
                    element.rptGrpCaption = ((List <TRptValue>)rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "shortcaption")
            {
                rg = ParseGroup(cur.FirstChild, ref report.valuesId, "value");

                if (rg != null)
                {
                    element.rptGrpShortCaption = ((List <TRptValue>)rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "template")
            {
                rg = ParseGroup(cur.FirstChild, ref report.queriesId, "queryDetail");

                if (rg != null)
                {
                    element.rptGrpTemplate = ((List <TRptQuery>)rg);
                }

                cur = GetNextEntity(cur);
            }

            if (cur.Name == "query")
            {
                rg = ParseGroup(cur.FirstChild, ref report.queriesId, "queryDetail");

                if (rg != null)
                {
                    element.rptGrpQuery = ((List <TRptQuery>)rg);
                }

                cur = GetNextEntity(cur);
            }

            return(element);
        }