Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# GitHub Repository metadata
url: vcl-dashboards-non-interactive-export
website: https://docs.devexpress.com/VCL/405642/ExpressDashboards/vcl-dashboards
description: Generate DevExpress VCL Dashboards in backend and service applications.
tags: [vcl, pdf, dashboards, backend, service, cli, console]
79 changes: 42 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
# Uncomment these types if you want even more clean repository. But be careful.
# It can make harm to an existing project source. Read explanations below.
#
# Resource files are binaries containing manifest, project icon and version info.
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
#*.res
#
# Type library file (binary). In old Delphi versions it should be stored.
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
#*.tlb
#
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
# Uncomment this if you are not using diagrams or use newer Delphi version.
#*.ddp
#
# Visual LiveBindings file. Added in Delphi XE2.
# Uncomment this if you are not using LiveBindings Designer.
#*.vlb
#
# Deployment Manager configuration file for your project. Added in Delphi XE2.
# Uncomment this if it is not mobile development and you do not use remote debug feature.
#*.deployproj
#
# C++ object files produced when C/C++ Output file generation is configured.
# Uncomment this if you are not using external objects (zlib library for example).
#*.obj
#

# Default Delphi compiler directories
# Content of this directories are generated with each Compile/Construct of a project.
# Most of the time, files here have not there place in a code repository.
#Win32/
#Win64/
#OSX64/
#OSXARM64/
#Android/
#Android64/
#iOSDevice64/
#Linux64/
Win32/
Win64/
Win64x/

# Delphi compiler-generated binaries (safe to delete)
*.exe
Expand All @@ -61,6 +27,7 @@
*.cfg
*.hpp
*Resource.rc
*.rsp

# Delphi local files (user-specific info)
*.local
Expand All @@ -75,8 +42,46 @@ __history/
__recovery/
*.~*


# ------------------------------------------------------------
# C++Builder specific
# ------------------------------------------------------------

# C++Builder compiler outputs
*.obj
*.hpp
*.ilc
*.ild
*.ilf
*.ils
*.map
*.tds

# Precompiled headers
*.pch

# C++Builder packages and libraries
*.bpl
*.bpi
*.lib
*.a
*.dll
*.so

# C++Builder intermediate / cache files
*.cbproj.local
*.cbproj.identcache
*.cbproj.user
*.cbtemp


# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
*.stat

# Boss dependency manager vendor folder https://github.com/HashLoad/boss
modules/

# Output files
*.pdf
*.docx
*.zip
78 changes: 78 additions & 0 deletions Delphi/ConsoleDashboards.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
program ConsoleDashboards;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils, System.Classes, dxBackend, dxBackend.Bundled,
dxBackend.ConnectionString.SQL, dxDashboard;
var
ACountryName: string;

procedure ExportDashboardToPdf(const ACountryName: string);
var
AManager: TdxBackendDataConnectionManager;
AConnection: TdxBackendDatabaseSQLConnection;
ADashboard: TdxDashboard;
AStream: TMemoryStream;
AOutputFileName: string;
begin
// Step 1: Create a dashboard instance and load the dashboard layout
ADashboard := TdxDashboard.Create(nil);
try
ADashboard.Name := 'Country Sales';
ADashboard.Layout.LoadFromFile('CountrySalesDashboard.xml');

// Step 2: Create a data connection manager and set up the database connection
AManager := TdxBackendDataConnectionManager.Create(nil);
try
AConnection := TdxBackendDatabaseSQLConnection(AManager.DataConnections.Add(TdxBackendDatabaseSQLConnection));

// Assign a database name matching the name specified in the dashboard layout
AConnection.DisplayName := 'NWindConnectionString';
// Assign a connection string required to use the local SQLite database
AConnection.ConnectionString := 'XpoProvider=SQLite; Data Source=nwind.db; Mode=ReadOnly';
AConnection.Active := True;

// Step 3: Define Dashboard Parameter Values
ADashboard.LoadParametersFromDashboard;
// Set the "CountryDashboardParameter" value in the dashboard layout
ADashboard.Parameters['CountryDashboardParameter'].Value := ACountryName;
ADashboard.ApplyParametersToState;

// Step 4: Export the dashboard to PDF
AStream := TMemoryStream.Create;
try
// Export the dashboard to a memory stream in the PDF format
ADashboard.ExportTo(TdxDashboardExportFormat.PDF, AStream);
// Save memory stream content to a file
AOutputFileName := 'Sales_' + ACountryName + '.pdf';
AStream.SaveToFile(AOutputFileName);
Writeln('Dashboard saved to: ', AOutputFileName);
finally
AStream.Free;
end;
finally
AManager.Free;
end;
finally
ADashboard.Free;
end;
end;

begin
if ParamCount < 1 then
begin
Writeln('Error: CountryName parameter is required. For example: ConsoleDashboards.exe USA');
Halt(1); // Exit with error code 1
end;

ACountryName := ParamStr(1); // Read the first parameter as CountryName
try
ExportDashboardToPdf(ACountryName);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Loading