Managed Code C#, VB.NET, C++

TARGET Reports managed code samples for use in automation

location:  InstallDir\Samples\Target Reports\Automation\Managed Code\

Sample Solution


A Visual Studio 2005 solution has been provided with sample projects demonstrating Target Reports Automation using ASP.NET, C#, Managed C++, and VB.Net.  You can open TargetReportSamples.sln and build any of the samples yourself, or for your convenience one is already built for you called TargetReportSample.exe. 

 

The C#, Managed C++, and VB.Net projects all show/implement the same set of samples, an image of what appears when you run TargetReportSample.exe is shown below: 

 

 

The actual implementation of the samples are broken down into several different categories: Show in Viewer, Data Output, Report Element Properties, Report Element Scope Properties, TARGET Variable Manipulations and Report Element Output Datasources, which is further broken down into flat file output, output via OLE DB providers, and output via ODBC data sources. A general description the functionality of each category is listed below. For more detailed information about actual API calls used by these samples please refer to the sample code provided, file and method names will be provided for each sample.

Show In Viewer
This section of samples demonstrates how to generate a report with TARGET Reports and have the result shown in its associated viewer. Ex. MS Word for rtf output, Internet explorer for html output, Adobe Acrobat for pdf output, or MS Excel for Excel output. Each of the 4 samples generates reports using the file “\Samples\TARGET Reports\1.1 Summary.report” which contains 2 reports elements, 1 chart and 1 table report element.

Source Locations: 
C#: 
File: TargetReportSamples.cs
Method: ShowRTF

Managed C++:
File: TargetReportSamples.h 
Method: ShowRTF

VB.Net:
File: TargetReportSamples.vb
Method: ShowRTF


Data Output
This section of samples demonstrates how to output a report to different types of files, .rtf, excel, etc. These samples will NOT show the generated files in its associated viewer. Each of the 4 different samples here outputs the results of the file “\Samples\TARGET Reports\1.1 Summary.report” to a different file.

Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetRTFFile 

Managed C++:
File: TargetReportSamples.h 
Method: SetRTFFile

VB.Net:
File: TargetReportSamples.vb 
Method: SetRTFFile


Report Element Properties
Enable/Disable Element

This sample demonstrates how to select and disable a report element so that any tables or charts that would be displayed in the report produced no longer appear. This particular sample disables the Graph Report element found in the file “\Samples\TARGET Reports\1.1 Summary.report” and displays the resultant .rtf file in the default .rtf viewer.

Source Locations: 
C#:
File: TargetReportSamples.cs
Method: DisableReportSetup

Managed C++:
File: TargetReportSamples.h
Method: DisableReportSetup

VB.Net:
File: TargetReportSamples.vb
Method: DisableReportSetup



Report Element Scope Properties
All of the following samples make use of the file, “\Samples\TARGET Reports\Automation\Projects\Input Files\Variable sample.report” which contains 2 report setups for displaying summary information for 1996 and one for 1997. All scope interactions deal with the first setup, Report_1, which operates on data from 1996.

Get Scope
Displays the current scope that is setup in the file and displays it in a message box. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: GetScope

Managed C++:
File: TargetReportSamples.h 
Method: GetScope

VB.Net:
File: TargetReportSamples.vb
Method: GetScope

Set Scope
Displays the scope before and after setting the scope to OrderDate >= '01/01/1995' AND OrderDate >= '01/01/1998'. Setting of a scope replaces everything in the existing scope. The report is then run with the altered scope and displayed in the default .rtf viewer. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetScope

Managed C++:
File: TargetReportSamples.h
Method: SetScope

VB.Net:
File: TargetReportSamples.vb
Method: SetScope

Modify Scope
Displays the scope before and after setting the scope to OrderDate >= '01/01/1995' AND OrderDate >= '01/01/1998'. Modifying the scope appends the modified text to the existing scope. The report is then run with the altered scope and displayed in the default .rtf viewer. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: ModifyScope

Managed C++:
File: TargetReportSamples.h
Method: ModifyScope

VB.Net:
File: TargetReportSamples.vb
Method: ModifyScope


