Skip to content

stefmorp/DDDTools

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DDDTools

DDDTools is a Windows Forms application designed for Italian businesses to generate PDF receipts (ricevute) from transaction data stored in Excel files. The application automates the process of creating professional receipts with customer information, amounts in both numbers and Italian words, and tax details.

Features

  • 📄 PDF Receipt Generation: Generate professional PDF receipts from Excel data
  • 🏦 Multiple Templates: Support for both bank (BANCA) and post office (POSTA) receipt templates
  • 💰 Italian Number Conversion: Automatically converts amounts to Italian words (e.g., "cinquecento euro / 00")
  • 📊 Excel Integration: Read and write transaction data to/from Excel files (.xlsx)
  • 🔍 Fast Data Access: Optimized for quick access to recent invoices
  • 🇮🇹 Italian Tax Fields: Handles Italian tax information (IVA/VAT, fiscal code, etc.)

Requirements

  • .NET Framework 4.5.2 or higher (recommended: 4.7.2 or 4.8)
  • Windows OS (Windows 7 SP1 or later)
  • Excel files (.xlsx format) with transaction data
  • PDF templates: template-banca.pdf and template-posta.pdf (must be in the application directory)

Troubleshooting Windows 10 Issues

If the application flashes and closes immediately on Windows 10:

  1. Install .NET Framework 4.8: Download and install from Microsoft's website
  2. Check error messages: The application now displays error dialogs if something goes wrong
  3. Verify dependencies: Ensure EPPlus.dll and itextsharp.dll are in the same folder as DDDTools.exe
  4. Check Windows Event Viewer: Look for application errors in Windows Logs → Application

Excel File Format

The Excel file should have the following structure:

  • Rows 1-3: Header rows (labels/metadata, not data)
  • Row 4 onwards: Data rows containing transaction records

Important: The ID is not stored in the Excel file. The ID is simply the row number (e.g., row 4 = ID "4", row 5 = ID "5", etc.). This means:

  • When you enter an ID in the application, you're specifying which row to read/write
  • The ID corresponds directly to the Excel row number
  • No ID column exists in the Excel file - it's derived from the row position
Column Field Description
1 Number Receipt number
2 Year Transaction year
3 Name Customer first name
4 Surname Customer last name
5 Address Street address
6 CAP Postal code
7 City City name
8 Province Province abbreviation
9 Fiscal Code Codice fiscale
10 IVA VAT number (Partita IVA)
11 Amount Transaction amount in euros
12 Date Transaction date

Note: The ID used in the application is the Excel row number. For example, if your data starts at row 4, the first record has ID "4", the second has ID "5", etc.

How to Use

Step 1: Load Excel File

  1. Launch the application
  2. Click "Carica Excel" (Load Excel) button
  3. Select your Excel file containing transaction data
  4. Wait for the progress bar to complete (the application will scan the file)

Step 2: Generate Receipt

  1. Enter the ID (which is the Excel row number) of the transaction you want to generate a receipt for
    • Important: The ID is the row number in Excel. Since data starts at row 4, the first record has ID "4", second has ID "5", etc.
    • Tip: The last invoice ID is typically the highest row number in your Excel file (e.g., if your last data row is 100, the ID is "100")
  2. Click either:
    • "Genera ricevuta (BANCA)" - For bank template
    • "Genera ricevuta (POSTA)" - For post office template
  3. Choose where to save the PDF file
  4. The receipt will be generated with all customer and transaction details

Step 3: View Files

  • Click "Apri ultimo PDF generato" to open the last generated PDF
  • Click "Apri Excel caricato" to open the loaded Excel file

Version 2.0 Improvements

Performance Optimizations

Version 2.0 introduces significant performance improvements, especially for large Excel files:

🚀 Lazy Loading

  • Before: The application loaded ALL rows from the Excel file into memory on startup
  • After: Only scans metadata (last row, last ID) and loads records on-demand
  • Impact: Initial load time reduced from 10-30 seconds to 1-2 seconds for large files (10,000+ rows)

💾 Smart Caching

  • Pre-loads only the last 50 records for quick access to recent invoices
  • Records are loaded on-demand when accessing older invoices
  • Automatic cache management prevents memory bloat
  • Impact: Most common use case (printing last invoice) is now instant

Efficient Data Access

  • Backward scanning to find the last row (faster than forward scanning)
  • Records loaded only when needed via GetById() method
  • Improved error handling with user-friendly messages

🔒 Thread Safety

  • Before: Dictionary access was not synchronized, causing potential race conditions when loading Excel files on a background thread while generating receipts on the UI thread
  • After: All dictionary and metadata access is protected with locks, ensuring thread-safe operations
  • Impact: Prevents InvalidOperationException and crashes when users generate receipts while Excel files are being loaded in the background
  • Technical: Uses lock statements to synchronize access to the database dictionary and metadata fields (lastID, lastnumber, totalRows)

📈 Performance Comparison

Scenario Version 1.0 Version 2.0 Improvement
Load 10,000 row Excel 15-30 sec 1-2 sec ~90% faster
Print last invoice 0.5-1 sec Instant ~100% faster
Print older invoice 0.5-1 sec 0.1-0.3 sec ~70% faster
Memory usage All rows Last 50 rows ~95% less

Technical Details

The optimization uses:

  • Lazy loading pattern: Data loaded only when requested
  • LRU-style caching: Most recently accessed records stay in memory
  • Efficient Excel scanning: Uses EPPlus Dimension property and backward iteration
  • On-demand record loading: GetRecord() method loads individual records from Excel when not in cache
  • Thread synchronization: All dictionary and metadata access protected with locks to prevent race conditions between background Excel loading and UI thread operations

Project Structure

DDDTools/
├── DDDTools/
│   ├── DataProcesser.cs      # Excel data processing (optimized in v2.0)
│   ├── PdfGenerator.cs         # PDF generation logic
│   ├── NumberToWords.cs       # Italian number-to-words conversion
│   ├── Form2.cs               # Main user interface
│   └── ...
└── README.md

Dependencies

  • EPPlus (ExcelPackage) - For Excel file manipulation
  • iTextSharp 5.5.10 - For PDF generation

License

See LICENSE file for details.

Author

Created by Fabrizio Spoleti


Note: Make sure the PDF template files (template-banca.pdf and template-posta.pdf) are present in the application directory for the receipt generation to work properly.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C# 100.0%