PruneBottle
asked on
FastReports how to generate a master-detail report in code
Fast Reports Inc. home siteRulesHelpSearchMembers Calendar
Search this forum only? More Search Options [X]My Assistant
Loading. Please Wait...
Site Message (Message will auto close in 2 seconds)
Logged in as: BatteryPack ( Log Out )
My Controls · View New Posts · My Assistant · My Friends · 0 New Messages
Fast Reports forum > Fast Reports Products > FastReport 4.0
Master-Detail using Code, How do you create a Master-Detail in code Options Track this topic Email this topic Print this topic Download this topic Subscribe to this forum Display Modes Switch to: Outline Standard Switch to: Linear+
BatteryPack
View Member Profile Add as Friend Send Message Find Member's Topics Find Member's Posts Today, 03:33 AM Post #1
Newbie
Group: Members
Posts: 3
Joined: 14-October 11
Member No.: 54120
Hi all.
I am trying out the demo software, and am most impressed with FastReport.
However, I have run into a fundamental problem for which there seems to be no documentation whatsoever.
I need to generate master-detail reports in code.
My example is a small school consisting of 3 teachers, each having 3 pupils.
All data comes from simple xml, and SQL is not used anywhere.
<?xml version="1.0" encoding="utf-8"?>
<school>
<teacher>
<TeacherName>Thomas</Teach erName>
<pupils>
<pupil>
<Name>Tim</Name>
</pupil>
<pupil>
<Name>Terry</Name>
</pupil>
<pupil>
<Name>Thelia</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Dillman</Teac herName>
<pupils>
<pupil>
<Name>Diggy</Name>
</pupil>
<pupil>
<Name>Derrick</Name>
</pupil>
<pupil>
<Name>Dora</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Fredman</Teac herName>
<pupils>
<pupil>
<Name>Fanny</Name>
</pupil>
<pupil>
<Name>Fern</Name>
</pupil>
<pupil>
<Name>Fenwick</Name>
</pupil>
</pupils>
</teacher>
</school>
I generate a schema which produces a typed dataset.
I proceed as follows.
public partial class Form1 : Form
{
public school School;
public school.teacherDataTable Teachers;
public school.pupilDataTable Pupils;
public Form1()
{
InitializeComponent();
School = new school();
Teachers = new school.teacherDataTable();
Pupils = new school.pupilDataTable();
School.ReadXml(@"c:\Fastre portStudy2 \Data\Scho ol41.xml") ;
Teachers.ReadXml(@"c:\Fast reportStud y2\Data\Sc hool41.xml ");
Pupils.ReadXml(@"c:\Fastre portStudy2 \Data\Scho ol41.xml") ;
}
I then try to generate a FasReport as follows:
private void btnLoad_Click(object sender, EventArgs e)
{
Report report = new Report();
report.RegisterData(School , "school");
report.RegisterData(School .Tables["t eacher"], "teacher");
report.RegisterData("pupil ", "relationteacher_pupils");
report.GetDataSource("teac her").Enab led = true;
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
report.Pages.Add(page1);
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = Units.Millimeters * 15f;
TextObject SchoolTitleText = new TextObject();
SchoolTitleText.Name = "SchoolTitle";
SchoolTitleText.Bounds = new RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
SchoolTitleText.Text = "NorthDale School";
SchoolTitleText.HorzAlign = HorzAlign.Left;
SchoolTitleText.Font = new Font("Tahoma", 14, FontStyle.Bold);
page1.ReportTitle.Objects. Add(School TitleText) ;
GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 1;
group1.Condition = "[teacher.TeacherName]";
page1.Bands.Add(group1);
group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Millimeters * 5;
DataBand databand1 = new DataBand();
databand1.Name = "Data1";
databand1.Height = Units.Centimeters * 0.5f;
databand1.DataSource = report.GetDataSource("teac her");
group1.Data = databand1;
TextObject TeacherText = new TextObject();
TeacherText.Name = "TeacherText";
TeacherText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
TeacherText.Text = "[teacher.TeacherName]";
TeacherText.Font = new Font("Tahoma", 11, FontStyle.Bold);
databand1.Objects.Add(Teac herText);
DataBand Databand2 = new DataBand();
Databand2.Name = "Data2";
Databand2.Height = Units.Centimeters * 0.5f;
Databand2.DataSource = report.GetDataSource("pupi l");
TextObject PupilText = new TextObject();
PupilText.Name = "PupilText";
PupilText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
PupilText.Text = "[pupil.Name]";
PupilText.Font = new Font("Tahoma", 10, FontStyle.Regular);
Databand2.Objects.Add(Pupi lText);
databand1.AddChild(Databan d2);
report.Show();
}
The report correctly lists the 3 teacters, but each teacher has all 9 pupils intead of 3.
I have hunted high and low for any documentation on how to create the master-detail relationships using code, but amazingly, there does not seem to be any.
The basic PDF deals only with a simple list, and the downloadable Net documentation is devoid of any guidance at all.
I would be most obliged if someone can assist me with this very fundamental task, so that I can go ahead and buy the software.
Regards
Paul
Search this forum only? More Search Options [X]My Assistant
Loading. Please Wait...
Site Message (Message will auto close in 2 seconds)
Logged in as: BatteryPack ( Log Out )
My Controls · View New Posts · My Assistant · My Friends · 0 New Messages
Fast Reports forum > Fast Reports Products > FastReport 4.0
Master-Detail using Code, How do you create a Master-Detail in code Options Track this topic Email this topic Print this topic Download this topic Subscribe to this forum Display Modes Switch to: Outline Standard Switch to: Linear+
BatteryPack
View Member Profile Add as Friend Send Message Find Member's Topics Find Member's Posts Today, 03:33 AM Post #1
Newbie
Group: Members
Posts: 3
Joined: 14-October 11
Member No.: 54120
Hi all.
I am trying out the demo software, and am most impressed with FastReport.
However, I have run into a fundamental problem for which there seems to be no documentation whatsoever.
I need to generate master-detail reports in code.
My example is a small school consisting of 3 teachers, each having 3 pupils.
All data comes from simple xml, and SQL is not used anywhere.
<?xml version="1.0" encoding="utf-8"?>
<school>
<teacher>
<TeacherName>Thomas</Teach
<pupils>
<pupil>
<Name>Tim</Name>
</pupil>
<pupil>
<Name>Terry</Name>
</pupil>
<pupil>
<Name>Thelia</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Dillman</Teac
<pupils>
<pupil>
<Name>Diggy</Name>
</pupil>
<pupil>
<Name>Derrick</Name>
</pupil>
<pupil>
<Name>Dora</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Fredman</Teac
<pupils>
<pupil>
<Name>Fanny</Name>
</pupil>
<pupil>
<Name>Fern</Name>
</pupil>
<pupil>
<Name>Fenwick</Name>
</pupil>
</pupils>
</teacher>
</school>
I generate a schema which produces a typed dataset.
I proceed as follows.
public partial class Form1 : Form
{
public school School;
public school.teacherDataTable Teachers;
public school.pupilDataTable Pupils;
public Form1()
{
InitializeComponent();
School = new school();
Teachers = new school.teacherDataTable();
Pupils = new school.pupilDataTable();
School.ReadXml(@"c:\Fastre
Teachers.ReadXml(@"c:\Fast
Pupils.ReadXml(@"c:\Fastre
}
I then try to generate a FasReport as follows:
private void btnLoad_Click(object sender, EventArgs e)
{
Report report = new Report();
report.RegisterData(School
report.RegisterData(School
report.RegisterData("pupil
report.GetDataSource("teac
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
report.Pages.Add(page1);
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = Units.Millimeters * 15f;
TextObject SchoolTitleText = new TextObject();
SchoolTitleText.Name = "SchoolTitle";
SchoolTitleText.Bounds = new RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
SchoolTitleText.Text = "NorthDale School";
SchoolTitleText.HorzAlign = HorzAlign.Left;
SchoolTitleText.Font = new Font("Tahoma", 14, FontStyle.Bold);
page1.ReportTitle.Objects.
GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 1;
group1.Condition = "[teacher.TeacherName]";
page1.Bands.Add(group1);
group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Millimeters * 5;
DataBand databand1 = new DataBand();
databand1.Name = "Data1";
databand1.Height = Units.Centimeters * 0.5f;
databand1.DataSource = report.GetDataSource("teac
group1.Data = databand1;
TextObject TeacherText = new TextObject();
TeacherText.Name = "TeacherText";
TeacherText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
TeacherText.Text = "[teacher.TeacherName]";
TeacherText.Font = new Font("Tahoma", 11, FontStyle.Bold);
databand1.Objects.Add(Teac
DataBand Databand2 = new DataBand();
Databand2.Name = "Data2";
Databand2.Height = Units.Centimeters * 0.5f;
Databand2.DataSource = report.GetDataSource("pupi
TextObject PupilText = new TextObject();
PupilText.Name = "PupilText";
PupilText.Bounds = new RectangleF(0, 0, Units.Millimeters * 59, Units.Millimeters * 7f);
PupilText.Text = "[pupil.Name]";
PupilText.Font = new Font("Tahoma", 10, FontStyle.Regular);
Databand2.Objects.Add(Pupi
databand1.AddChild(Databan
report.Show();
}
The report correctly lists the 3 teacters, but each teacher has all 9 pupils intead of 3.
I have hunted high and low for any documentation on how to create the master-detail relationships using code, but amazingly, there does not seem to be any.
The basic PDF deals only with a simple list, and the downloadable Net documentation is devoid of any guidance at all.
I would be most obliged if someone can assist me with this very fundamental task, so that I can go ahead and buy the software.
Regards
Paul
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello mlmcc.
I was not aware that this pdf existed as they have another one they call "programmers guide".
However, when I got hold of the one you mentioned, everything became much clearer, and I now see that I can do without code.
This is a fine piece of software.
Thanks for your help.
Regards
Paul.
I was not aware that this pdf existed as they have another one they call "programmers guide".
However, when I got hold of the one you mentioned, everything became much clearer, and I now see that I can do without code.
This is a fine piece of software.
Thanks for your help.
Regards
Paul.
ASKER
Thanks. Problem solved.
I showed you how to do it in Crystal (which requires no code, just creating the report in the GUI).
When I opened the XML in Crystal it showed 3 tables
Teacher, Pupils, Pupil
Teacher Pupils Pupil
ClassId ClassId PupilId
TeacherName PupilId PupilName
Somewhere you have to link the tables. Crystal uses the link editor and generates SQL to implement the data reading and table linking. I don't know FastReports so I can't say how to do it.
mlmcc