示例#1
0
        /// <summary>
        /// calculate a level
        ///
        /// </summary>
        /// <returns>The number of the line calculated. -1 if unsuccessful
        /// </returns>
        public int Calculate(TRptLevel rptLevel, int masterRow)
        {
            if (rptLevel == null)
            {
                return -1;
            }

            TRptDetail rptDetail = rptLevel.rptDetail;

            if (rptDetail == null)
            {
                return -1;
            }

            if (Parameters.Get("CancelReportCalculation").ToBool() == true)
            {
                // TLogging.Log('Report calculation was cancelled', [ToStatusBar]);
                return -1;
            }

            int thisRunningCode = GetNextRunningCode();
            List <TRptField>rptGrpField = rptDetail.rptGrpField;
            List <TRptLowerLevel>rptGrpLowerLevel = rptDetail.rptGrpLowerLevel;
//          TLogging.Log("[MReporting\\Calculation.cs] Calculate(" + rptLevel.strName + ", " + masterRow + ")");

            if (rptDetail.rptSwitch != null)
            {
                TRptDataCalcSwitch calcSwitch = new TRptDataCalcSwitch(this);
                calcSwitch.Calculate(rptDetail.rptSwitch, out rptGrpLowerLevel, out rptGrpField);
            }

            if (rptGrpLowerLevel != null)
            {
                TRptDataCalcLowerLevel calcLowerLevel;

                if (Depth == 0)
                {
                    Int16 subreport = 0;

                    foreach (TRptLowerLevel rptLowerLevel in rptGrpLowerLevel)
                    {
                        Parameters.Add("CurrentSubReport", subreport);
                        calcLowerLevel = new TRptDataCalcLowerLevel(this);
                        calcLowerLevel.Calculate(rptLowerLevel, thisRunningCode);
                        subreport++;

                        if (Parameters.Get("CancelReportCalculation").ToBool() == true)
                        {
                            // TLogging.Log('Report calculation was cancelled', [ToStatusBar]);
                            return -1;
                        }
                    }

                    Parameters.Add("CurrentSubReport", -1);
                }
                else
                {
                    foreach (TRptLowerLevel rptLowerLevel in rptGrpLowerLevel)
                    {
                        calcLowerLevel = new TRptDataCalcLowerLevel(this);
                        calcLowerLevel.Calculate(rptLowerLevel, thisRunningCode);

                        if (Parameters.Get("CancelReportCalculation").ToBool() == true)
                        {
                            // TLogging.Log('Report calculation was cancelled', [ToStatusBar]);
                            return -1;
                        }
                    }
                }
            }
            else if (rptGrpField != null)
            {
                TRptDataCalcField calcGrpField = new TRptDataCalcField(this);
                calcGrpField.Calculate(rptGrpField);
            }

            TRptDataCalcHeaderFooter calcHeaderFooter = new TRptDataCalcHeaderFooter(this);
            calcHeaderFooter.Calculate(rptLevel.rptGrpHeaderField, rptLevel.rptGrpHeaderSwitch);
            calcHeaderFooter.Calculate(rptLevel.rptGrpFooterField, rptLevel.rptGrpFooterSwitch, rptLevel.strFooterLine, rptLevel.strFooterSpace);

            string strIdentification = rptLevel.strIdentification;
            string strId = "";

            while (strIdentification.Length != 0)
            {
                if (strId.Length != 0)
                {
                    strId += '/';
                }

                string strTemp = StringHelper.GetNextCSV(ref strIdentification).Trim();

                if (Parameters.Exists(strTemp, -1, Depth))
                {
                    strId += Parameters.Get(strTemp, -1, Depth).ToString(false);
                }
                else
                {
                    strId += strTemp;
                }
            }

            this.LineId = thisRunningCode;
            this.ParentRowId = masterRow;
            TRptDataCalcResult calcResult = new TRptDataCalcResult(this, Depth, -1, this.LineId, this.ParentRowId);

            if (calcResult.SavePrecalculation(masterRow, rptLevel.strCondition, strId))
            {
                // only write log if something was actually saved.
                TLogging.Log("preparing " + strId, TLoggingType.ToStatusBar);
            }

            if (Parameters.Get("CancelReportCalculation").ToBool() == true)
            {
                // TLogging.Log('Report calculation was cancelled', [ToStatusBar]);
                return -1;
            }

            if (thisRunningCode == 0)
            {
                // at this point all the values are precalculated
                // go again through the numbers, and calculate the function results, e.g. variance on ReportingConsts.COLUMNs
                calcResult.RecalculateFunctionColumns();
                calcResult.CheckDisplayStatus();

                if (Parameters.Exists("param_sortby_columns"))
                {
                    TLogging.Log("sorting...", TLoggingType.ToStatusBar);

                    Boolean SortMultipleLevels = false;

                    if (Parameters.Exists("param_sort_multiple_levels"))
                    {
                        // if we allow sorting of multiple levels, the result will be changed to flat table
                        // and we will end up with all the results in level 0. We might want this in some reports (e.g. Personnel-Birthday report)
                        SortMultipleLevels = true;
                    }

                    calcResult.GetResults().Sort(Parameters.Get("param_sortby_columns").ToString(), SortMultipleLevels);
                }

                TLogging.Log("finished", TLoggingType.ToStatusBar);
            }

            return thisRunningCode;
        }
