Sneak Peek Reporting X10: Using Objects As Data Sources
The direct use of enumerable business objects as a data source to merge templates is one of the most commonly requested features of TX Text Control Reporting. In TX Text Control X10, DocumentServer.MailMerge is getting a new method to start the merge process with an IEnumerable object. public void MergeObjects(System.Collections.IEnumerable mergeData); Use IEnumerable Objects As Data Sources MailMerge interprets all public properties of objects in the collection as table columns and child…

The direct use of enumerable business objects as a data source to merge templates is one of the most commonly requested features of TX Text Control Reporting.
In TX Text Control X10, DocumentServer.MailMerge is getting a new method to start the merge process with an IEnumerable object.
public void MergeObjects(System.Collections.IEnumerable mergeData);
Use IEnumerable Objects As Data Sources
MailMerge interprets all public properties of objects in the collection as table columns and child tables. Properties of type IEnumerable are automatically instantiated as relations and are used for merge blocks and nested merge blocks.
Consider the following class structure as a data source:

Below is the C# code that represents the above UML class design:
public class Invoice
{
public List<Product> Products
{
get;
set;
}
public Customer Customer
{
get;
set;
}
}
public class Product
{
public Product(string Name, Decimal Price)
{
this.Name = Name;
this.Price = Price;
}
public string Name
{
get;
set;
}
public Decimal Price
{
get;
set;
}
}
The template consists of a merge block named Products. The merge fields in the block are named Name and Price.

The following code shows how to create the data source object and how to start the merge process using MergeObjects:
Invoice invoice = new Invoice();
invoice.Products = new List<Product>();
invoice.Products.Add(new Product("Apple", 3.55m));
invoice.Products.Add(new Product("Banana", 2.4m));
invoice.Products.Add(new Product("Pineapple", 2.99m));
var invoices = new List<Invoice>();
invoices.Add(invoice);
mailMerge1.MergeObjects(invoices);
New String Formatter
This sample shows another new feature of TX Text Control X10: Merge field string formatter. The field Price is formatted as a currency string with the format $#,###.00 which renders the results with a currency symbol and 2 decimal places:
Input: 2.4m
Output: $2.40

Define the Textual Representation in Your Classes
TX Text Control X10 Reporting allows the textual formatting to be done in your business objects. You can easily override the ToString() method to return a well formatted address block directly from your business object.
Consider a class to represent a Customer:

The following code is the C# implementation of the above class:
public class Customer
{
public Customer(string firstName, string lastName, string address, string phone)
{
FirstName = firstName;
LastName = lastName;
Address = address;
Phone = phone;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public override string ToString()
{
return String.Format("Customer Details:
First Name - {0}
Last Name - {1}
Address - {2}
Phone - {3}", FirstName, LastName, Address, Phone);
}
}
TX Text Control MailMerge calls the ToString() method to get the text from your class which returns a pre-formatted string with carriage returns. The following screenshot shows the results of the above-described new concepts:

These are just some of the great improvements of the upcoming version TX Text Control X10 - stay tuned for more.
Related Posts
TX Text Control 33.0 SP3 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 3 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…
ASP.NETASP.NET CoreDocument Viewer
High-Performance Text Replacement in Large DOCX Files using C# .NET
Learn how to efficiently replace text in large DOCX files using C# .NET and the ServerTextControl component from Text Control. This article demonstrates the performance benefits of using the…
ASP.NETASP.NET CoreDocument Viewer
Document Viewer 33.2.1 Released: New Event and Bug Fixes
This service pack includes important bug fixes and improvements to enhance the stability and performance of the Document Viewer. In addition, a new event has been introduced to provide developers…
ASP.NETAccessibilityASP.NET Core
Upcoming Support for PDF/UA Compliance and Tagged PDF Generation in Version 34.0
We are happy to announce that version 34.0 will support PDF/UA compliance and the creation of tagged PDF documents. This significant update demonstrates our ongoing commitment to accessibility by…
TX Text Control 33.0 SP2 is Now Available: What's New in the Latest Version
TX Text Control 33.0 Service Pack 2 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…