NavHelperFunction

When converting RDLC reports to ForNAV reports, you will notice that the Showoutput value on sections and controls sometimes has a function call to the NavHelperFunction, like in the following example from the RDLC Purchase Invoice:

 

NavHelperFunction.IIFNOT(DynamicsNavDataSet.ShowInternalInfo==true && DynamicsNavDataSet.DimText_DimensionLoop1!=””,false,true)

 

The NavHelperFunction has been put in place to emulate some of the built-in RDLC functions and custom VB-script functions in the standard reports.

 

Most of the functions emulate the corresponding RDLC functions 1:1 – but because ForNAV works on single records being read and not a dataset’s set-functions (such as First, Last, Sum, Previous and CountRows) it does not return the correct value. However, because the ForNAV Converter places controls and/or sections referring to these functions in Headers, Bodies, and Footers, depending on which RDLC function has been used, the logic works in the same way as in the RDLC report. Emulation of the VB-script functions is mainly to mitigate the lack of support RDLC has for page breaks/group totals, which also often has global variables (states) tied to them.

 

Because ForNAV implements the standard JavaScript function library and has better support for page breaks/group totals, both from code and properties, we recommend that you do not use the the NavHelperFunction to develop new reports. In situations where the logic is hard to understand, we recommend replacing it with JavaScript logic.

 

The following is the C# implementation for the current list of NavHelperFunctions:

 

public class ScriptHelperFunctions

