/// <summary> /// todoComment /// </summary> /// <param name="rptGrpValue"></param> /// <param name="AWithSpaceBetweenValues"></param> /// <returns></returns> public TVariant Calculate(List <TRptValue>rptGrpValue, Boolean AWithSpaceBetweenValues) { TVariant ReturnValue; String listValue; String listText; Boolean first; TRptDataCalcCalculation rptDataCalcCalculation; ReturnValue = new TVariant(); foreach (TRptValue rptValue in rptGrpValue) { if (EvaluateCondition(rptValue.strCondition)) { if ((AWithSpaceBetweenValues == true) && (ReturnValue.TypeVariant != eVariantTypes.eEmpty)) { ReturnValue.Add(new TVariant(' ')); } if (rptValue.strFunction == "csv") { // this is only for sql queries listValue = Parameters.Get(rptValue.strVariable, column, Depth).ToString(); if ((listValue.Length > 3) && (listValue.Substring(0, 4) == "CSV:")) { listValue = listValue.Substring(4); } first = true; ReturnValue.Add(new TVariant(" (")); if (listValue.Length == 0) { // this would make the sql query invalid; so insert a false condition to at least make it run, and return no records ReturnValue.Add(new TVariant(" 1 = 0 ")); } while (listValue.Length != 0) { bool IsFirstPair = true; string value = StringHelper.GetNextCSV(ref listValue).Trim(); if (first) { first = false; } else { ReturnValue.Add(new TVariant(" OR ")); } if (rptValue.strText.IndexOf(',') != -1) { // there are two things to compare (e.g. motivation group and motivation detail) // motivation group and detail come in pairs, separated by comma, enclosed by quotes (getNextCSV strips the quotes) string valuePair = value; listText = rptValue.strText; string calculationText = rptValue.strCalculation; // if the format is defined in the xml file, it overwrites the value we get from (new TVariant(value).TypeVariant == eVariantTypes.xxx bool ValueIsNumber = (rptValue.strFormat == "Number"); bool ValueIsText = (rptValue.strFormat == "Text"); ReturnValue.Add(new TVariant('(')); while (listText.Length != 0) { if (IsFirstPair) { // we have taken out the first value already from listValue value = valuePair; IsFirstPair = false; } else { value = StringHelper.GetNextCSV(ref listValue).Trim(); } if (listText.Length < rptValue.strText.Length) { if (calculationText.Length > 0) { ReturnValue.Add(new TVariant(" " + calculationText + " ")); } else { ReturnValue.Add(new TVariant(" AND ")); } } //todo: allow integer as well; problem with motivation detail codes that are just numbers; //todo: specify type with text, variable names and type //if (new TVariant(value).TypeVariant == eVariantTypes.eString) if (!ValueIsNumber || ValueIsText) { ReturnValue.Add(new TVariant(StringHelper.GetNextCSV(ref listText).Trim() + " = '")); ReturnValue.Add(new TVariant(value)); ReturnValue.Add(new TVariant("' ")); } else { ReturnValue.Add(new TVariant(StringHelper.GetNextCSV(ref listText).Trim() + " = ")); ReturnValue.Add(new TVariant(value)); ReturnValue.Add(new TVariant(' ')); } } ReturnValue.Add(new TVariant(')')); } else { // if the format is defined in the xml file, it overwrites the value we get from (new TVariant(value).TypeVariant == eVariantTypes.xxx bool ValueIsNumber = (rptValue.strFormat == "Number"); bool ValueIsText = (rptValue.strFormat == "Text"); if ((ValueIsText || (new TVariant(value).TypeVariant == eVariantTypes.eString)) && !ValueIsNumber) { ReturnValue.Add(new TVariant(' ' + rptValue.strText + " = '")); ReturnValue.Add(new TVariant(value)); ReturnValue.Add(new TVariant("' ")); } else { ReturnValue.Add(new TVariant(' ' + rptValue.strText + " = ")); ReturnValue.Add(new TVariant(value)); ReturnValue.Add(new TVariant(' ')); } } } ReturnValue.Add(new TVariant(") ")); } else { if (rptValue.strText.Length != 0) { ReturnValue.Add(new TVariant(rptValue.strText), rptValue.strFormat); } if (rptValue.strVariable.Length != 0) { ReturnValue.Add(Parameters.Get(rptValue.strVariable, column, Depth), rptValue.strFormat); } if (rptValue.strCalculation.Length != 0) { rptDataCalcCalculation = new TRptDataCalcCalculation(this); ReturnValue.Add(rptDataCalcCalculation.EvaluateHelperCalculation(rptValue.strCalculation), rptValue.strFormat); } if (rptValue.strFunction.Length != 0) { ReturnValue.Add(EvaluateFunctionString(rptValue.strFunction), rptValue.strFormat); } } } } return ReturnValue; }
/// <summary> /// todoComment /// </summary> /// <param name="rptField"></param> public void Calculate(TRptField rptField) { int cmpos; string whichField; TRptDataCalcCalculation rptDataCalcCalculation; String list; String element; column = -1; whichField = rptField.strWhichfield; if (whichField.IndexOf("columns") == 0) { column = ReportingConsts.ALLCOLUMNS; } else if (whichField.IndexOf("column ") == 0) { if (whichField[7] == '{') { String ParameterName = whichField.Substring(8, whichField.Length - 9); column = GetParameters().Get(ParameterName).ToInt(); } else { column = (Int32)StringHelper.StrToInt(whichField.Substring(7, whichField.Length - 7)); } } else if (whichField.IndexOf("left ") == 0) { column = ReportingConsts.COLUMNLEFT + (Int32)StringHelper.StrToInt(whichField.Substring(5, whichField.Length - 5)) + 1; } else if (whichField.IndexOf("header ") == 0) { column = ReportingConsts.HEADERCOLUMN + (Int32)StringHelper.StrToInt(whichField.Substring(7, whichField.Length - 7)) + 1; } else { if (whichField == "title1") { column = ReportingConsts.HEADERTITLE1; } if (whichField == "title2") { column = ReportingConsts.HEADERTITLE2; } if (whichField == "descr1") { column = ReportingConsts.HEADERDESCR1; } if (whichField == "descr2") { column = ReportingConsts.HEADERDESCR2; } if (whichField == "descr3") { column = ReportingConsts.HEADERDESCR3; } if (whichField == "period1") { column = ReportingConsts.HEADERPERIOD; } if (whichField == "period2") { column = ReportingConsts.HEADERPERIOD2; } if (whichField == "period3") { column = ReportingConsts.HEADERPERIOD3; } if (whichField == "left1") { column = ReportingConsts.HEADERPAGELEFT1; } if (whichField == "left2") { GetParameters().Add("FOOTER2LINES", new TVariant(true), -1, Depth); column = ReportingConsts.HEADERPAGELEFT2; } if (whichField == "type") { column = ReportingConsts.HEADERTYPE; } } if (rptField.strAlign != "") { GetParameters().Add("ColumnAlign", new TVariant(rptField.strAlign), column, Depth); } if (rptField.strFormat.Length != 0) { GetParameters().Add("ColumnFormat", new TVariant(rptField.strFormat), column, Depth); } if (rptField.strLine.IndexOf("above") != -1) { GetParameters().Add("LineAbove", new TVariant(true), column, Depth); } if (rptField.strLine.IndexOf("below") != -1) { GetParameters().Add("LineBelow", new TVariant(true), column, Depth); } if (rptField.strPos.IndexOf("indented") != -1) { GetParameters().Add("indented", new TVariant(true), column, Depth); } cmpos = rptField.strPos.IndexOf("cm"); if (cmpos != -1) { GetParameters().Add("ColumnPosition", new TVariant(StringHelper.TryStrToDecimal(rptField.strPos.Substring(0, cmpos), 0.0M)), column, Depth); } cmpos = rptField.strWidth.IndexOf("cm"); if (cmpos != -1) { GetParameters().Add("ColumnWidth", new TVariant(StringHelper.TryStrToDecimal(rptField.strWidth.Substring(0, cmpos), 0.0M)), column, Depth); } if (rptField.strCalculation.Length != 0) { rptDataCalcCalculation = new TRptDataCalcCalculation(this); // allow several helper calculations to be executed after each other; // e.g. giftbatchexport; first get the accumulated description of the gift details, then get bank account details list = rptField.strCalculation; while (list.Length != 0) { element = StringHelper.GetNextCSV(ref list).Trim(); rptDataCalcCalculation.EvaluateHelperCalculation(element); } } if (column != -1) { if (rptField.rptGrpValue != null) { // overwrite the global column calculation GetParameters().Add("param_calculation", new TVariant(), column, Depth, null, null, ReportingConsts.CALCULATIONPARAMETERS); } Calculate(rptField.rptGrpValue, rptField.rptGrpFieldDetail); } else { throw new Exception("ERROR: whichField problem: " + whichField); } }