Page 1 of 1
Dynamic reports with business objects
Posted: Thu Nov 22, 2012 8:59 am
by tpontow
Hello,
are there any existing samples regarding dynamic report creation using business objects?
Not alone i need to create components (StiText controls) at runtime and place them in HeaderBand and DataBand i also need to create the DataColumns of my business object. Are there any best practices for that scenario?
Thanks
Thorsten Pontow
Re: Dynamic reports with business objects
Posted: Fri Nov 23, 2012 9:27 am
by Alex K.
Hello,
Please check the following code:
Code: Select all
StiReport report = new StiReport();
StiPage page = report.Pages[0];
DataSet ds = new DataSet("Demo");
ds.ReadXmlSchema("d:\\Demo.xsd");
ds.ReadXml("d:\\Demo.xml");
DataTable dt = new DataTable("Categories");
dt = ds.Tables["Categories"];
report.RegBusinessObject("Demo", ds);
report.Dictionary.SynchronizeBusinessObjects(3);
//Create TitleBand
StiHeaderBand TitleBand = new StiHeaderBand();
TitleBand.Height = 0.85;
TitleBand.Name = "TitleBand";
page.Components.Add(TitleBand);
//Create Title text on header
StiText headerText = new StiText(new RectangleD(0, 0, page.Width, 0.85));
headerText.Text = "Tacticdescription";
headerText.HorAlignment = StiTextHorAlignment.Left;
headerText.Name = "TitleHeader";
headerText.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold);
TitleBand.Components.Add(headerText);
//Create HeaderBand
StiHeaderBand headerBand = new StiHeaderBand();
headerBand.Height = 0.5;
headerBand.Name = "HeaderBand";
page.Components.Add(headerBand);
//Create Databand
StiDataBand dataBand = new StiDataBand();
dataBand.BusinessObjectGuid = report.Dictionary.BusinessObjects["Demo"].BusinessObjects["Categories"].Guid;
dataBand.Height = 0.5;
dataBand.Name = "DataBand";
page.Components.Add(dataBand);
double pos = 0;
double columnWidth = page.Width / dt.Columns.Count;
int nameIndex = 1;
foreach (DataColumn dataColumn in dt.Columns)
{
StiText hText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
hText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
hText.Text.Value = dataColumn.Caption;
hText.HorAlignment = StiTextHorAlignment.Center;
hText.Name = "HeaderText" + nameIndex.ToString();
hText.Brush = new StiSolidBrush(Color.Orange);
hText.Border.Side = StiBorderSides.All;
headerBand.Components.Add(hText);
StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
dataText.Text = "{Demo.Categories." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(dataColumn.ColumnName) + "}";
dataText.Name = "DataText" + nameIndex.ToString();
dataText.Border.Side = StiBorderSides.All;
dataBand.Components.Add(dataText);
pos = pos + columnWidth;
nameIndex++;
}
report.Compile();
report.Show();
Thank you.
Re: Dynamic reports with business objects
Posted: Mon Nov 26, 2012 12:26 pm
by tpontow
That helped me a lot!
Thank you.
Thorsten Pontow
Re: Dynamic reports with business objects
Posted: Mon Nov 26, 2012 12:30 pm
by Alex K.
Hello,
We are always glad to help you!
Let us know if you need any additional help.
Thank you.