private static string getFunctionCall(string code, cReportFormula formula) { int n = code.IndexOf("("); var functionName = cUtil.subString(code, 8, n-8); var parameters = ""; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { var fint = formula.getFormulasInt().item(_i); parameters += "globals.getVar(\"p__" + _i + "__\").getValue(),"; } if (parameters.Length > 0) { parameters = parameters.Substring(0, parameters.Length - 1); } return functionName + "(" + parameters + ")"; }
private static string getFunctionCall(string code, cReportFormula formula) { int n = code.IndexOf("("); var functionName = cUtil.subString(code, 8, n - 8); var parameters = ""; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { var fint = formula.getFormulasInt().item(_i); parameters += "globals.getVar(\"p__" + _i + "__\").getValue(),"; } if (parameters.Length > 0) { parameters = parameters.Substring(0, parameters.Length - 1); } return(functionName + "(" + parameters + ")"); }
private void pSetIndexColInGroupFormula(cReportFormula formula, List<object[]> recordsets) { cReportFormulaInt fint = null; String colName = ""; DataTable rs = null; if (!m_reportDisconnected) { rs = (DataTable)recordsets[0][0]; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); if (pIsGroupFormula((int)fint.getFormulaType())) { colName = fint.getParameters().item(0).getValue(); pSetColIndexInGroupFormulaAux(rs, fint, colName, cReportGlobals.C_KEYINDEXCOL); if (fint.getFormulaType() == csRptFormulaType.CSRPTGROUPPERCENT) { colName = fint.getParameters().item(1).getValue(); pSetColIndexInGroupFormulaAux(rs, fint, colName, cReportGlobals.C_KEYINDEXCOL2); } } } } }
private void pSetFormulaIndexGroup(cReportFormula formula, cReportSection sec) { // TODO: Use of ByRef founded Private Function pSetFormulaIndexGroup(ByRef Formula As cReportFormula, ByRef Sec As cReportSection) As Boolean cReportFormulaInt fint = null; int indexGroup = 0; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); if (pIsGroupFormula((int)fint.getFormulaType())) { if (fint.getFormulaType() == csRptFormulaType.CSRPTGROUPPERCENT) { formula.setIdxGroup2(0); indexGroup = cUtil.valAsInt(fint.getParameters().item(3).getValue()); } else { indexGroup = cUtil.valAsInt(fint.getParameters().item(2).getValue()); } if (fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP) == null) { fint.getParameters().add2("", cReportGlobals.C_KEYINDEXGROUP); } if (indexGroup == -1) { if (sec.getTypeSection() == csRptSectionType.GROUP_HEADER || sec.getTypeSection() == csRptSectionType.GROUP_FOOTER) { // index of the group // fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(sec.getIndex().ToString()); formula.setIdxGroup(sec.getIndex()); } else if (sec.getTypeSection() == csRptSectionType.MAIN_DETAIL) { // index of the most internal group // fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(m_groups.count().ToString()); formula.setIdxGroup(m_groups.count()-1); } else { fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue("0"); formula.setIdxGroup(0); } } else { fint.getParameters().item(cReportGlobals.C_KEYINDEXGROUP).setValue(indexGroup.ToString()); formula.setIdxGroup(indexGroup); } } } }
public void evalFunction(cReportFormula formula) { String codeC = ""; m_objGlobals.setMode(eReportCompilerMode.C_EVAL); pEvalGroupFunctions(formula); cReportError.gDebugSection = formula.getSectionName(); cReportError.gDebugSectionLine = formula.getSectionLineIndex(); cReportError.gDebugControl = formula.getControlName(); m_formula = formula; pCompile(formula.getText(), false, codeC); if (formula.getFormulasInt().count() > 0) { if (G.isNumeric(codeC)) { pEvalSyntax("", codeC, false, formula); } else { if (cUtil.subString(codeC.Trim(), 0, 8).ToLower() == "function") { pEvalSyntax("", codeC, false, formula); } } } else { pEvalSyntax("", codeC, false, formula); } m_formula = null; }
public void evalFunctionGroup(cReportFormula formula) { cReportFormulaInt fint = null; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); pEvalFunctionGroup(fint); } }
public object resultFunction(cReportFormula formula) { String code = ""; object[] vResult = null; m_objGlobals.setMode(eReportCompilerMode.C_RESULT); m_ctrlName = formula.getControlName(); vResult = new object[formula.getFormulasInt().count()]; cReportFormulaInt fint = null; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); vResult[_i] = pResultFunctionInt(fint); } // we check if the code has scripting or is only // calls to internal functions // code = formula.getTextC().Replace(C_KEYFUNCINT, ""); code = code.Replace(" ", ""); // if after removing calls to internal functions and spaces // there is only a number we don't have scripting // if (G.isNumeric(code)) { if (vResult.Length > 0) { formula.setLastResult(vResult[0]); formula.setHaveToEval(false); return formula.getLastResult(); } // the function can be only a constant (it is used in Cairo navigation) // else { return code; } } else { code = formula.getTextC(); var parameters = ""; for (int i = 0; i < vResult.Length; i++) { // if one argument is null it means we don't have a row for this formula // so we don't need to compile the code // if (vResult[i] == null) { return null; } /* TODO: remove me code = code.Replace(C_KEYFUNCINT + cReportGlobals.format(i + 1, "000"), getNumericVal(vResult[i].ToString())); * */ var parameter = "p__" + i + "__"; parameters += parameter + ","; code = code.Replace(C_KEYFUNCINT + cReportGlobals.format(i + 1, "000"), parameter); var paramValue = m_objGlobals.getVar(parameter); if (paramValue == null) { paramValue = m_objGlobals.addVar(parameter); } paramValue.setValue(vResult[i]); } if (parameters.Length > 0) { parameters = parameters.Substring(0, parameters.Length - 1); code = insertParametersIntoFunction(code, parameters); } formula.setLastResult(pExecScriptCode(code, formula)); formula.setHaveToEval(false); return formula.getLastResult(); } }
private void pEvalGroupFunctions(cReportFormula formula) { cReportFormulaInt fint = null; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); switch (fint.getFormulaType()) { case csRptFormulaType.CSRPTGROUPTOTAL: evalGroupTotal(fint); break; case csRptFormulaType.CSRPTGROUPMAX: evalGroupMax(fint); break; case csRptFormulaType.CSRPTGROUPMIN: evalGroupMin(fint); break; case csRptFormulaType.CSRPTGROUPAVERAGE: evalGroupAverage(fint); break; case csRptFormulaType.CSRPTGROUPPERCENT: evalGroupPercent(fint); break; case csRptFormulaType.CSRPTGROUPCOUNT: evalGroupCount(fint); break; case csRptFormulaType.CSRPTGROUPLINENUMBER: evalGroupLineNumber(fint); break; } } }
public void initVariable(cReportFormula formula) { cReportVariable var = null; cReportFormulaInt fint = null; cStructTime st = null; for (int _i = 0; _i < formula.getFormulasInt().count(); _i++) { fint = formula.getFormulasInt().item(_i); for (int _j = 0; _j < fint.getVariables().count(); _j++) { var = fint.getVariables().item(_j); System.TypeCode typeCode = System.Type.GetTypeCode(var.getValue().GetType()); switch (typeCode) { case System.TypeCode.DBNull: break; case System.TypeCode.Decimal: case System.TypeCode.Double: case System.TypeCode.Int16: case System.TypeCode.Int32: case System.TypeCode.Int64: case System.TypeCode.Single: case System.TypeCode.UInt16: case System.TypeCode.UInt32: case System.TypeCode.UInt64: case System.TypeCode.Byte: case System.TypeCode.SByte: case System.TypeCode.DateTime: case System.TypeCode.Boolean: var.setValue(0); break; case System.TypeCode.Char: case System.TypeCode.String: var.setValue(""); break; case System.TypeCode.Object: if (var.getValue() is cStructTime) { st = (cStructTime)var.getValue(); st.setHour(0); st.setMinute(0); st.setSecond(0); } break; case System.TypeCode.Empty: break; default: break; } } } }
// it compiles the code of every formula // first it replaces every internal function by // dummy return values (of the type of the internal function) // if after the replace there is code it call cReportScriptEngine.compileCode // if there are no errors it returns true // public bool checkSyntax(cReportFormula formula) { try { String code = ""; m_formula = formula; m_formula.getFormulasInt().clear(); // check syntax code = formula.getText(); m_formula.setTextC(code); pCheckSyntax(code); return true; } catch (Exception ex) { cError.mngError(ex, "checkSyntax", C_MODULE, ""); m_formula = null; m_fint = null; return false; } }