This example shows how to create a simple report in Runtime. Let's create the report with the header, data, totals and show it in the viewer. First, create a new report and add data source to the dictionary:
private void button1_Click(object sender, System.EventArgs e)
{
StiReport report = new StiReport();
// Add data to datastore
report.RegData(dataSet1);
// Fill dictionary
report.Dictionary.Synchronize();
StiPage page = report.Pages[0];
...
Add a Header Band with Text Boxes and assign data titles to them:
...
// Create HeaderBand
StiHeaderBand headerBand = new StiHeaderBand();
headerBand.Height = 0.5;
headerBand.Name = "HeaderBand";
page.Components.Add(headerBand);
// Create text on header
StiText headerText = new StiText(new RectangleD(0, 0, 5, 0.5));
headerText.Text = "CompanyName";
headerText.HorAlignment = StiTextHorAlignment.Center;
headerText.Name = "HeaderText";
headerText.Brush = new StiSolidBrush(Color.LightGreen);
headerBand.Components.Add(headerText);
...
Next, add a Data Band with Text Boxes, which contain references to the data fields:
...
// Create Databand
StiDataBand dataBand = new StiDataBand();
dataBand.DataSourceName = "Customers";
dataBand.Height = 0.5;
dataBand.Name = "DataBand";
page.Components.Add(dataBand);
// Create text
StiText dataText = new StiText(new RectangleD(0, 0, 5, 0.5));
dataText.Text = "{Line}.{Customers.CompanyName}";
dataText.Name = "DataText";
dataBand.Components.Add(dataText);
...
Next, add a Footer Band with Text Box, which contain a function of data totals:
...
// Create FooterBand
StiFooterBand footerBand = new StiFooterBand();
footerBand.Height = 0.5;
footerBand.Name = "FooterBand";
page.Components.Add(footerBand);
// Create text on footer
StiText footerText = new StiText(new RectangleD(0, 0, 5, 0.5));
footerText.Text = "Count - {Count()}";
footerText.HorAlignment = StiTextHorAlignment.Right;
footerText.Name = "FooterText";
footerText.Brush = new StiSolidBrush(Color.LightGreen);
footerBand.Components.Add(footerText);
...
In the end, show a report in the viewer:
...
report.Show();
}
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: