Simplified LINQ Reporting Template Syntax for Split Contains ToDateTime ToBoolean Methods | Build Report DataTable Row | C# .NET

Hello Sir,

I am paid user of aspose and I have few queries related to template synatax that can work with Linq reporting engine.
For your reference, I have attached source template and output document.

Below is the .net code:

DataTable dataTable = new DataTable("tbl");
dataTable.Columns.Add(new DataColumn("DT#judgment_hearing_date#"));
dataTable.Columns.Add(new DataColumn("BR#P1#", typeof(Boolean)));
dataTable.Columns.Add(new DataColumn("BR#P2#", typeof(Boolean)));
dataTable.Columns.Add(new DataColumn("DT#property_state#"));
DataRow dataRow = dataTable.NewRow();
dataRow[0] = Convert.ToDateTime("6/6/2020");
dataRow[1] = false;
dataRow[2] = true;
dataRow[3] = "AL";
dataTable.Rows.Add(dataRow);
ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(System.Convert));
engine.KnownTypes.Add(typeof(System.Boolean));
engine.KnownTypes.Add(typeof(System.String));
engine.KnownTypes.Add(typeof(System.Array));
engine.KnownTypes.Add(typeof(System.DateTime));
engine.Options = ReportBuildOptions.InlineErrorMessages;
engine.BuildReport(docMain, dataTable.Rows[0], "firstrow");

Query1:
Below mentioned template syntax is working but it looks complex for end user. Is there any other way to convert string into different datatype like int,datetime etc in simple way.

<<if [Convert.ToDateTime(DT#judgment_hearing_date#) >= Convert.ToDateTime(“5/6/2020”)]>>Print this text if it’s a date greater or equal to than 5/6/2020 
<<else>>Otherwise print this if date is less than 05/06/2020<</if>>

Query2:
Below mentioned template syntax is working fine and returning true but it looks complex for end user. is there any other simple way to check string in string array ?

<<if ["AL,GA".Split(',').Contains(DT#property_state#)]>>Array contains AL<<else>>Array doesn’t contain AL and GA<</if>>

Simpler example like below:

<<if [DT#property_state# in ("AL,GA")]>>Array contains AL<<else>>Array doesn’t contain AL and GA<</if>>

Query3:
As you can see in the above .net code where datatable column (BR#P1#) value is true with datatype as boolean. below are the two template syntax called as code1 and code2.
Code1 is working but why code2 is not working ?

Code1: (It is working fine)

<<if [BR#P1# == true]>>Print this text if P1 evaluates to true<<elseif [BR#P2# == true]>>Otherwise print this if P2 evaluates to True<<else>>Otherwise print this <</if>>

and this code is not working fine

Code2: (Not working)

<<if [BR#P1#]>>Print this text if P1 evaluates to true<<elseif [BR#P2#]>>Otherwise print this if P2 evaluates to True<<else>>Otherwise print this <</if>>

I also check the datatype, both are returning boolean type

<<[(BR#P1#).GetType()]>>  
<<[(Convert.ToBoolean(BR#P1#)).GetType()]>>   

doc.zip (42.9 KB)

@johnkaltz,

There are some ways to shorten template expressions in the same way as it can be done in C#. For example,

Convert.ToDateTime(“5/6/2020”)
can be replaced with
new DateTime(2020, 5, 6)

and

"AL,GA".Split(',').Contains(DT#property_state#)
can be replaced with
"AL,GA".Contains(DT#property_state#)

This most likely happens because the corresponding data column allows null values. This makes the engine to treat the column as if it was of Nullable type. If you never have null values in the column then you may set DataColumn.AllowDBNull to false, then everything should work as expected.

private static DataTable GetDataTable()
{
    DataTable dataTable = new DataTable("tbl");
    dataTable.Columns.Add(new DataColumn("DT#judgment_hearing_date#"));
    dataTable.Columns.Add(new DataColumn("BR#P1#", typeof(Boolean)) { AllowDBNull = false });
    dataTable.Columns.Add(new DataColumn("BR#P2#", typeof(Boolean)) { AllowDBNull = false });
    dataTable.Columns.Add(new DataColumn("DT#property_state#"));
    DataRow dataRow = dataTable.NewRow();
    dataRow[0] = Convert.ToDateTime("6/6/2020");
    dataRow[1] = false;
    dataRow[2] = true;
    dataRow[3] = "AL";
    dataTable.Rows.Add(dataRow);

    return dataTable;
}

Document doc = new Document("E:\\Temp\\in.docx");
DataTable dt = GetDataTable();
ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(System.Convert));
engine.KnownTypes.Add(typeof(System.Boolean));
engine.KnownTypes.Add(typeof(System.String));
engine.KnownTypes.Add(typeof(System.Array));
engine.KnownTypes.Add(typeof(System.DateTime));
engine.Options = ReportBuildOptions.InlineErrorMessages;
engine.BuildReport(doc, dt.Rows[0], "firstrow");
doc.Save("E:\\Temp\\20.7.docx");

A post was split to a new topic: Enhancements to ReportBuildOptions.InlineErrorMessages