One of the challenges for any enterprise level application is reporting. How do we create reports? How to do we let our users create them without our involvement? How do we deploy them? etc…
These and all other reporting related questions are addressed by suites like XtraReports™. The deployment question is an interesting one. How should we deliver the actual reports? Should we hard-code them into the app? Should we have a special folder for the report files or should we save them into a database? This last option is what I want to show you how to do, using the end-user report designer.
The first thing we will need to do is to create an end-user report designer. I learned how to do this by watching this video.
I have added an extra button “Publish” and when clicked, I want to show a wizard of some sort and submit this report to the database using an OData service end point.
Preparing the Publishing Web Service
A single report will be saved in two tables: the “Report” table and “File” table.
[ResourceSetName("Reports")]
public class Report : XPCustomObject {
Guid _ID;
[Key(AutoGenerate=true)]
public Guid ID {
get { return _ID; }
set {
SetPropertyValue<Guid>("ID", ref _ID, value);
}
}
string _Title;
[Size(256)]
public string Title {
get { return _Title; }
set {
SetPropertyValue<string>("Title", ref _Title, value);
}
}
File _File;
[Association("File-Reports")]
public File File {
get { return _File; }
set {
SetPropertyValue<File>("File", ref _File, value);
}
}
}
[ResourceSetName("Files")]
public class File : XPCustomObject {
Guid _ID;
[Key(AutoGenerate = true)]
public Guid ID {
get { return _ID; }
set {
SetPropertyValue<Guid>("ID", ref _ID, value);
}
}
[Association("File-Reports")]
public XPCollection<Report> Reports {
get {
return GetCollection<Report>("Reports");
}
}
byte[] _Binary;
public byte[] Binary {
get { return _Binary; }
set {
SetPropertyValue<byte[]>("Binary", ref _Binary, value);
}
}
}
and the OData service:
public class List : XpoDataService {
public static void InitializeService(DataServiceConfiguration config) {
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
Publishing the Report
After the OData service is ready, we can submit the report using the Data Service Client Library:
DataServiceContext list = new DataServiceContext(new Uri("http://localhost.:56844/List.svc"));
Reports.Designer.Service.File file = new Reports.Designer.Service.File();
file.Binary = GetReportBinary();
Report report = new Report();
report.Title = title;
list.AddObject("Files", file);
list.AddObject("Reports", report);
list.SetLink(report, "File", file);
list.SaveChanges();
private byte[] GetReportBinary() {
byte[] binary;
using (MemoryStream stream = new MemoryStream()) {
xrDesignPanel1.Report.SaveLayout(stream);
binary = stream.ToArray();
}
return binary;
}
And that’s it! We can now access the reports and the actual report files from anywhere.
http://localhost:56844/List.svc/Reports
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed
xml:base="http://localhost:56844/List.svc/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">Reports</title>
<id>http://localhost:56844/List.svc/Reports</id>
<updated>2010-08-24T23:00:35Z</updated>
<link rel="self" title="Reports" href="Reports" />
<entry>
<id>http://localhost:56844/List.svc/Reports(guid'13378cf1-553e-4fd7-9b5e-bd63eb6106cb')</id>
<title type="text"></title>
<updated>2010-08-24T23:00:35Z</updated>
<author>
<name />
</author>
<link rel="edit" title="Report" href="Reports(guid'13378cf1-553e-4fd7-9b5e-bd63eb6106cb')" />
<link
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File"
type="application/atom+xml;type=entry"
title="File"
href="Reports(guid'13378cf1-553e-4fd7-9b5e-bd63eb6106cb')/File"/>
<category
term="Reports.Web.Report"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">13378cf1-553e-4fd7-9b5e-bd63eb6106cb</d:ID>
<d:Title>Products</d:Title>
</m:properties>
</content>
</entry>
</feed>
http://localhost:56844/List.svc/Reports(guid'13378cf1-553e-4fd7-9b5e-bd63eb6106cb')/File
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<entry
xml:base="http://localhost:56844/List.svc/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<id>http://localhost:56844/List.svc/Files(guid'1b5c8d22-99b3-4c93-b4dd-e2573bf11605')</id>
<title type="text"></title>
<updated>2010-08-24T23:02:10Z</updated>
<author>
<name />
</author>
<link
rel="edit"
title="File"
href="Files(guid'1b5c8d22-99b3-4c93-b4dd-e2573bf11605')"/>
<link
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Reports"
type="application/atom+xml;type=feed"
title="Reports"
href="Files(guid'1b5c8d22-99b3-4c93-b4dd-e2573bf11605')/Reports"/>
<category
term="Reports.Web.File"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">1b5c8d22-99b3-4c93-b4dd-e2573bf11605</d:ID>
<d:Binary m:type="Edm.Binary">Ly8......NCg==</d:Binary>
</m:properties>
</content>
</entry>
We are still missing the Report Viewer piece, so we’ll address this in Part 2.
Cheers
Azret