Report Element Output Datasources
Report elements have the option of saving their individual results to an output data source such as a dbase file, excel table, access table, SQL Server table, etc. The samples listed here demonstrate how to setup various kinds of output data sources for a report element. These samples make use of the file: “\Samples\TARGET Reports\1.1 Summary.report”. The output data sources are all set for the Report Element with the name: “Report_1”.

Flat File Datasources
The suggested method to set flat file data sources is to use the SetDS method. For Excel and Access files you will additionally need to set the table name. For Text/CSV output files there are also additional properties that can be set to specify delimiters. 

DBF Output Datasource
This sample sets the output data source to “\Samples\TARGET Reports\Automation\Projects\Output Files\output_table.dbf” and runs the report. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetDBFOutput

Managed C++:
File: TargetReportSamples.h
Method: SetDBFOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetDBFOutput

Excel Output Datasource
This sample sets the output data source to “\Samples\TARGET Reports\Automation\Projects\Output Files\output_table.xls” to a table named MyTable and runs the report. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetExcelOutput

Managed C++:
File: TargetReportSamples.h
Method: SetExcelOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetExcelOutput

MS Access Output Datasource
This sample sets the output data source to “\Samples\ TARGET Reports\Automation\Projects\Output Files\output_table.mdb” to a table named MyTable and runs the report. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetAccessOutput

Managed C++:
File: TargetReportSamples.h
Method: SetAccessOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetAccessOutput

Text/CSV Output Datasource
This sample sets the output data source to “\Samples\ TARGET Reports\Automation\Projects\Output Files\output_table.txt”. This output file is setup to include column names as the first line of the file and separates fields with “,” and to identify text it uses the qualifier “||”. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetTextOutput

Managed C++:
File: TargetReportSamples.h
Method: SetTextOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetTextOutput

OLEDB Datasources
To setup OLEDB data sources you need to set CLSID, dsn, database, schema, and table values explicitly as well as user name and password if needed. 

MS Sql Server Output Datasource
This sample demonstrates how to setup a MS Sql Server data source. For MS Sql Server the CLSID use is SQLOLEDB. This is the progid of the SQL OLEDB Provider. Dsn is assigned to the server name, database is set to the database name, schema name is set to “dbo” by default, and in this case the table name is set to “MyTable”. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetSqlSvrOutput

Managed C++:
File: TargetReportSamples.h
Method: SetSqlSvrOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetSqlSvrOutput

Oracle Output Datasource
This sample demonstrates how to setup a MS Sql Server data source. For Oracle the CLSID used is “MSDAORA”. This is the progid of the Microsoft Provider for Oracle you could also use “OraOLEDB.Oracle” which is the progid for the Oracle Provider for OLEDB. Dsn is assigned to the server name, database is set to the database name, schema name is set to “MySchema”, and in this case the table name is set to “MyTable”. 
Source Locations: 
C#:
File: TargetReportSamples.cs 
Method: SetOracleOutput

Managed C++:
File: TargetReportSamples.h 
Method: SetOracleOutput

VB.Net:
File: TargetReportSamples.vb 
Method: SetOracleOutput

ODBC Datasources
For every ODBC data source connection the CLSID must be set to “MSDASQL” which is the progid for Microsoft Provider for ODBC drivers. Dsn should be set to the file or system dsn name created for this particular driver setup. In MOST cases it should not be required to specify user name and password because this information is usually stored in the driver setup. 

MS Sql Server ODBC Output Datasource
This sample demonstrates how setup an output data source for an ODBC driver that is setup to connect to a MS Sql Server table. 
Source Locations: 
C#:
File: TargetReportSamples.cs 
Method: SetODBCSqlSvrOutput

Managed C++:
File: TargetReportSamples.h
Method: SetODBCSqlSvrOutput

VB.Net:
File: TargetReportSamples.vb 
Method: SetODBCSqlSvrOutput

MySQL ODBC Output Datasource
This sample demonstrates how setup an output data source for an ODBC driver that is setup to connect to an Oracle table. 
Source Locations: 
C#:
File: TargetReportSamples.cs
Method: SetODBCMysqlOutput

