Ejemplo n.º 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="precalculatedColumns"></param>
        /// <returns></returns>
        public TVariant Precalculate(TVariant[] precalculatedColumns)
        {
            String strCalculation;
            TRptDataCalcCalculation rptDataCalcCalculation;
            TRptCalculation         rptCalculation;

            TVariant ReturnValue = new TVariant();

            // calculation is used for display in the GUI, formula is used for adding ledgers
            if ((!GetParameters().Exists("param_calculation", column, Depth)))
            {
                return(ReturnValue);
            }

            if (GetParameters().Exists("param_formula", column, Depth))
            {
                strCalculation = GetParameters().Get("param_formula", column, Depth).ToString();
            }
            else
            {
                strCalculation = GetParameters().Get("param_calculation", column, Depth).ToString();
            }

            rptCalculation = ReportStore.GetCalculation(CurrentReport, strCalculation);

            if (rptCalculation == null)
            {
                ReturnValue = EvaluateFunctionCalculation(strCalculation, precalculatedColumns);
            }
            else
            {
                rptDataCalcCalculation = new TRptDataCalcCalculation(this);

                if (!rptDataCalcCalculation.EvaluateCalculationFunction(rptCalculation.rptGrpQuery, ref precalculatedColumns, ref ReturnValue))
                {
                    ReturnValue = rptDataCalcCalculation.EvaluateCalculationAll(rptCalculation,
                                                                                null,
                                                                                rptCalculation.rptGrpTemplate,
                                                                                rptCalculation.rptGrpQuery).VariantValue;

                    if (ReturnValue.IsZeroOrNull())
                    {
                        ReturnValue.ApplyFormatString(rptCalculation.strReturnsFormat);
                        return(ReturnValue);
                    }

                    // Removed some code from here due to Bug 3081 Reports crash if data contains the word SELECT
                    // Even if there were a case for running SQL at this point, it wouldn't work anyway due
                    // to the "" parameter in the call to DatabaseConnection.SelectDT().
                }

                ReturnValue.ApplyFormatString(rptCalculation.strReturnsFormat);
            }

            return(ReturnValue);
        }
Ejemplo n.º 2
0
        public void TestGeneralParametersProcessing()
        {
            TParameterList parameters = new TParameterList();

            TVariant value = new TVariant();

            value.ApplyFormatString("Currency");
            Assert.AreEqual("0", value.ToFormattedString(), "null value for currency should be 0");
            value = new TVariant(value.ToFormattedString());
            parameters.Add("amountdue", value, -1, 2);
            parameters.Save("testDebug.json");
            Assert.AreEqual(true, parameters.Exists("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel), "can find added parameter");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 2,
                                                eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            //Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 1,
                                                eParameterFit.eBestFitEvenLowerLevel).ToFormattedString(), "currency parameter cannot be accessed from level up");

            // this test only works with english culture settings
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);
            parameters.Add("IntegerList", "300,400");
            parameters.Save("test.json");
            parameters.Load(Path.GetFullPath("test.json"));
            Assert.AreEqual("eString:300,400", parameters.Get(
                                "IntegerList").EncodeToString(), "integers separated by comma should be treated as string");
            parameters.Save("test2.json");
        }
Ejemplo n.º 3
0
        public void TestGeneralParametersProcessing()
        {
            TParameterList parameters = new TParameterList();

            TVariant value = new TVariant();

            value.ApplyFormatString("Currency");
            Assert.AreEqual("0", value.ToFormattedString(), "null value for currency should be 0");
            value = new TVariant(value.ToFormattedString());
            parameters.Add("amountdue", value, -1, 2, null, null, ReportingConsts.CALCULATIONPARAMETERS);
            parameters.Save("testDebug.csv", true);
            Assert.AreEqual(true, parameters.Exists("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel), "can find added parameter");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 2,
                                                eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            //Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 1,
                                                eParameterFit.eBestFitEvenLowerLevel).ToFormattedString(), "currency parameter cannot be accessed from level up");

            parameters.Add("IntegerList", "300,400");
            parameters.Save("test.csv", false);
            parameters.Load(Path.GetFullPath("test.csv"));
            Assert.AreEqual("eString:300,400", parameters.Get(
                                "IntegerList").EncodeToString(), "integers separated by comma should be treated as string");
            parameters.Save("test2.csv", true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="precalculatedColumns"></param>
        /// <returns></returns>
        public TVariant Precalculate(TVariant[] precalculatedColumns)
        {
            TVariant ReturnValue;
            String   strCalculation;
            TRptDataCalcCalculation rptDataCalcCalculation;
            TRptCalculation         rptCalculation;
            DataTable tab;

            ReturnValue = new TVariant();

            // calculation is used for display in the GUI, formula is used for adding ledgers
            if ((!GetParameters().Exists("param_calculation", column, Depth)))
            {
                return(ReturnValue);
            }

            if (GetParameters().Exists("param_formula", column, Depth))
            {
                strCalculation = GetParameters().Get("param_formula", column, Depth).ToString();
            }
            else
            {
                strCalculation = GetParameters().Get("param_calculation", column, Depth).ToString();
            }

            rptCalculation = ReportStore.GetCalculation(CurrentReport, strCalculation);

            if (rptCalculation == null)
            {
                ReturnValue = EvaluateFunctionCalculation(strCalculation, precalculatedColumns);
            }
            else
            {
                rptDataCalcCalculation = new TRptDataCalcCalculation(this);

                if (!rptDataCalcCalculation.EvaluateCalculationFunction(rptCalculation.rptGrpQuery, ref precalculatedColumns, ref ReturnValue))
                {
                    ReturnValue = rptDataCalcCalculation.EvaluateCalculationAll(rptCalculation,
                                                                                null,
                                                                                rptCalculation.rptGrpTemplate,
                                                                                rptCalculation.rptGrpQuery);

                    if (ReturnValue.IsZeroOrNull())
                    {
                        ReturnValue.ApplyFormatString(rptCalculation.strReturnsFormat);
                        return(ReturnValue);
                    }

                    int SelectPos = ReturnValue.ToString().ToUpper().IndexOf("SELECT");

                    if ((SelectPos >= 0) && (SelectPos <= 3))
                    {
                        // this is an sql statement and not a function result
                        tab = DatabaseConnection.SelectDT(ReturnValue.ToString(), "", DatabaseConnection.Transaction);

                        if (tab.Rows.Count > 0)
                        {
                            if (tab.Rows[0][0].GetType() == typeof(String))
                            {
                                ReturnValue = new TVariant(Convert.ToString(tab.Rows[0][0]));
                            }
                            else
                            {
                                ReturnValue = new TVariant(tab.Rows[0][0]);
                            }
                        }
                    }
                }

                ReturnValue.ApplyFormatString(rptCalculation.strReturnsFormat);
            }

            return(ReturnValue);
        }