Dynamic reports with business objects

Stimulsoft Ultimate discussion
Post Reply
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Dynamic reports with business objects

Post 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
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Dynamic reports with business objects

Post 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.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Dynamic reports with business objects

Post by tpontow »

That helped me a lot!

Thank you.

Thorsten Pontow
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Dynamic reports with business objects

Post by Alex K. »

Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.
Post Reply