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.

Loading...
Loading...

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.

Loading...
Loading...

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.

Template

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

Loading...

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