Use a class instead of datatable

Stimulsoft Reports.NET discussion
Post Reply
overcrash
Posts: 11
Joined: Thu Aug 21, 2008 3:09 pm
Location: Ir

Use a class instead of datatable

Post by overcrash »

How can i use my class instead of dataset or datatabel for report database?
i want to use the following class:

Code: Select all

    [Serializable]
    class Person
    {
        string code, name;

        public Person()
        {
        }
        public string Code
        {
            get { return code; }
            set { code = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Use a class instead of datatable

Post by Brendan »

You should be able to register it just like a DataTable of DataSet source

Code: Select all

Person p = new Person();
p.Code = "JB";
p.Code = "Joe Bloggs";

StiReport report = new StiReport();
report.RegData("Person", p);
report.Design();
Also add the Assembly Reference to the report property "ReferencedAssemblies" so it knows where the Person class resides. You can do this from the Designer by select the Report object from the property grid and setting the property.
overcrash
Posts: 11
Joined: Thu Aug 21, 2008 3:09 pm
Location: Ir

Use a class instead of datatable

Post by overcrash »

I couldn't add my fields in report.
1. add a stimulreport object in form1 --> stiReport1
2. add "TestStimulReport.exe" in its ReferencedAssemblies
3. call design for stiReport1

so what shall I do for find person class and properties?
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Use a class instead of datatable

Post by Brendan »

Here's a vs2005 sample using 2007.3.0.0 stimulreport references (you may need to update the project references to whatever version you have installed)
Download Link

When the designer is open you should see your registered object in there Dictionary here:
Image
overcrash
Posts: 11
Joined: Thu Aug 21, 2008 3:09 pm
Location: Ir

Use a class instead of datatable

Post by overcrash »

Thank you
It is in runtime design mode but how can i have it in design mode
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Use a class instead of datatable

Post by Brendan »

Once you register your business objects with the report file, you can save the generated report to a location on your machine (File -> Save As).

After this you can use that mrt file to design your report outside of runtime.

Then when you want to use the report you have designed at run time you can call

Code: Select all

//Get Business object from Application
Person p = new Person();
p.Code = "JB";
p.Code = "Joe Bloggs";

//Load Designed Report
stiReport1.Load(@"C:\myReports\MyReport.mrt");
stiReport1.RegData("Person", p);
stiReport1.Show();
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Use a class instead of datatable

Post by Brendan »

You can also register Business Objects in the report from design mode using:

1. From the Dictionary Add "New Data Source.."
2. Select "Data from Business Objects"
3. Type in the 'Name in Source' and 'Name' of your class "Person".
4. Press the 'Get Columns from Assembly' Button on the toolbar
5. Browse to your compiled assembly
6. Check the Business Objects and the Properties you wish to register as columns.
7. Click OK to add the data source structure for your business object so you can begin designing.

1. Some things to note is that your assembly must be compiled before you can use it as a lookup for a Data Source.
2. Any classes you wish to expose must be compiled as 'public class'. So if Person was just 'class Person' then it will not show. It must be exposed as 'public class Person' in your assembly.
3. Make sure to add the assembly name to the ReferencedAssemblies property of the Report.
4. You probably won't have any design time 'Preview' as there is no actual data registered with the report, this would have to be done at runtime.
overcrash
Posts: 11
Joined: Thu Aug 21, 2008 3:09 pm
Location: Ir

Use a class instead of datatable

Post by overcrash »

2. Any classes you wish to expose must be compiled as 'public class'. So if Person was just 'class Person' then it will not show. It must be exposed as 'public class Person' in your assembly.
Thank you Brendan
overcrash
Posts: 11
Joined: Thu Aug 21, 2008 3:09 pm
Location: Ir

Use a class instead of datatable

Post by overcrash »

Hi again,
Whats happen if I obfuscate my exe ? whether it could find classes after obfuscating or it dose not need them after compiled.
Post Reply