/// <summary> /// recalculate row after all the columns have been calculated already, /// but now the functions based on other columns are calculated. /// </summary> /// <param name="situation"></param> /// <param name="row"></param> public static void RecalculateRow(TRptSituation situation, TResult row) { int counter; string strCalculation; TVariant ColumnCalc; TVariant levelCalc; TRptDataCalcResult rptDataCalcResult; String ColumnFormat; TVariant value; for (counter = 0; counter <= row.column.Length - 1; counter += 1) { // calculation is used for display in the GUI, formula is used for adding ledgers ColumnCalc = situation.GetParameters().Get("param_formula", counter, -1, eParameterFit.eExact); if (ColumnCalc.IsZeroOrNull()) { ColumnCalc = situation.GetParameters().Get("param_calculation", counter, -1, eParameterFit.eExact); } levelCalc = situation.GetParameters().Get("param_formula", ReportingConsts.ALLCOLUMNS, row.depth, eParameterFit.eExact); if (levelCalc.IsZeroOrNull()) { levelCalc = situation.GetParameters().Get("param_calculation", ReportingConsts.ALLCOLUMNS, row.depth, eParameterFit.eExact); } strCalculation = ""; if ((!ColumnCalc.IsZeroOrNull() && situation.GetReportStore().IsFunctionCalculation(situation.GetCurrentReport(), ColumnCalc.ToString()))) { // e.g. add(Column(1), Column(2)) strCalculation = ColumnCalc.ToString(); } else if ((!levelCalc.IsZeroOrNull() && situation.GetReportStore().IsFunctionCalculation(situation.GetCurrentReport(), levelCalc.ToString()))) { // e.g. getSumLowerReport strCalculation = levelCalc.ToString(); } if (situation.GetReportStore().IsFunctionCalculation(situation.GetCurrentReport(), strCalculation)) { rptDataCalcResult = new TRptDataCalcResult(situation, row.depth, counter, row.childRow, row.masterRow); ColumnFormat = ""; if (situation.GetParameters().Exists("ColumnFormat", counter, row.depth)) { ColumnFormat = situation.GetParameters().Get("ColumnFormat", counter, row.depth).ToString(); } value = rptDataCalcResult.Precalculate(row.column); value.ApplyFormatString(ColumnFormat); if (value.ToFormattedString().Length > 0) { row.column[counter] = value; } } } }
/// <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; }