示例#2
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptGrpFieldDetail"></param>
        /// <returns></returns>
        public TVariant Calculate(List <TRptFieldDetail>rptGrpFieldDetail)
        {
            TVariant ReturnValue;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;

            ReturnValue = new TVariant();

            foreach (TRptFieldDetail rptFieldDetail in rptGrpFieldDetail)
            {
                if (EvaluateCondition(rptFieldDetail.strCondition))
                {
                    if (rptFieldDetail.rptGrpValue != null)
                    {
                        rptDataCalcValue = new TRptDataCalcValue(this);
                        ReturnValue.Add(rptDataCalcValue.Calculate(rptFieldDetail.rptGrpValue));
                    }
                    else
                    {
                        rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                        ReturnValue.Add(rptDataCalcSwitch.Calculate(rptFieldDetail.rptSwitch));
                    }
                }
            }

            return ReturnValue;
        }
示例#3
0
        /// <summary>
        /// calculate the value of a switch
        /// </summary>
        /// <param name="rptSwitch"></param>
        /// <returns></returns>
        public TVariant Calculate(TRptSwitch rptSwitch)
        {
            TVariant ReturnValue;
            TRptDataCalcField rptDataCalcField;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;
            TRptCase rptCase;

            ReturnValue = new TVariant();
            rptCase = GetFittingCase(rptSwitch);

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

            if (rptCase.rptSwitch != null)
            {
                rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                ReturnValue.Add(rptDataCalcSwitch.Calculate(rptCase.rptSwitch));
            }
            else
            {
                if (rptCase.rptGrpField != null)
                {
                    rptDataCalcField = new TRptDataCalcField(this);
                    rptDataCalcField.Calculate(rptCase.rptGrpField);
                }

                if (rptCase.rptGrpValue != null)
                {
                    rptDataCalcValue = new TRptDataCalcValue(this);
                    ReturnValue.Add(rptDataCalcValue.Calculate(rptCase.rptGrpValue));
                }
            }

            return ReturnValue;
        }
示例#4
0
        /// <summary>
        /// this procedure should be used in levels only
        /// </summary>
        /// <returns>void</returns>
        public void Calculate(TRptSwitch rptSwitch, out List <TRptLowerLevel>rptGrpLowerLevel, out List <TRptField>rptGrpField)
        {
            TRptDataCalcSwitch calcSwitch;
            TRptCase rptCase;

            rptGrpField = null;
            rptGrpLowerLevel = null;
            rptCase = GetFittingCase(rptSwitch);

            if (rptCase != null)
            {
                rptGrpField = rptCase.rptGrpField;
                rptGrpLowerLevel = rptCase.rptGrpLowerLevel;

                if (rptCase.rptSwitch != null)
                {
                    calcSwitch = new TRptDataCalcSwitch(this);
                    calcSwitch.Calculate(rptCase.rptSwitch, out rptGrpLowerLevel, out rptGrpField);
                }
            }
        }
示例#5
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptGrpField"></param>
        /// <param name="rptGrpSwitch"></param>
        /// <param name="strLine"></param>
        /// <param name="strSpace"></param>
        public void Calculate(List <TRptField>rptGrpField, List <TRptSwitch>rptGrpSwitch, string strLine, string strSpace)
        {
            TRptDataCalcSwitch calcSwitch;
            TRptDataCalcField calcField;

            if ((strLine != null) && (strLine.IndexOf("above") != -1))
            {
                GetParameters().Add("FullLineAbove", new TVariant(true), -1, Depth);
            }

            if ((strLine != null) && (strLine.IndexOf("below") != -1))
            {
                GetParameters().Add("FullLineBelow", new TVariant(true), -1, Depth);
            }

            if ((strSpace != null) && (strSpace.IndexOf("above") != -1))
            {
                GetParameters().Add("SpaceLineAbove", new TVariant(true), -1, Depth);
            }

            if ((strSpace != null) && (strSpace.IndexOf("below") != -1))
            {
                GetParameters().Add("SpaceLineBelow", new TVariant(true), -1, Depth);
            }

            if (rptGrpSwitch != null)
            {
                column = -1;
                calcSwitch = new TRptDataCalcSwitch(this);
                calcSwitch.Calculate(rptGrpSwitch);
            }

            if (rptGrpField != null)
            {
                calcField = new TRptDataCalcField(this);
                calcField.Calculate(rptGrpField);
            }
        }
示例#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;
        }