Page 1 of 2

IList object's property to report column without data source

Posted: Thu Feb 21, 2013 12:16 am
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?

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

Posted: Thu Feb 21, 2013 11:37 am
by HighAley
Hello.

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

Thank you.

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

Posted: Thu Feb 21, 2013 12:36 pm
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!

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

Posted: Thu Feb 21, 2013 1:19 pm
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.

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

Posted: Thu Feb 21, 2013 10:31 pm
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?

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

Posted: Fri Feb 22, 2013 12:46 pm
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.

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

Posted: Mon Feb 25, 2013 9:57 pm
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.

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

Posted: Tue Feb 26, 2013 10:57 am
by Alex K.
Hello,

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

Thank you.

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

Posted: Thu Feb 28, 2013 2:55 am
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.

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

Posted: Fri Mar 01, 2013 11:15 am
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.