Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Designing Sales Delivery Notes with Blank Row Filling Using FastReport: A Guide with A4 Template

Tech 2

This guide demonstrates how to design a sales delivery note print template that automatically fills blank rows to maintain a consistent table height on each page, using the FastReport designer.

Overview of the Blank Row Filling Template

Template Preview:



We will use a Sales Delivery Note as an example.

Step-by-Step Configuration

1. Identify the Document ID

  1. Create a new Sales Delivery Note in your system.

  2. Return to the list view and edit the newly created document.

  3. Note the document ID displayed at the top of the form.


2. Duplicate and Prepare the Print Template

  1. Navigate to Configuration > Report Templates.

  2. Find the sales delivery note print template you wish to modify.

  3. Duplicate the template and open the duplicate for editing.

  4. In the template details, locate the data parameter settings and note the current ID parameter (you will update this later).


3. Launch the Report Designer

  1. Ensure the FastReport service is running.

  2. From the report template list, click "Design Template" for your duplicated template.


4. Initial Designer View

Upon entering, you will see the default template layout.


5. Reorganize Report Bands

5.1. Add Necessary Bands

  1. Click the Settings (gear icon) in the top-left corner.

  2. Add a Page Header band and a second Data band.


The interface after adding bands:


5.2. Move Content and Clean Up

  1. Move the content from the "Report Title" band and the first row from the original "Data" band in to the new Page Header band.

  2. Delete the now-empty "Report Title" and the original "Data Header" bands.


5.3. Identify Data Bands

You will now have two main data bands:

  • The upper band (Data1) will contain the actual transaction lines.

  • The lower band (Data2) will be used for filling blank rows. Click on the yellow area of each band to see its name selected in the Report Tree on the right.


5.4. Configure the Blank Row Band (Data2)

  1. Copy the table structure (cells, borders) from Data1 and paste it into Data2.

  2. Clear all data bindings and text from the cells in Data2. This band should contain only the empty table structure.


5.5. Move Foooter Content

  1. Move the content from the "Report Summary" band (like totals) into the Page Footer band.

  2. Delete the empty "Report Summary" band.


6. Add the Automation Script

  1. Switch to the Code view by clicking the button at the bottom-left of the designer.

  2. The default code structure will be visible.


6.1. Insert the Custom Code

Add the following code block inside the ReportScript class. The exact line may vary, but it should be placed with other event hendlers.

// --- BEGIN INSERTED CODE ---
int maxRowsPerPage = 16; // Maximum data rows to display per page

private void Page1_StartPage(object sender, EventArgs e)
{
    int actualDataRowCount = Data1.DataSource.RowCount;
    int blankRowsNeeded = maxRowsPerPage - (actualDataRowCount % maxRowsPerPage);

    // If the data exactly fills the page, hide the blank row band.
    if (blankRowsNeeded == maxRowsPerPage)
    {
        Data2.Visible = false;
    }
    else
    {
        Data2.Visible = true;
        Data2.RowCount = blankRowsNeeded; // Set the number of blank rows to render
    }
}
// --- END INSERTED CODE ---

Complete ReportScript class example after insertion:

namespace FastReport
{
    public class ReportScript
    {
        int maxRowsPerPage = 16;

        private void Page1_StartPage(object sender, EventArgs e)
        {
            int actualDataRowCount = Data1.DataSource.RowCount;
            int blankRowsNeeded = maxRowsPerPage - (actualDataRowCount % maxRowsPerPage);

            if (blankRowsNeeded == maxRowsPerPage)
            {
                Data2.Visible = false;
            }
            else
            {
                Data2.Visible = true;
                Data2.RowCount = blankRowsNeeded;
            }
        }
        // ... other existing code ...
    }
}

6.2. Code Explanation & Customization

  • Data1: Refers to the band containing your actual sales items.

  • Data2: Refers to the band that will generate the empty rows.

  • maxRowsPerPage = 16: This variable defines how many data rows (excluding headers) fit on a single page. You must adjust this number based on your page size (e.g., A4, Letter) and font size.


7. Bind the Event Handler

  1. Switch back to the Design view.

  2. In the Report Tree, select the top-level Page1.

  3. In the Properties pane, click the Events tab (lightning bolt icon).

  4. Find the StartPage event, click the dropdown, and select Page1_StartPage (the method you just created).


8. Preview and Finalize

  1. Click Preview (or Report > Preview) to test the template.

  2. The Data2 band should now generate enough empty rows to make the total rows on each page equal to maxRowsPerPage.

Important Note on maxRowsPerPage: This number represents the total body rows per page. For an A4 sheet with your specific layout, this might be 44 rows, not 16. Determine the correct value by checking how many rows of your Data1 table fit on a single page in the preview.



9. Update the Template Data Parameter

Before using the template in your system, you must finalize its configuration.

  1. Save and exit the report designer.

  2. Back in your system's report template configuration, edit the details of your new template.

  3. Find the data parameter (often named "ID" or similar) that was initially set to a specific document ID.

  4. Change this parameter's value to 0 (zero). This typically makes the template generic, allowing it to be used for any document by passing the correct ID at print time.

Download Ready-to-Use Templates

Two pre-configured sales delivery note templates with blank row filling are provided for download:

  • One formatted for a page size fitting 16 rows.

  • One formatted for A4 paper.


Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.