Strange issue with .mrt file (int to int - type casting issue)

Stimulsoft Reports.Net discussion
Post Reply
nagarajasia
Posts: 14
Joined: Thu Dec 08, 2016 8:56 am

Strange issue with .mrt file (int to int - type casting issue)

Post by nagarajasia » Wed Jan 08, 2020 8:43 am

Hello,

I got stuck up with a strange issue :( with Stimulsoft PDF rendering process.

Issue Details:-

I have a database table "Products" with column "Product_Id" and its datatype is integer.
In the .mrt file, there is a text box control (Text1) located inside the DataBand control. In the Text1_BeforePrint event contains the following code

Code: Select all

int Product_ID= Products.Product_Id;  //It throws an error
//int Product_ID=int.Parse(Products.Product_Id.ToString());  This would revolve the issue
if(Product_ID>123)
{
  Text1.TextValue="If loop";
}
else
{
  Text1.TextValue="Else Loop";
}
Strange Issue
During the PDF rendering process with asp.net web application, it throws a type casting exception "Cannot implicitly convert type 'string' to 'int'" in the very first line of code.
int Product_ID= Products.Product_Id;
I am wondering why it throws error when the column ProductId is already int column.

No issue with XML DataSource
We have checked the same .mrt file with XML datasource but this time it rendered the PDF perfectly without issue.


Version Details
.Net Version :- Asp.net 4.0
Stimulsoft Version :- 2018.1.6

Note
Here, i intend is to know why the above issue occurred when the data passed via asp.net application Dataset but not with XML datasource.
As of now, we have overcome this issue by using the type casting int.Parse() as below,

Code: Select all

int Product_ID=int.Parse(Products.Product_Id);

To reproduce the same issue at your end, Kindly use the attached .mrt file and the below code with .net application

Code: Select all

protected void btn_GeneratePDF_Click(object sender, EventArgs e)
        {
            DataSet ds_Source = GetSource();
            //ExportXML(ds_Source);
            GeneratePDF(templatePath, ds_Source);
        }

        public void GeneratePDF(string templatePath,DataSet ds_InputData)
        {
            
            Report.Load(templatePath);
            Report.Dictionary.Databases.Clear();
            Report.Dictionary.DataSources.Clear();
            Report.RegData(ds_InputData);
            Report.Dictionary.Synchronize();
            Report.Compile();
            Report.Render(true);

            using (Stream ostream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"CurrentPDFs\Sample.PDF", FileMode.OpenOrCreate, FileAccess.Write))
            {
                Report.ExportDocument(StiExportFormat.Pdf, ostream);

            }
        
        }

        public class Employee
        {
            public string Employee_Name { get; set; }
            public int Employee_ID { get; set; }
           
        }

        public class Products
        {
            public string Product_Name { get; set; }
            public int Product_Id { get; set; }
         
        }


        public DataSet GetSource()
        {
            /**/
            List<Employee> Students = new List<Employee>(){  
                new Employee() { Employee_Name = "Pradeep",  Employee_ID = 100 },  
                 new Employee() { Employee_Name = "Smith",  Employee_ID = 101},  
                new Employee() { Employee_Name = "John",  Employee_ID = 102 }  
            };


            List<Products> ProductInformation = new List<Products>(){  
                new Products() { Product_Name = "Chrysler",  Product_Id = 123},  
                 new Products() { Product_Name = "Donnellys", Product_Id = 456},  
             
            };


            DataSet ds_ExtensionMethod = new DataSet();
            ExtensionMethod extensionMethod = new ExtensionMethod();

           ds_ExtensionMethod.Tables.Add(extensionMethod.ToDataTable(Students));
           ds_ExtensionMethod.Tables.Add(extensionMethod.ToDataTable(ProductInformation));


            return ds_ExtensionMethod;
        }

To check the same with xml kindly use the attached data.xml and data.xsd files.
Attachments
Report.mrt
(5.5 KiB) Downloaded 7 times
data.xsd
(1.05 KiB) Downloaded 6 times
data.xml
(602 Bytes) Downloaded 6 times
HighAley
Posts: 8115
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Strange issue with .mrt file (int to int - type casting issue)

Post by HighAley » Mon Jan 13, 2020 7:17 pm

Hello,


We don't see the ExtensionMethod description in your code.
The issue could be in it.

Thank you.
nagarajasia
Posts: 14
Joined: Thu Dec 08, 2016 8:56 am

Re: Strange issue with .mrt file (int to int - type casting issue)

Post by nagarajasia » Tue Jan 14, 2020 1:34 pm

Hello,

Thanks for your reply. Here is the ExtensionMethod code,

Code: Select all

  public class ExtensionMethod
    {
        public DataTable ToDataTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);
            //Get all the properties by using reflection   
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                //Setting column names as Property names  
                dataTable.Columns.Add(prop.Name);
            }
            foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {

                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }

            return dataTable;
        }  
    }
Lech Kulikowski
Posts: 2101
Joined: Tue Mar 20, 2018 5:34 am

Re: Strange issue with .mrt file (int to int - type casting issue)

Post by Lech Kulikowski » Sun Jan 19, 2020 9:43 pm

Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
nagarajasia
Posts: 14
Joined: Thu Dec 08, 2016 8:56 am

Re: Strange issue with .mrt file (int to int - type casting issue)

Post by nagarajasia » Tue Jan 21, 2020 4:17 pm

Hello,

Thanks for your reply. Kindly provide a solution ASAP.
Post Reply