/// <summary> /// todoComment /// </summary> /// <returns></returns> protected Boolean Calculate() { this.Results.Clear(); if (Parameters.Exists("calculateFromMethod")) { if (!CalculateFromMethod(Parameters.Get("calculateFromMethod").ToString())) { TLogging.Log(TLogging.LOG_PREFIX_ERROR + "Could not calculate from method (or report was cancelled)."); return false; } } else { TRptDataCalcHeaderFooter calcHeaderFooter = new TRptDataCalcHeaderFooter(this, -1, -1, 0, 0); calcHeaderFooter.Calculate(CurrentReport.pagefield, CurrentReport.pageswitch); InitColumnCaptions(); TRptDataCalcLevel calclevel = new TRptDataCalcLevel(this, 0, -1, 0, 0); if ((calclevel.Calculate(CurrentReport.GetLevel("main"), 0) == -1) || (Parameters.Get("CancelReportCalculation").ToBool() == true)) { TLogging.Log(TLogging.LOG_PREFIX_ERROR + "Could not calculate main level (or report was cancelled)."); return false; } InitColumnLayout(); } // call after calculating, because new parameters will be added InitDetailReports(); return true; }
/// <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; }