Use Case: Expense report

This demo shows a master-detail report use case with a business object as the data source. The template contains master data (the purpose of the expense report, dates), employee information and the expenses in form of a table (detail information).

Simply Select a report and click on Create report to start the merge process.

Demo

SelectPurposeDate
SelectMicrosoft Conference5/1/2014
SelectSAP Conference5/1/2014
SelectClient Meeting5/1/2014


Reports can be merged into a single document or all reports can be created as separate documents. The MailMerge Reporting engine can be used in all types of .NET based applications including Web Applications, Web Services or Windows Services.

Sources

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

namespace tx_aspnet_samples.Reporting
{
    public partial class expenses : System.Web.UI.Page
    {
        private TXTextControl.DocumentServer.MailMerge mailMerge1;
        private System.ComponentModel.IContainer components;
        private TXTextControl.DocumentServer.DocumentController documentController1;
        private TXTextControl.ServerTextControl serverTextControl2;
        private TXTextControl.ServerTextControl serverTextControl1;

        protected void Button1_Click(object sender, EventArgs e)
        {
            // deserialize XML into business object
            XmlSerializer serializer = new XmlSerializer(typeof(Expenses));
            Expenses expenses = (Expenses)serializer.Deserialize(
                new StreamReader(Server.MapPath("/datasource/expense_report_data.xml")));

            // new object list, only with the selected row
            Expenses copy = new Expenses();
            copy.Add(expenses[GridView1.SelectedIndex]);
            
            // load template
            mailMerge1.LoadTemplate(Server.MapPath("/documents/template_expenses.docx"), 
                TXTextControl.DocumentServer.FileFormat.WordprocessingML);
            
            // merge template with object data
            mailMerge1.MergeObjects(copy);

            // save the resulting document
            byte[] data;
            mailMerge1.SaveDocumentToMemory(out data, 
                TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);

            DocumentViewer1.LoadDocumentFromMemory(data, 
                TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            InitializeComponent();

            DocumentViewer1.DocumentController = documentController1;

            // deserialize XML into business object
            XmlSerializer serializer = new XmlSerializer(typeof(Expenses));
            Expenses expenses = (Expenses)serializer.Deserialize(
                new StreamReader(Server.MapPath("/datasource/expense_report_data.xml")));
            
            GridView1.DataSource = expenses;
            GridView1.DataBind();
        }
    }
}

Mail Merge - Reporting