TX Text Control Blog

MailMerge: Using smart business objects to calculate batch totals and subtotals

Björn Meyer

Blogged by Björn Meyer on April 21, 2017 and tagged with reporting, business objects, merge blocks.

Text Control's MailMerge class supports IEnumerable objects, DataSets, DataTables and Json as data sources for mail merge processes. A smart advantage of business objects is that a specific logic can be implemented into these classes. Consider the following business object:

MailMerge: Using smart business objects to calculate batch totals and subtotals

Order is the main object or Master Table for the mail merge process. It consists of Customer information, a Total and a collection of ProductBlocks. The ProductBlock class contains the sum of prices of all contained Products.

If a new list of products is added to the ProductBlock object, the BlockSum field is calculated automatically. Therefore, the total sum of a ProductBlock object is always accurate and must not be set manually.

The main object Order implements the INotifyPropertyChanged interface which is used to update the ObservableCollection of ProductBlocks. Each time, a new ProductBlock is added, the Total is calculated.

The following screenshot shows a sample template with a nested merge block. The outer block is ProductBlocks that contains a child block called Products. As Products is a list member of the object ProductBlock, it can be repeated in a separate nested block.


The following code shows the creation of a data object and how to call the MergeObject method to start the merge process:

After merging the template, the ProductBlocks are repeated and the block sum is rendered at the end of each block. At the very end, the total sum is shown which has been calculated automatically inside the business object.

Merge results
Call us: +1 704-544-7445 (United States)





Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2015 Launch PartnerVisual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner