FACS Statement with Export Per Client
Trouble seeing the images? Right click on images and open in new tab to enlarge or zoom in on the page (Ctrl + mousewheel).
In this article we discuss the steps to leverage a script that will set up the FACS STATEMENT to be exported to a single file per client.
What is the FACS Statement with Export Per Client?
The FACS STATEMENT with Export Per Client view will export each client to its own PDF file.
Video Tutorial:
Not Yet Available.
Steps to Create a FACS Statement with Export Per Client
Download FACSStatement_ClientExport.vdm report file attached to the bottom of this article.
1. Open VDM.
2. Open your View.
3. Enter the Finished Report designer.
4. Click on Script and paste the following script into the text area.
Script:
// Importing a generic collection namespace which contains interfaces and classes that define generic collections.
using System.Collections.Generic;
// Initializing a list of strings to store client identifiers.
List<string> Clients = new List<string>();
// Initializing a list of integers to store page numbers where a client's report ends.
List<int> PageEnds = new List<int>();
// Declaring an integer to keep track of the current page number.
int CurrentPageNumber = 0;
// A boolean flag to check if the previous page contained a client total.
bool PrevPageTotal = false;
// A string to keep track of the client number from the previous page.
string PrevPageClientNum = "";
// This method is triggered before the 'label42' control is printed on the report.
private void label42_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
if((string)GetCurrentColumnValue("Detail") == "Client Total")
{
// If the current detail column's value is "Client Total", it sets the flag 'PrevPageTotal' to true
// and stores the current client number in 'PrevPageClientNum'.
PrevPageTotal = true;
PrevPageClientNum = (string)GetCurrentColumnValue("YourNum");
}
}
// This method is triggered before the 'label16' control is printed on the report.
private void label16_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
// If the previous page was a total page and the current client number is different from the previous,
// it adds the previous client number and the current page number to their respective lists.
if(PrevPageTotal && (string)GetCurrentColumnValue("YourNum") != PrevPageClientNum)
{
Clients.Add(PrevPageClientNum);
PageEnds.Add(CurrentPageNumber);
}
// Resets the 'PrevPageTotal' flag and the 'PrevPageClientNum' string for the next page.
PrevPageTotal = false;
PrevPageClientNum = "";
// Increments the current page number for the next iteration.
CurrentPageNumber += 1;
}
// This method is triggered after the report has been printed.
private void XtraReport_AfterPrint(object sender, System.EventArgs e) {
int CurPage = 1;
// Casting the Report object to a specific report type 'XtraReport'.
XtraReport r = (XtraReport)Report;
// Manually add the last client and the total pages if it wasn't added in the previous steps
if (PrevPageTotal && !string.IsNullOrEmpty(PrevPageClientNum))
{
Clients.Add(PrevPageClientNum);
PageEnds.Add(CurrentPageNumber);
}
// Looping through each client in the list.
for (int i = 0; i <= Clients.Count - 1; i++)
{
// If it's the first client, the current page is set to 1, else it is set to the end page of the previous client plus one.
if (i == 0)
{
CurPage = 1;
}
else
{
CurPage = PageEnds[i-1] + 1;
}
// Get the current date and format it as a string.
string currentDate = DateTime.Now.ToString("yyyyMMdd");
// Include the current date in the PDF filename.
string Filename = @"C:\Temp\" + Clients[i] + "_" + currentDate + ".pdf";
// Set up the PDF export options, specifying the page range for the current client.
PdfExportOptions pdfOptions = r.ExportOptions.Pdf;
pdfOptions.PageRange = CurPage + "-" + PageEnds[i];
// Export the specified page range of the report to a PDF file for the current client.
r.ExportToPdf(Filename, pdfOptions);
}
}
5. Set the Before Print script on label 42 and label 16 to the corresponding event from the script.
Label 42 uses label42_BeforePrint
Label 16 uses label16_BeforePrint
6. Set the After Print script on the XtraReport to XtraReport_AfterPrint
7. Preview the results and check the specified file path in the script (Default: C:\temp)
Comments
0 comments
Please sign in to leave a comment.