Building Report Template in Code

Stimulsoft Reports.Silverlight discussion
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Building Report Template in Code

Post by jasond-s »

Hello.

Is there any way to build a Report Template in code behind in the silverlight client or the rest of the .NET pack?

I have a requirement to create the output of the report designer, in the code behind and was wondering if this was possible?


Many thanks.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Building Report Template in Code

Post by Alex K. »

Hello,

Please check the sample project in attachment.

Thank you.
Attachments
DynamicCreateReport.zip
(15.46 KiB) Downloaded 508 times
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Re: Building Report Template in Code

Post by jasond-s »

This sample won't work without the data schema, marked in code as "e:\\Demo.xsd" and, I assume, the data as "e:\\Demo.xml".

But I understand that principles, thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Building Report Template in Code

Post by Alex K. »

Hello,

Ok.
Let us know if you need any additional help.

Thank you.
Attachments
Demo.zip
(479.77 KiB) Downloaded 475 times
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Re: Building Report Template in Code

Post by jasond-s »

Ok this is what I have. When I load it up in the Silverlight app, the designer looks correct, all the bands and expressions are there. But the preview shows only a single line of empty borders? Also when I go into the designer the databand has no datasourse assigned and there are none in the dialog when I double click this band?


private async void TreeViewSelectionChangedCommandExecute(ReportItem item)
{
var report = item as Report;

if (report == null || WebServiceAgent == null)
return;

var result = await WebServiceAgent.RetrieveReportAsync(report);

if (result == null)
return;

var reportData = result.ReportData;
var set = new DataSet();
set.Load(reportData);

var stireport = new StiReport();
stireport.RegBusinessObject("DataSet", set);
//stireport.Dictionary.Synchronize();

StiPage page = stireport.Pages[0];

var headerBand = new StiHeaderBand
{
Height = 0.5,
Name = "HeaderBand"
};
page.Components.Add(headerBand);

StiGroupHeaderBand group = new StiGroupHeaderBand();
group.Condition = new StiGroupConditionExpression("{ DataSet[Surname] }");
page.Components.Add(group);

var dataBand = new StiDataBand
{
DataSourceName = "DataSet",
Height = 0.5,
Name = "DataBand",
};
page.Components.Add(dataBand);


double pos = 0;
double columnWidth = page.Width / set.Tables[0].Columns.Count;
int nameIndex = 1;

foreach (DataColumn dataColumn in set.Tables[0].Columns)
{
//Create text on header
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.ColumnName;
hText.HorAlignment = StiTextHorAlignment.Center;
hText.Name = "HeaderText" + nameIndex.ToString();
hText.Brush = new StiSolidBrush(Colors.Orange);
hText.Border.Side = StiBorderSides.All;
headerBand.Components.Add(hText);

StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));

dataText.Text = "{ DataSet." + dataColumn.ColumnName + " }";
dataText.Name = "DataText" + nameIndex.ToString();
dataText.Border.Side = StiBorderSides.All;

dataBand.Components.Add(dataText);
pos = pos + columnWidth;
nameIndex++;
}

if (Render != null)
{
Render(stireport);
}
}
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Re: Building Report Template in Code

Post by jasond-s »

Sorry forgot one thing.... This is what the render method looks like.

viewModel.Render = r =>
{
var service = StiConfig.GetServices(StiLoadServiceType.StiSLPanelService).OfType<StiSLDictionaryPanelService>().FirstOrDefault();

if (service != null)
{
service.SetDictionaryDelete(false);
service.ShowActionsButton = false;
service.ShowBusinessObjectNewFromDataSetMenuItem = false;
service.ShowBusinessObjectNewMenuItem = false;
service.ShowCategoryNewMenuItem = false;
service.ShowColumnNewMenuItem = false;
service.ShowDeleteButton = false;
service.ShowDeleteForDataSource = false;
service.ShowDeleteForBusinessObject = false;
service.ShowDeleteForDataConnection = false;
service.ShowDeleteMenuItem = false;
}

foreach (var trigger in r.Pages.OfType<StiPage>())
{
var band = trigger.Components.OfType<StiDataBand>().FirstOrDefault();

if (band == null)
continue;
}

r.Render();

StiReportViewer.Report = r;
StiReportDesigner.Report = r;
};
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Building Report Template in Code

Post by HighAley »

Hello.

If you use Business objects instead of Data Sources, you should set the BusinessObjectGuid property of the data band but not the DataSourceName.

Thank you.
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Re: Building Report Template in Code

Post by jasond-s »

Does the business object 'Name' then have to be a GUID and is the same as the 'BusinessObjectGuid' value passed to the 'StiDataBand'? There is no property or constructor of the 'StiBusinessObjectData' that takes a GUID that I can find.

With the 'StiDataBand.BusinessObjectGuid = "DataSet"' matching the 'StiReport.RegBusinessObject("DataSet", set)' still fails. The business object is visible in the desinger, but the DataBand states, 'No Data Source'.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Building Report Template in Code

Post by HighAley »

Hello.

You should change your code to the next one.

Code: Select all

stireport.RegBusinessObject("DataSet", set);
stireport.Dictionary.SynchronizeBusinessObjects(3);

...

var dataBand = new StiDataBand
{
BusinessObjectGuid = stireport.Dictionary.BusinessObjects["DataSet"].Guid,
Height = 0.5,
Name = "DataBand",
};
Thank you.
jasond-s
Posts: 6
Joined: Mon Mar 18, 2013 11:58 am

Re: Building Report Template in Code

Post by jasond-s »

This seems to have helped. The dataset is now visible in the BusinessObjects collection, but the report will not populate with data until I select the DataTable and not the DataSet from the business object list in the designer. I don't want to have to open up the designer really and want the DataTable to be bound to the DataBand and so populate with the data.
Locked