/// <summary> /// Set the given DateTime control to be blank instead of /// DateTime.Now if the value is not specified. /// </summary> private void SetdtpControlManual(Ict.Petra.Client.CommonControls.TtxtPetraDate AControl, TVariant AValue) { if (AValue.IsZeroOrNull()) { AControl.Date = null; } }
/// <summary> /// print a currency value (actually all sorts of values, e.g. dates) into a string /// </summary> /// <param name="value">the value to be printed</param> /// <param name="format">the format to be used; can be dayofyear for birthdays, currency, etc</param> /// <returns>the formatted string</returns> public static String FormatCurrency(TVariant value, String format) { String ReturnValue; decimal d; DateTime ThisYearDate; // for partnerkey String OrigFormat; ReturnValue = ""; if (format.ToLower() == "dayofyear") { if (value.IsZeroOrNull()) { ReturnValue = "N/A"; } else { ThisYearDate = new DateTime(DateTime.Today.Year, value.ToDate().Month, value.ToDate().Day); ReturnValue = DateToStr(ThisYearDate, "dd-MMM").ToUpper(); } return ReturnValue; } if (format == null) { format = ""; } OrigFormat = format; if (value.TypeVariant == eVariantTypes.eString) { format = ""; } else { format = GetFormatString(value.FormatString, format); } if (value != null) { if ((format == null) || (format.Length == 0)) { return value.ToString(); } String formatPositive = GetNextCSV(ref format, ";"); String formatNegative = GetNextCSV(ref format, ";"); String formatZero = GetNextCSV(ref format, ";"); String formatNil = GetNextCSV(ref format, ";"); if ((OrigFormat.ToLower() == "partnerkey") || (value.FormatString == "partnerkey")) { if (value.ToInt64() <= 0) { ReturnValue = FormatCurrencyInternal(0, "0000000000"); } else { ReturnValue = FormatCurrencyInternal(value.ToDecimal(), formatPositive); } } else if ((value.TypeVariant == eVariantTypes.eDecimal) || (value.TypeVariant == eVariantTypes.eCurrency) || (value.TypeVariant == eVariantTypes.eInteger)) { d = value.ToDecimal(); if (d > 0) { ReturnValue = FormatCurrencyInternal(d, formatPositive); } else if (d < 0) { ReturnValue = FormatCurrencyInternal(Math.Abs(d), formatNegative); } else { // (d == 0) ReturnValue = FormatCurrencyInternal(d, formatZero); } } else if (value.IsZeroOrNull()) { ReturnValue = FormatCurrencyInternal(0, formatNil); } else { ReturnValue = value.ToString(); } } return ReturnValue; }
/// <summary> /// todoComment /// </summary> /// <param name="calculation"></param> /// <returns></returns> public TVariant EvaluateHelperCalculation(String calculation) { TVariant ReturnValue; TRptCalculation rptCalculation; DataTable tab; string strReturns; Boolean firstRow; ReturnValue = new TVariant(); rptCalculation = ReportStore.GetCalculation(CurrentReport, calculation); if (rptCalculation == null) { TLogging.Log("calculation " + calculation + " could not be found."); return ReturnValue; } ReturnValue = Calculate(rptCalculation, null); if (ReturnValue.IsZeroOrNull() || (ReturnValue.ToString().Trim().ToUpper().IndexOf("SELECT") != 0)) { return ReturnValue; } if (rptCalculation.strReturnsFormat.ToLower() == "list") { // reset the variables, so we are able to start a new list strReturns = rptCalculation.strReturns; while (strReturns.Length != 0) { Parameters.Add(StringHelper.GetNextCSV(ref strReturns).Trim(), "", -1, Depth, null, null, ReportingConsts.CALCULATIONPARAMETERS); } } String strSql = ReturnValue.ToString(); strSql = ReplaceQuotesForSql(strSql, rptCalculation.strId); tab = DatabaseConnection.SelectDT(strSql, "EvaluateHelperCalculation", DatabaseConnection.Transaction); if ((tab == null) || (tab.Rows.Count == 0)) { // reset the variables, we don't want to display the results of the previous calculation strReturns = rptCalculation.strReturns; while (strReturns.Length != 0) { Parameters.Add(StringHelper.GetNextCSV(ref strReturns).Trim(), "", -1, Depth, null, null, ReportingConsts.CALCULATIONPARAMETERS); } } ReturnValue = new TVariant(); firstRow = true; foreach (DataRow row in tab.Rows) { if (!firstRow) { ReturnValue.Add(new TVariant(", ")); } firstRow = false; if (Convert.ToString(row[0]) != new TVariant(row[0]).ToString()) { ReturnValue.Add(new TVariant(Convert.ToString(row[0]))); } else { ReturnValue.Add(new TVariant(row[0])); } AddResultsToParameter(rptCalculation.strReturns, rptCalculation.strReturnsFormat, row, Depth); } return ReturnValue; }
/// <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; }
/// <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; }