Dynamically add Sti components/elements to existing report

Stimulsoft Reports.NET discussion
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

Hi,

I have a small report, designed and saved as .dll.
It contains some static text fields in the PageHeaderBand.

I am loading this report as below:

Code: Select all

StiReport report;
string strReportPath = "d:\myreport.dll";
report = StiReport.GetReportFromAssembly(strReportPath);
After loading it like above, I am trying to add a table and populate it based on some data retreived from DB.
Also I am trying to add simple StiText.

The problem is that the StiText, never gets populated with the value I am setting ( I am trying with this text just for testing).
On the other hand, the table shows the correct number of columns and rows, but all cells are empty.

Is it possible to achive this scenario? Meaning to dynamically add a table to an existing report.

More code from my project:

Code: Select all

                               DataTable tblDR = GetData(dtStartTimeStamp);
                               tblDR.TableName = "tblDR";
                               report.RegData(tblDR);

                               report.RegData(tblDR);
                               report.Dictionary.Synchronize();

                                StiPage page = report.Pages[0];

                                StiTable table = new StiTable();
                                table.Name = "Table1";

                                table.ColumnCount = tblDR.Columns.Count;
                                table.RowCount = 3;
                                table.HeaderRowsCount = 1;
                                table.FooterRowsCount = 1;
                                table.Width = page.Width;
                                table.Height = page.GridSize * 12;
                                table.DataSourceName = String.Format("{0}", tblDR.TableName);

                                page.Components.Add(table);

                                table.CreateCell();
                                table.TableStyle = StiTableStyle.Style12;

                                int indexHeaderCell = 0;
                                int indexDataCell = 3;

                                foreach (DataColumn column in tblDR.Columns)
                                {
                                    //Set text on header
                                    StiTableCell headerCell = table.Components[indexHeaderCell] as StiTableCell;
                                    headerCell.Text.Value = column.Caption;
                                    headerCell.HorAlignment = StiTextHorAlignment.Center;
                                    headerCell.VertAlignment = StiVertAlignment.Center;

                                    StiTableCell dataCell = table.Components[indexDataCell] as StiTableCell;
                                    string sDataCellExpresion = String.Format("{{{0}.{1}}}", tblDR.TableName, Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName));
                                    dataCell.Text.Value = sDataCellExpresion;


                                    indexHeaderCell++;
                                    indexDataCell++;
                                }

Can some one plese let me know what I am missing.
Why the table is not getting populated with data?

I gave to mention, that this report is to tbe displayed in StiWebReportViewer

Code: Select all

StiWebViewer1.Report = report;
StiWebViewer1.DataBind();
Thank you!
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

Just finished some more tests.
It seems that if the report is created like below some data appears:

Code: Select all

report = new StiReport();
Is there a problem with loading an existing report (with few design elements already in place, like a logo, timestamp and a report name header)?
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

After more trial & error attempts here are some more findings:

1. If the report is compiled into a .dll, it seems that there is no way to show to dynamic table.
I tried to call report.Compile() after dynamically adding controls, but it throws an "already compiled error".

2. If the report is loaded using code below, there are some signs of data coming in

Code: Select all

StiReport report = new StiReport();
strReportPath = Server.MapPath("myreport_v02.mrt");
report.Load(strReportPath);
The only thing is that there is some additional work required to pass parameters to the report and to report's dataSources:

Code: Select all

report.Compile();

report.CompiledReport["ReportDay"] = DateTime.Now;

report.CompiledReport.DataSources["src1"].Parameters["@param1"].ParameterValue = param1Val;
NOTE: CompiledReport

Maybe this is documented some place, but I was not able to find this information.

Now, all I have to do, is to figure out the structure of the StiTable in order to show the data in the correct cell.

At this point, there seems to be no match between the datatable and the StiTable.
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

Can anyone tell how to correctly pupulate the StiTable with the data from a DataTabel in the code snipped below:

Code: Select all

DataTable tblDR = GetData(dtStartTimeStamp);
                               tblDR.TableName = "tblDR";
                               report.RegData(tblDR);

                               report.RegData(tblDR);
                               report.Dictionary.Synchronize();

                                StiPage page = report.Pages[0];

                                StiTable table = new StiTable();
                                table.Name = "Table1";

                                table.ColumnCount = tblDR.Columns.Count;
                                table.RowCount = 3;
                                table.HeaderRowsCount = 1;
                                table.FooterRowsCount = 1;
                                table.Width = page.Width;
                                table.Height = page.GridSize * 12;
                                table.DataSourceName = String.Format("{0}", tblDR.TableName);

                                page.Components.Add(table);

                                table.CreateCell();
                                table.TableStyle = StiTableStyle.Style12;

                                int indexHeaderCell = 0;
                                int indexDataCell = 3;

                                foreach (DataColumn column in tblDR.Columns)
                                {
                                    //Set text on header
                                    StiTableCell headerCell = table.Components[indexHeaderCell] as StiTableCell;
                                    headerCell.Text.Value = column.Caption;
                                    headerCell.HorAlignment = StiTextHorAlignment.Center;
                                    headerCell.VertAlignment = StiVertAlignment.Center;

                                    StiTableCell dataCell = table.Components[indexDataCell] as StiTableCell;
                                    string sDataCellExpresion = String.Format("{{{0}.{1}}}", tblDR.TableName, Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName));
                                    dataCell.Text.Value = sDataCellExpresion;


                                    indexHeaderCell++;
                                    indexDataCell++;
                                }
The first column of the DataTable tblDR is DateTime.
The rest of the columns are decimal numbers with 2 decimal places.

Can anyone plese let me know what is the correct way to Data Bind the StiTable to the DataTable returned from Database?

(the code snipped above was found on this forum also)
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

In order to properly populate the StiTable, the line

Code: Select all

int indexDataCell = 3;
should be

Code: Select all

int indexDataCell = tblDR.Columns.Count;
DataCells are the next in Components collection of the table, right after the header cells.

So there are tblDR.Columns.Count header cells, followed by tblDR.Columns.Count data cells.
StiTable settings:

Code: Select all

table.ColumnCount = tblDR.Columns.Count;
table.RowCount = 2;
table.HeaderRowsCount = 1;
table.FooterRowsCount = 0;
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Dynamically add Sti components/elements to existing report

Post by Alex K. »

Hello,

Could you please clarify what problems do you have on the current moment. And if they are, please kindly send us a sample project for analysis.

Thank you.
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

I had a problem (the one describe in the first post), but after some more trial and error attempts I managed to solve it.
Just posted my findings just in case other users are facing the same issue.

There is ome more question related to this:

How many footer rows can be added dynamically?

I have a DataTable with 6 rows of data and I need to add 1 HeaderRow and 6 Footer Rows for different aggregates (Min, Max, Avg, Sum).
The maximum footer rows I was able to add was:

Code: Select all

                            table.ColumnCount = tblDR.Columns.Count;
                            table.RowCount = 6;
                            table.HeaderRowsCount = 1;
                            table.FooterRowsCount = 4;
If I am trying to add one moreextra footer row like below, the report is not rendered correctly:

Code: Select all

                            table.ColumnCount = tblDR.Columns.Count;
                            table.RowCount = 7;
                            table.HeaderRowsCount = 1;
                            table.FooterRowsCount = 5;
Can you please let me know how many footer rows can be added?
mmmmmm
Posts: 27
Joined: Mon Oct 24, 2011 5:51 am

Dynamically add Sti components/elements to existing report

Post by mmmmmm »

Hello,

can anyone please advice on the FooterRows issue in the previous post, please?

thank you
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Dynamically add Sti components/elements to existing report

Post by Alex K. »

Hello,

Theoretically, if we understand you correct, then any number of footers.

Thank you.
mihiri1
Posts: 12
Joined: Tue May 15, 2012 3:00 am
Location: Brisbane, QLD

Set Stretch to Print Are

Post by mihiri1 »

Hi,

I have a A3 Stimulsoft Report, Run the report and print to A3 paper, I get a nice report. but if I print it to A4 size paper, then some parts of the report gets cut off(only half of the report is visible on A4))
Then I tried setting Stretch to Print Area= True, this makes the report print fine to A3, but on A4 I see even though the columns are reduced in size, the font sizes still look the same. This results in some numbers and letters getting cut off from most of the columns.

What does the Stretch to Print Area really does?
How can I solve this issue?

Thanks
Post Reply