Managed C++:
File: TargetReportSamples.h 
Method: SetODBCMysqlOutput

VB.Net:
File: TargetReportSamples.vb
Method: SetODBCMysqlOutput

TARGET Variable manipulations:
These 2 samples make use of the “<Install Dir>\Samples\ TARGET Reports\Automation\Projects\Input Files\Variable sample.report”. This sample files contains 2 table reports on the second page and displays summary information for the years 1996 and 1997 respectively on the first page. The report element for the year 1996 ( Report_1 ) also has some additional scripting code that displays addition summary information( Max and Avg of Price USD and Price GBR by default ) for 1996 at the end of the report. This extra reporting information is ONLY shown if the TARGET Variable of Report_1 by the name of “GetAggs” is set to a value of 1. By default this is 0.

Edit TARGET Variable Value
This sample demonstrates how to access this TARGET variable and alter its value. Once the value is altered to 1 the report is run and the result will be displayed in the .rtf viewer 
Source Locations: 
C#:
File: TargetReportSamples.cs 
Method: SetTARGETVariableValue

Managed C++:
File: TargetReportSamples.h 
Method: SetTARGETVariableValue

VB.Net:
File: TargetReportSamples.vb 
Method: SetTARGETVariableValue

Modify TARGET Variable Array
The extra summary information which is output as a result of setting the TARGET variable, GetAggs, to 1 is stored as an array inside of a different TARGET variable, Stat_names. By default these names are as follows: Max( Freight ), Max( Price_ ), Avg( Freight ), Avg( Price_ ) ( Please note that Freight and Price_ are the ID Names for Price USD and Price GBR respectively ). These values when passed as a parameter for GetStatistics, see documentation for more information on GetStatistics, return an array of numeric values containing the results of the summary calculations for each summary function passed into GetStatistics. 

This sample 1st enables this additional summary information by setting the value of the TARGET variable GetAggs to 1, but it also CHANGES the summary statistics that are calculated by this process. This is done by altering the values stored in the TARGET variable, Stat_name. The values for Stat_name are changed to: Count( Freight ), Min( Freight ), Count( Price_ ), and Min( Price_ ). The report is then run and displayed in .rtf viewer. 
Source Locations: 
C#:
File: TargetReportSamples.cs 
Method: SetTARGETVariableArray

Managed C++:
File: TargetReportSamples.h 
Method: SetTARGETVariableArray

VB.Net:
File: TargetReportSamples.vb 
Method: SetTARGETVariableArray

TARGET Variable Value as Date
Demonstrates how to display the date value of a TARGET variable as a string by specifying different formats. The results are displayed in a message box. 
Source Locations: 
C#: 
File: TargetReportSamples.cs 
Method: GetTARGETVariableAsDateString 

Managed C++: 
File: TargetReportSamples.h 
Method: GetTARGETVariableAsDateString 

VB.Net: 
File: TargetReportSamples.vb 
Method: GetTARGETVariableAsDateString 

TARGET Variable Value as Numeric
Demonstrates how to display the numeric value of a TARGET variable as a string by specifying different formats. The results are displayed in a message box. 
Source Locations: 
C#:
File: TargetReportSamples.cs 
Method: GetTARGETVariableAsNumericString

Managed C++:
File: TargetReportSamples.h 
Method: GetTARGETVariableAsNumericString

VB.Net:
File: TargetReportSamples.vb 
Method: GetTARGETVariableAsNumericString

ASP .Net Sample
The TargetReportsASPNET sample demonstrates how to use Target Reports Automation under ASP .NET. This sample makes use of the file: “\Samples\Target Reports\1.1 Summary.report”. The asp page in the sample contains 2 calendar controls. When the submit button is clicked the scope for the report element “Report_1” is modified to contain “OrderDate >= <start_date> AND OrderDate <= <end_date>”, where <start_date> and <end_date> are the values taken from the 2 calendar controls. The report is then run using the RunGetStream method and displays/embeds the html results on the bottom of this web page.
Comments