Master-Detail using Code
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</TeacherName>
<pupils>
<pupil>
<Name>Tim</Name>
</pupil>
<pupil>
<Name>Terry</Name>
</pupil>
<pupil>
<Name>Thelia</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Dillman</TeacherName>
<pupils>
<pupil>
<Name>Diggy</Name>
</pupil>
<pupil>
<Name>Derrick</Name>
</pupil>
<pupil>
<Name>Dora</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Fredman</TeacherName>
<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:\FastreportStudy2\Data\School41.xml);
Teachers.ReadXml(@c:\FastreportStudy2\Data\School41.xml);
Pupils.ReadXml(@c:\FastreportStudy2\Data\School41.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["teacher"], "teacher");
report.RegisterData("pupil", "relationteacher_pupils");
report.GetDataSource("teacher").Enabled = 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(SchoolTitleText);
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("teacher");
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(TeacherText);
DataBand Databand2 = new DataBand();
Databand2.Name = "Data2";
Databand2.Height = Units.Centimeters * 0.5f;
Databand2.DataSource = report.GetDataSource("pupil");
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(PupilText);
databand1.AddChild(Databand2);
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
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</TeacherName>
<pupils>
<pupil>
<Name>Tim</Name>
</pupil>
<pupil>
<Name>Terry</Name>
</pupil>
<pupil>
<Name>Thelia</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Dillman</TeacherName>
<pupils>
<pupil>
<Name>Diggy</Name>
</pupil>
<pupil>
<Name>Derrick</Name>
</pupil>
<pupil>
<Name>Dora</Name>
</pupil>
</pupils>
</teacher>
<teacher>
<TeacherName>Fredman</TeacherName>
<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:\FastreportStudy2\Data\School41.xml);
Teachers.ReadXml(@c:\FastreportStudy2\Data\School41.xml);
Pupils.ReadXml(@c:\FastreportStudy2\Data\School41.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["teacher"], "teacher");
report.RegisterData("pupil", "relationteacher_pupils");
report.GetDataSource("teacher").Enabled = 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(SchoolTitleText);
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("teacher");
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(TeacherText);
DataBand Databand2 = new DataBand();
Databand2.Name = "Data2";
Databand2.Height = Units.Centimeters * 0.5f;
Databand2.DataSource = report.GetDataSource("pupil");
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(PupilText);
databand1.AddChild(Databand2);
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
Comments
Could you please send me the project code to tz@fast-report.com?