How to create a report template dynamically

In order to create the report template dynamically you need to override the ReportService function as in the example below. The creation and editing of the template happens through the object model of a document:

protected override PerpetuumSoft.Reporting.DOM.Document 
RenderCore(IDictionary<string, object> parameters, string reportName)
{
  Document doc = inlineReportSlot.LoadReport();

  doc.Pages.Clear();
  doc.ScriptLanguage = ScriptLanguage.CSharp;
  
  Page page = new Page();
  doc.Pages.Add(page);
  
  Detail detail = new Detail();
  detail.Location = new PerpetuumSoft.Framework.Drawing.Vector(0, 0);
  detail.Size = new PerpetuumSoft.Framework.Drawing.Vector(5.5f, 3f).
ConvertUnits(Unit.Centimeter, Unit.InternalUnit);
  page.Controls.Add(detail);
  
  TextBox textBox = new TextBox();
  detail.Controls.Add(textBox);
  
  textBox.Location = new PerpetuumSoft.Framework.Drawing.Vector(page.
Margins.Left, 0);
  textBox.Size = new PerpetuumSoft.Framework.Drawing.Vector(page.Size.
Width - page.Margins.Right - page.Margins.Left, Unit.Convert(2.5f, 
Unit.Centimeter, Unit.InternalUnit));
  textBox.Text = "Dynamic Text Box";
  textBox.Fill = new PerpetuumSoft.Framework.Drawing.SolidFill(System.
Drawing.Color.LightBlue);
  textBox.Border = new PerpetuumSoft.Framework.Drawing.Border(new 
PerpetuumSoft.Framework.Drawing.BorderLine(PerpetuumSoft.Framework.
Drawing.LineStyle.Dash, System.Drawing.Color.Red, 2f));

  // Creating dataBand with 3 rows
  DataBand dataBand = new DataBand();
  page.Controls.Add(dataBand);
  dataBand.Name = "dataBand";
  dataBand.Location = new PerpetuumSoft.Framework.Drawing.Vector(0,
5.5f).ConvertUnits(Unit.Centimeter, Unit.InternalUnit);
  dataBand.InstanceCount = 3;

  detail = new Detail();
  dataBand.Controls.Add(detail);
  detail.Location = new PerpetuumSoft.Framework.Drawing.Vector(0, 0);
  detail.Size = new PerpetuumSoft.Framework.Drawing.Vector(5.5f, 1f).
ConvertUnits(Unit.Centimeter, Unit.InternalUnit);
  
  textBox = new PerpetuumSoft.Reporting.DOM.TextBox();
  textBox.Name = "textBox2";
  detail.Controls.Add(textBox);
  textBox.Location = new PerpetuumSoft.Framework.Drawing.Vector(1.5f,
0f).ConvertUnits(Unit.Centimeter, Unit.InternalUnit);
  textBox.Size = new PerpetuumSoft.Framework.Drawing.Vector(5.5f, 1f).
ConvertUnits(Unit.Centimeter, Unit.InternalUnit);
  // Binding
  textBox.DataBindings.Add(new ReportDataBinding("Value", 
"\"Line #\"+dataBand.LineNumber.ToString()"));
  textBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  
  inlineReportSlot.SaveReport(doc);
  return base.RenderCore(parameters, "rsToRender");
}

In this example, the ReportManager has the inlineReportSlot with ReportName = "rsToRender".

Add Feedback