/// <summary> /// calculate the next level deeper /// </summary> /// <param name="rptLowerLevel"></param> /// <param name="masterRow"></param> public void Calculate(TRptLowerLevel rptLowerLevel, int masterRow) { TRptDataCalcLevel rptDataCalcLevel; TRptCalculation rptCalculation; TRptDataCalcCalculation rptDataCalcCalculation; TRptDataCalcParameter rptDataCalcParameter; if (!EvaluateCondition(rptLowerLevel.strCondition)) { return; } if (rptLowerLevel.rptGrpParameter != null) { rptDataCalcParameter = new TRptDataCalcParameter(this); rptDataCalcParameter.Calculate("", rptLowerLevel.rptGrpParameter); } if (rptLowerLevel.strCalculation.Length == 0) { rptDataCalcLevel = new TRptDataCalcLevel(this); rptDataCalcLevel.Depth++; rptDataCalcLevel.Calculate(CurrentReport.GetLevel(rptLowerLevel.strLevel), masterRow); } else { rptCalculation = ReportStore.GetCalculation(CurrentReport, rptLowerLevel.strCalculation); if (rptCalculation == null) { TLogging.Log("calculation not found:" + rptLowerLevel.strCalculation); return; } rptDataCalcCalculation = new TRptDataCalcCalculation(this); rptDataCalcCalculation.EvaluateCalculation(rptCalculation, rptLowerLevel.rptGrpParameter, rptLowerLevel.strLevel, masterRow); } }
/// <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> /// 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(); }