IList object's property to report column without data source

Stimulsoft Reports.WEB discussion
billd
Posts: 10
Joined: Wed Feb 20, 2013 11:56 pm

IList object's property to report column without data source

Post by billd »

Hi,
I want to pass an IList to a Report. The code is:

Code: Select all

 
IList<Product> pros = new List<Product>
     {
      new Product() { Id = 1, Name = "Gizmo 1", Price = 1.99M },
      new Product() { Id = 2, Name = "Gizmo 2", Price = 2.99M },
      new Product() { Id = 3, Name = "Gizmo 3", Price = 3.99M }
     };

 StiReport report = new StiReport();
report.RegData("ProductIEnumerable", pros);
report.Load(@"C:\Projects\Test\Content\Reports\Products.mrt");
return StiMvcViewer.GetReportSnapshotResult(HttpContext, report);  // error line
In the report in the DataBand I have tree fields (columns):
{pros.Id}, {pros.Name} and {pros.Price}

I get an error:
error CS0103: The name 'pros' does not exist in the current context.

I've tried:
{Id}, {Name} and {Price}
{ProductIEnumerable.Id}, {ProductIEnumerable.Name} and {ProductIEnumerable.Price}

Still the same error.

How do I assign a report column to an object's property without data source?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: IList object's property to report column without data so

Post by HighAley »

Hello.

Could you send us a working sample project which reproduces the issue?

Thank you.
Michail
Posts: 20
Joined: Wed Feb 20, 2013 6:16 am

Re: IList object's property to report column without data so

Post by Michail »

billd hello!
You need in Products.mrt create Business object with Name - ProductIEnumerable( my - VeneerBalance)
this Business object has variable - id , name , price ( i have Id,Name and i.e)
you create Data,which get necessary data from business object

Sorry for my bad English!
Attachments
help.jpg
help.jpg (493.16 KiB) Viewed 5106 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: IList object's property to report column without data so

Post by HighAley »

Hello.
Michail wrote:You need in Products.mrt create Business object with Name - ProductIEnumerable( my - VeneerBalance)
this Business object has variable - id , name , price ( i have Id,Name and i.e)
you create Data,which get necessary data from business object
If you want to create business object you should use RegBusinessObject() method.
The RegData() method creates Data Sources.

Thank you.
billd
Posts: 10
Joined: Wed Feb 20, 2013 11:56 pm

Re: IList object's property to report column without data so

Post by billd »

Thanks guys!
I got it.
It works :)

Could you please help me with another problem?

I want to pass a List of product objects where each product contains a List of Test objects:

Code: Select all

 List<Product> _data = new List<Product>
     {
      new Product() { Id = 1, Name = "Gizmo 1", Price = 1.99M },
      new Product() { Id = 2, Name = "Gizmo 2", Price = 2.99M },
      new Product() { Id = 3, Name = "Gizmo 3", Price = 3.99M }
     };
	 List<Test> testList = new List<Test>();
	foreach (Product p in _data)
	{
		for (int i = 0; i < 4; i++)
		{
			Test t = new Test { TestName = "Test " + i.ToString() };
			testList.Add(t);
		}
		p.Tests = testList;
	}

	  StiReport report = new StiReport();
	  report.RegBusinessObject("pros", _data);
	  report.Load(@"C:\Reports\ProductDetail.mrt");
How do I design the report?

I've created the product business object with a nested business object called Test (string TestName) (see the attachment) and have used a Sub-Report control to display all Test related to each product but it doesn't work. I can't create a Relation between objects because they don't have any related property.

If the business object is nested does the relation is created automatically?
Do I need to create a product Id in the Test object?
Attachments
BO_image.png
BO_image.png (5.18 KiB) Viewed 5090 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: IList object's property to report column without data so

Post by HighAley »

Hello.
billd wrote:I've created the product business object with a nested business object called Test (string TestName) (see the attachment) and have used a Sub-Report control to display all Test related to each product but it doesn't work. I can't create a Relation between objects because they don't have any related property.
There is a problem with using Business objects in sub-reports. Please, use Panel instead of sub-report. You don't need to set the relation between band to get master-detailed report with business objects.

Thank you.
billd
Posts: 10
Joined: Wed Feb 20, 2013 11:56 pm

Re: IList object's property to report column without data so

Post by billd »

Thanks Aleksey.
I've been trying to find an example without any success.
Could you please point to a resource (video or text) or some example how to do it?

Regards,
B.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: IList object's property to report column without data so

Post by Alex K. »

Hello,

Please see the videos from the following link:
http://www.stimulsoft.com/en/videos?tags=busobjects

Thank you.
billd
Posts: 10
Joined: Wed Feb 20, 2013 11:56 pm

Re: IList object's property to report column without data so

Post by billd »

Hi Aleksey,

I've watched them all but it didn't help much. No example for this particular scenario or using a panel for Master-Detail display as you have mentioned in your previous post.

I've tried connecting directly to a DB and have tried using a stored procedure together with the Master-Detail wizard and both solutions work fine.

With a manually created report and a passed list of objects with another list of objects nested, it doesn't work.
I don't know how to create connection between two DataBands.

I'm stuck here. I really like your product but my app can't connect directly reports to the DB. In my controllers I have a list of ViewModel objects returned from the service layer.

Thank you,
B.
Attachments
TestReport.zip
(11.53 MiB) Downloaded 418 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: IList object's property to report column without data so

Post by Alex K. »

Hello,

Please check the business objects name in your class and in your report. It is different.
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string Desc { get; set; }
public List<Test> Tests { get; set; }
}
but in report datasource have name "Test". Please try to change the name of business object from "Test" to "Tests".

Thank you.
Attachments
Capture.PNG
Capture.PNG (29.6 KiB) Viewed 5041 times
Post Reply