{

Report report;

public ScriptHelperFunctions(Report report) { this.report = report; }

public String Space(int count) => new string(‘ ‘, count);

public object GetFieldValue(string ClassName, string FieldName) { return report.NavSettings.GetFieldValue(ClassName, FieldName); }

public Object IIF(bool Expr, Object IfTrue, Object IfFalse) { return Expr ? IfTrue : IfFalse; }

public Object IIFNOT(bool Expr, Object IfFalse, Object IfTrue) { return Expr ? IfTrue : IfFalse; }

public Object First(Object Value, string Scope) { return (Value); }

public Object First(Object Value) { return (Value); }

public Object Last(Object Value, string Scope) { return (Value); }

public Object Last(Object Value) { return (Value); }

public Object Sum(Object Value, string Scope) { return (Value); }

public Object Sum(Object Value) { return (Value); }

public Object Previous(Object Value, string Scope) { return (null); }

public Object Previous(Object Value) { return (null); }

public Object RunningValue(Object Value, Object Function, string Scope) { return Value; }

public Object RunningValue(Object Value, Object Function) { return Value; }

public bool IsNullOrEmpty(String Text) { return Text == null || Text == “”; }

public int RowNumber(Object Scope) { return 0; } // Used for color

public int Count(object Value) { return 1; } // Rec.Count;

public int CountRows() { return (1); }

public int CountDistinct(object Value) { return (1); }

public int ToInt(Object Value) { return int.Parse(Value.ToString()); }

public DateTime ToDate(Object Value) { return DateTime.Parse(Value.ToString()); }

public Double ToDecimal(Object Value) { return Double.Parse(Value.ToString()); }

public float ToFloat(Object Value) { return float.Parse(Value.ToString()); }

public Double Round(Double Number) { return ((int)Number); }

public string ToString(Object Value) { return Value.ToString(); }

public int Len(String Value) { return Value.Length; }

public int InStr(String Value, string Value2) { return Value.IndexOf(Value2) + 1; }

public string Left(string Value, int Length) { return Value.Substring(0, Length); }

public string Right(string Value, int Length) { return Value.Substring(Value.Length – Length, Length); }

public string Replace(string Src, Object From, Object To) { return From.ToString() == “” ? Src : Src.Replace(From.ToString(), To.ToString()); }

public string Trim(String s) { return (s.Trim()); }

public string TrimEnd(String Value) { return (Value.TrimStart()); }

public string TrimStart(String Value) { return (Value.TrimEnd()); }

public string Upper(String Value) { return (Value.ToUpper()); }

public string Lower(String Value) { return (Value.ToLower()); }

public string Chr(int No) { char c = (char)No; return (c.ToString()); }

public string Choose(int Number, params string[] Values) { return Number > 0 && Number <= Values.Length ? Values[Number-1] : “”; }

public string[] Split(string Value, string Separator) { return Value.Split(new string[] { Separator },StringSplitOptions.None); }

public string Format(string FormatString,params object[] Values) { return string.Format(FormatString, Values); }

public Object BlankZero(Double Number) { if (Number == 0) return “”; else return Number; }

public Object BlankPos(Double Number) { if (Number > 0) return “”; else return Number; }

public Object BlankZeroAndPos(Double Number) { if (Number >= 0) return “”; else return Number; }

public Object BlankNeg(Double Number) { if (Number < 0) return “”; else return Number; }

public Object BlankNegAndZero(Double Number) { if (Number <= 0) return “”; else return Number; }

public Double CalcPct(Double Amount1, Double Amount2) { return Math.Round(Amount2 != 0d ? Amount1 / Amount2 * 100d : 0d,1); }

public string CalcLeft(string Value, string Value2) { int Index = Value.IndexOf(Value2); return Index >= 0 ? Left(Value, Index) : “”; }

public string CalcRight(string Value, string Value2) { int Index = Value.IndexOf(Value2); return Index >= 0 ? Right(Value, Value.Length – Index + 1) : “”; }

public bool IsNull(Object Value) { return Value == null || Value == DBNull.Value; }

public string FormatAddress(string Name, string Address, string Address2, string City, string County) { return Name + (Address == “” ? “” : “,” + Address) + (Address2 == “” ? “” : “,” + Address2) + (City == “” ? “” : “,” + City) + (County == “” ? “” : “,” + County); }

public object BlankToZero(string Value) { if (Value == “”) return 0; else return Value; }

public Double NotBlankZero(Double Value) { return Value; }

private Double _NegValue = 0;

public Double NegValue(Double Value) { _NegValue += Value; return (_NegValue); }

public Double NegativeValuesFunc(Double Value) { return Value > 0 ? Value : 0; }

public Double AverageFunc(Double Cost, Double Quantity) { return Quantity == 0 ? 0 : Cost / Quantity; }

public string CutOnlyFirstLetters(string Value) { string[] Values = Value.Split(‘ ‘); return Left(Values[0], 2) + Left(Values[1], 2); } // Return Left(Cstr(Choose(1, Split(Cstr(Stroka) )) ),2)+ Left(Cstr(Choose(2,Split(Cstr(Stroka))) ),2)

public string CutOnlyFourLetters(string Value) { string[] Values = Value.Split(‘ ‘); return Left(Values[0], 5) + Left(Values[1], 4); } // Return Left(Cstr(Choose(1, Split(Cstr(Stroka) )) ),5)+ Left(Cstr(Choose(2,Split(Cstr(Stroka))) ),4)

 

int _PageOffset = 0;

public int GetPageNumber(bool NewPage, int PageNumber) { if (NewPage) { _PageOffset = PageNumber – 1; } return PageNumber – _PageOffset; }

public bool ResetPageNumber() { return true; }

 

string _CompanyName = “”;

public bool SetCompanyName(string CompanyName) { if (CompanyName != “”) _CompanyName = CompanyName; return true; }

public string GetCompanyName() { return _CompanyName; }

 

string _PageCaption = “”;

public bool SetPageCaption(string PageCaption) { if (PageCaption != “”) _PageCaption = PageCaption; return true; }

public string GetPageCaption() { return _PageCaption; }

string _ReportTitle = “”;

public bool SetReportTitle(string ReportTitle) { if (ReportTitle != “”) _ReportTitle = ReportTitle; return true; }

public string GetReportTitle() { return _ReportTitle; }

private object[] _Picture = new object[] { null, null, null };

public bool SetPicture(Object Value, int Group) { if (Value != null && Value != DBNull.Value) _Picture[Group-1] = Value; return true; }

public object GetPicture(int Group) { return _Picture[Group-1]; }

string _TextPage = “”;

public bool SetTextPage(string TextPage) { if (TextPage != “”) _TextPage = TextPage; return true; }

public string GetTextPage() { return _TextPage; }

Object _CodeGroup = null;

public bool CodeChanged(object CodeGroup) { if (CodeGroup != _CodeGroup) { _CodeGroup = CodeGroup; return true; } else return false; }

public string GetCopyText(string CopyText) { return CopyText; }

public string CalcIndicatorPct(Double Value, Double Sum) { return (Value == 0d ? 0d : (Sum – Value) / Value * 100).ToString(“N1”, CultureInfo.InvariantCulture); }

public Double CalcProfitAmount(Double Amount_LCY, Double CostAmount) { return (Amount_LCY – CostAmount); }

public Double CalcInvDisc(Double SalesPrice, Double UsagePrice) { return (UsagePrice != 0d ? 100 * SalesPrice / UsagePrice : 100) / 10d; }

public Double CalcCostPerUnit(Double Value, Double Value2, Double Value3) { if (Value3 > 0) Value2 /= Value3; return Value + Value2; }

public Double Rnd(int Seed) { return new Random(DateTime.Now.Millisecond).NextDouble(); }

public Double Rnd() { return Rnd(0); }

 

int _ColPage = 0;

public int NumOfPage(object Group) { return ++_ColPage; }

 

object _IsShownGroup = null;

int _IsShownCount = 0;

public bool IsShown(object Group)

{

if (Group == _IsShownGroup)

{

_IsShownCount++;

return _IsShownCount > 2 ? true : false;

}

_IsShownGroup = Group;

_IsShownCount = 0;

return false;

}

 

string _AllLines = “”;

public string GetLines(int ExistLines) { _AllLines += ExistLines.ToString(); return _AllLines; }

public string ShowLines() { return _AllLines; }

 

int _Offset = 0;

public int GetGroupPageNumber(bool NewPage,int PageNumber) { if (NewPage) _Offset = PageNumber – 1; return PageNumber – _Offset; }

public string GetGroupPageNumber(string PageCaption, bool NewPage, int PageNumber) { _Offset = PageNumber – 1; return PageCaption + (PageNumber – _Offset).ToString(); }

public bool IsNewPage() { return true; }

Object _CurrentGroup=null, _CurrentGroup2 = null,_CurrentGroup3 = null;

public bool IsNewPage(Object Group,Object Group2)

{

if (Group != _CurrentGroup)

{

_CurrentGroup2 = Group2;

_CurrentGroup = Group;

return true;

}

if (Group != _CurrentGroup2)

{

_CurrentGroup2 = Group2;

return true;

}

return false;

}

bool newPage = false;

public bool IsNewPage(Object Group, Object Group2, Object Group3)

{

newPage = false;

 

if (Group != _CurrentGroup)

{

newPage = true;

 

_CurrentGroup = Group;

_CurrentGroup2 = Group2;

_CurrentGroup3 = Group3;

}

else

{

if (Group2 != _CurrentGroup2)

{

newPage = true;

_CurrentGroup2 = Group2;

_CurrentGroup3 = Group3;

}

else

{

if (Group3 != _CurrentGroup3)

{

newPage = true;

_CurrentGroup3 = Group3;

 

}

}

}

return newPage;

}

bool _HideOnce = true;

public bool HideOnce() { if (_HideOnce) { _HideOnce = false; return true; } else return false; }

 

bool _HideNext = false;

public bool HideNext() { if (!_HideNext) { _HideNext = true; return false; } else return true; }

 

bool _MustGroupFooterPrint = false;

public bool MustGroupFooterPrint(bool Value,bool Value2) { if (!_MustGroupFooterPrint) { _MustGroupFooterPrint = !Value && Value2; return _MustGroupFooterPrint; } else return false; }

public bool ShowFooter() { return HideOnce(); }

public bool HideFooter() { return HideNext(); }

 

// 37 Balance Comp. – Prev.Year

string _FooterText = null;

public string SetFooterText(string FooterText) { if (FooterText != null && FooterText != “”) _FooterText = FooterText; return null; }

public string GetPageFooter(int PageNumber,int TotalPages)

{

if (_FooterText == null)

return “”;

string[] t = _FooterText.Split((char) 177);

return string.Format(t[2], PageNumber, PageNumber == TotalPages ? t[0] : t[1]);

}

 

// Report 7312 Bin Content Create Wksh Report

bool _first = true;

object _currentgroup = null;

public bool HideRow() { return HideNext(); }

public bool HideRow2(Object Group)

{

if (_first)

{

_first = false;

return true;

}

if (_currentgroup == Group)

return false;

_currentgroup = Group;

return true;

}

 

// Report 126 Reminder Nos.

int _AllLinesCounter = 0,_AllLinesCounter2 = 0;

public bool LinesCounter(bool Value) { if (!Value) _AllLinesCounter++; return Value; }

public bool LinesCounter2(bool Value) { if (!Value) _AllLinesCounter2++; return Value; }

public int ShowAllLinesCounter() { return _AllLinesCounter == 0 ? _AllLinesCounter2 : _AllLinesCounter; }

public int ShowAllLinesCounter2() { return _AllLinesCounter2; }

int _LinesCount = 0, _LinesShown = 0;

public int ShowNumberOfLinesPerOnePage(int AllLinesCounter,int P)

{

if (P == 1)

_LinesShown = 0;

int a = AllLinesCounter – _LinesShown;

_LinesShown = AllLinesCounter;

return P > 1 && _LinesShown == 0 ? 0 : a;

}

public int NumberOfLinesPerOnePage(bool Visible) { if (!Visible) _LinesCount++; return _LinesCount; }

public int SumOfLinesPerOnePage() { return _LinesCount; }

public string FormatAmount(Double Value) { return Value > 0 ? “(” + Math.Round(Value, 0).ToString(“#,##0.##”) + “)” : Math.Round(-Value, 0).ToString(“#,##0.##”); }

}