@@ -5,70 +5,40 @@ program ConsoleDashboards;
55{ $R *.res}
66
77uses
8- System.SysUtils,
9- System.Classes,
10- System.IniFiles,
11- dxBackend,
12- dxBackend.Bundled,
13- dxBackend.ConnectionString.SQL,
14- dxDashboard;
8+ System.SysUtils, System.Classes, dxBackend, dxBackend.Bundled,
9+ dxBackend.ConnectionString.SQL, dxDashboard;
1510
1611procedure ExportDashboardToPdf ;
1712var
1813 AManager: TdxBackendDataConnectionManager;
1914 AConnection: TdxBackendDatabaseSQLConnection;
2015 ADashboard: TdxDashboard;
21-
2216 AStream: TMemoryStream;
23-
24- AIni: TIniFile;
25-
26- AParamName: string;
27- AKeys: TStringList;
28- I: Integer;
2917begin
3018 TdxBackend.Instance.Start; // Start the backend
3119
3220 AManager := TdxBackendDataConnectionManager.Create(nil );
33- AIni := TIniFile.Create(' ..\PDFDashboardGenerator.ini' );
3421 try
35- AConnection := TdxBackendDatabaseSQLConnection(AManager.DataConnections.
36- Add(TdxBackendDatabaseSQLConnection));
22+ AConnection := TdxBackendDatabaseSQLConnection(AManager.DataConnections.Add(TdxBackendDatabaseSQLConnection));
3723
38- AConnection.ClassName;
39- AConnection.DisplayName := AIni.ReadString(' Connection' , ' Name' , ' ' );
40- AConnection.ConnectionString :=
41- AIni.ReadString(' Connection' , ' ConnectionString' , ' ' );
24+ // Set up SQLite database connection
25+ AConnection.DisplayName := ' NWindConnectionString' ;
26+ AConnection.ConnectionString := ' XpoProvider=SQLite; Data Source=..\nwind.db; Mode=ReadOnly' ;
4227 AConnection.Active := True;
4328
4429 ADashboard := TdxDashboard.Create(nil );
4530 try
46- ADashboard.Layout.LoadFromFile(AIni.ReadString( ' Dashboard ' , ' LayoutFileName ' , ' ' ) );
47- ADashboard.Name := ' Dashboard ' ;
31+ ADashboard.Layout.LoadFromFile(' CountrySalesDashboard.xml ' );
32+ ADashboard.Name := ' Country Sales ' ;
4833
4934 ADashboard.LoadParametersFromDashboard;
50-
51- AKeys := TStringList.Create;
52- AIni.ReadSection(' Parameters' , AKeys);
53- try
54- for I := 0 to AKeys.Count - 1 do
55- begin
56- AParamName := AKeys[I];
57-
58- if ADashboard.Parameters.ParamByName[AParamName] <> nil then
59- ADashboard.Parameters
60- .ParamByName[AKeys[I]]
61- .Value := AIni.ReadString(' Parameters' , AParamName, ' ' );
62- end ;
63- ADashboard.ApplyParametersToState;
64- finally
65- AKeys.Free;
66- end ;
35+ ADashboard.Parameters[' CountryDashboardParameter' ].Value := ' USA' ;
36+ ADashboard.ApplyParametersToState;
6737
6838 AStream := TMemoryStream.Create;
6939 try
70- ADashboard.ExportTo(TdxDashboardExportFormat.PDF, AStream);// probably, we can add an overload
71- AStream.SaveToFile(AIni.ReadString( ' Dashboard ' , ' OutputFileName ' , ' ' ))
40+ ADashboard.ExportTo(TdxDashboardExportFormat.PDF, AStream);
41+ AStream.SaveToFile(' Sales_USA.pdf ' );
7242 finally
7343 AStream.Free;
7444 end ;
@@ -77,14 +47,12 @@ begin
7747 end ;
7848 finally
7949 AManager.Free;
80- AIni.Free;
8150 end ;
8251end ;
8352
8453begin
8554 try
8655 ExportDashboardToPdf;
87- { TODO -oUser -cConsole Main : Insert code here }
8856 except
8957 on E: Exception do
9058 Writeln(E.ClassName, ' : ' , E.Message);
0 commit comments