Integrating reporting functionality into applications is a very easy task using TX Text Control. The out-of-the-box ribbon tab "Reporting" provides all required features to add merge fields, repeating blocks and special fields.
The TXText
╰ DocumentServer.DataSources Namespace
╰ DataSourceManager Class
The DataSourceManager class is designed for handling all existing kinds of data sources which can be used together with the MailMerge class. is designed for handling all existing kinds of data sources that can be used with the TXText
╰ DocumentServer Namespace
╰ MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services. .
After creating an application that uses the ribbon interface and the pre-designed ribbon tabs, your form should look similar to this:
The ribbon tab TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonReportingTab Class
The RibbonReportingTab class represents a Windows Forms ribbon tab to integrate mail merge and reporting functionality. has the TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonReportingTab Class
╰ DataSourceManager Property
Provides the DataSourceManager that is connected with the RibbonReportingTab. which returns the connected DataSourceManager.
The DataSourceManager object provides methods to load data from various sources:
- LoadAssembly
- LoadDataSet
- LoadDataTable
- LoadJson
- LoadObjects
- LoadSingleObject
- LoadXmlFile
- LoadXmlString
Consider the following classes that should be used as a data source:
public class Report | |
{ | |
public string Name { get; set; } | |
public List<Sale> Sales { get; set; } = new List<Sale>(); | |
} | |
public class Sale | |
{ | |
public Customer Customer { get; set; } | |
public Product Product { get; set; } | |
} | |
public class Product | |
{ | |
public string Name { get; set; } | |
public decimal Price { get; set; } | |
} | |
public class Customer | |
{ | |
public string Name { get; set; } | |
public int Id { get; set; } | |
public string Street { get; set; } | |
public string City { get; set; } | |
public int Zip { get; set; } | |
} |
The following code creates a new object and loads it into the DataSourceManager using the TXText
╰ DocumentServer.DataSources Namespace
╰ DataSourceManager Class
╰ LoadSingle Method
Loads a single object which is either a Dictionary with string keys or an object of an arbitrary type as a data source. .
Report report = new Report() { Name = "Test Report 2018" }; | |
report.Sales.Add(new Sale() | |
{ | |
Customer = new Customer() | |
{ | |
Name = "Customer 1", | |
City = "Charlotte", | |
Id = 1, | |
Street = "6672 Test Street", | |
Zip = 27781 | |
}, | |
Product = new Product() | |
{ | |
Name = "My Product 1", | |
Price = 7782.12m | |
} | |
}); | |
DataSourceManager dsManager = ribbonReportingTab1.DataSourceManager; | |
dsManager.LoadSingleObject(report); |
The drop-downs to insert merge fields and repeating merge blocks are filled automatically with the available values.
The DataSourceManager provides the TXText
╰ DocumentServer.DataSources Namespace
╰ DataSourceManager Class
╰ Merge Method
Merges a binary TX internal unicode format document with the currently loaded data source. to merge a template with the current data to implement a preview functionality. The following code saves the template in a byte array, merges the template with data and loads back the resulting document into the TX Text Control:
// save the document | |
byte[] bDocument = null; | |
textControl1.Save(out bDocument, TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
// create the preview | |
IList<byte[]> bResults = ribbonReportingTab1.DataSourceManager.Merge(bDocument, 1, textControl1); | |
// load the preview into the Text Control | |
textControl1.Load(bResults[0], TXTextControl.BinaryStreamType.InternalUnicodeFormat); |