TFORMer SDK - NET 8
Repository Access

This sample demonstrates functions to access or modify the information stored in a Repository.

See also
Repository / FormLayout
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class RepositorySamples
{
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
Repository ConnectToStandAloneForm ()
{
// Create a new Repository instance using a stand-alone FormLayout (extension *.tff)
// Examples are usually installed in
// - Windows Vista or later: C:/Program Data/TEC-IT/TFORMer/8/Examples
// - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples
Repository repository = new Repository(@"C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples/Command Line/ODBCReportPDF/ODBCReportPDF.tff", false, true);
return repository;
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
Repository ConnectToRepository ()
{
// Create a new Repository instance using a Repository (extension *.tfr)
// Examples are usually installed in
// - Windows Vista: C:/Program Data/TEC-IT/TFORMer/8/Examples
// - Older Microsoft Windows versions: C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples
Repository repository = new Repository(@"C:/Documents and Settings/All Users/Application Data/TEC-IT/TFORMer/8/Examples/Demo Repository/Demos.tfr", false, true);
return repository;
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void DataFieldUsageStandAloneForm ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// A stand-alone FormLayout contains only the global Project, the global Project holds the FormLayout and all DataField definitions
Project project = repository.GlobalProject;
// Retrieve the one and only FormLayout within the stand-alone FormLayout
FormLayout formlayout = project.FirstFormLayout;
// Iterate all DataFields within the Project
DataField datafield = project.FirstDataField;
while (datafield != null)
{
Console.Write(datafield.ToString());
// Retrieve the usage of the DataFields in the FormLayout
switch (formlayout.GetDataFieldUsage (datafield.Name))
{
case DataFieldUsage.Calculated: Console.Write ("--> The value of this DataField is computed within the FormLayout"); break;
case DataFieldUsage.Invalid : Console.Write ("--> Invalid usage - contact TEC-IT"); break;
case DataFieldUsage.Normal : Console.Write ("--> The DataField is used within the FormLayout; its value can be set"); break;
case DataFieldUsage.NotUsed : Console.Write ("--> This DataField is not used in this FormLayout"); break;
case DataFieldUsage.Parameter : Console.Write ("--> This is a system DataField (like the page number) used within the FormLayout"); break;
}
Console.WriteLine();
datafield = datafield.Next;
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void FetchFormLayoutStandAloneForm ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// A stand-alone FormLayout contains only the global Project, the global Project contains the FormLayout
Project project = repository.GlobalProject;
if (project != null)
{
Console.Write(project.ToString());
// Retrieve the first (and only) FormLayout
FormLayout formlayout = project.FirstFormLayout;
if (formlayout != null)
{
Console.Write(formlayout.ToString());
}
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateProjects ()
{
Repository repository = ConnectToRepository ();
// Retrieve the first Project
Project project = repository.FirstProject;
while (project != null)
{
Console.Write(project.ToString());
// Get the next Project
project = project.Next;
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateFormLayoutsRepository ()
{
Repository repository = ConnectToRepository ();
// Retrieve the first Project
Project project = repository.FirstProject;
while (project != null)
{
Console.Write(project.ToString());
// Retrieve the first FormLayout in this Project
FormLayout formlayout = project.FirstFormLayout;
while (formlayout != null)
{
Console.Write(formlayout.ToString());
// Get the next FormLayout in this Project
formlayout = formlayout.Next;
}
// Get the next Project
project = project.Next;
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateDataFieldsStandAloneForm ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// A stand-alone FormLayout contains only the global Project, the global Project holds all DataField definitions
Project project = repository.GlobalProject;
// Retrieve the first DataField
DataField datafield = project.FirstDataField;
while (datafield != null)
{
// Your code follows
Console.WriteLine (datafield.Name);
// Get the next DataField
datafield = datafield.Next;
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void DataSourceOdbcModify ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// DataSources are defined in a Project or a global Project
Project project = repository.GlobalProject;
// Retrieve the DataSource by name
// Since we know the type of the DataSource, we can cast it to DataSourceOdbc
DataSourceOdbc dataSource = (DataSourceOdbc) (project.GetDataSource("ODBC"));
// Modify some DataSource properties
dataSource.User = "";
dataSource.Password = "";
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void DataSourceCsvModify ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// DataSources are defined in a Project or a global Project
Project project = repository.GlobalProject;
// Retrieve the DataSource by name
// Since we know the type of the DataSource, we can cast it to DataSourceCsv
DataSourceCsv dataSource = (DataSourceCsv)project.GetDataSource("CSV");
// Modify some DataSource properties
dataSource.Qualifier = "'";
dataSource.Separator = ",";
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void DataSourceXmlModify ()
{
Repository repository = ConnectToStandAloneForm ();
// Retrieve the global Project
// DataSources are defined in a Project or a global Project
Project project = repository.GlobalProject;
// Retrieve the DataSource by name
// Since we know the type of the DataSource, we can cast it to DataSourceXml
DataSourceXml dataSource = (DataSourceXml)project.GetDataSource("XML");
// Modify some DataSource properties
dataSource.XsltFilename = ""; // clear XSLT filename
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateDataSourcesProject (Project project)
{
// Iterate all DataSources of the Project
for (DataSource ds = project.FirstDataSource; ds != null; ds = ds.Next)
{
Console.WriteLine (ds.ToString ());
// Print information for the DataSourceParameters of the DataSource
for (DataSourceParameter dsParam = ds.FirstParameter; dsParam != null; dsParam = dsParam.Next)
Console.WriteLine (dsParam.ToString ());
// Print information for the ComputedFields of the DataSource
for (ComputedField dsComp = ds.FirstComputedField; dsComp != null; dsComp = dsComp.Next)
Console.WriteLine (dsComp.ToString ());
// Print the mapping between source fields and DataFields
for (DSFieldMapping dsFieldmap = ds.FirstFieldMapping; dsFieldmap != null; dsFieldmap = dsFieldmap.Next)
Console.WriteLine (dsFieldmap.ToString ());
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateDataSources ()
{
// Open the Repository
Repository repository = ConnectToRepository ();
// Iterate the DataSources of the global Project
// If a Repository is used, the global Project and additional user-defined Projects may exist
Console.WriteLine ("Global project");
IterateDataSourcesProject (repository.GlobalProject);
// Iterate additional Projects
// Additional Projects are only possible when using a Repository
for (Project project = repository.FirstProject; project != null; project = project.Next)
{
Console.WriteLine (project.ToString ());
// Iterate the DataSources of the Project
IterateDataSourcesProject (project);
}
}
//-------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------
void IterateDataSourcesStandAloneForm ()
{
Repository repository = ConnectToStandAloneForm ();
// Iterate the DataSources of the global Project
// If a stand-alone FormLayout is used, the global Project is the only Project
Console.WriteLine ("Global project");
IterateDataSourcesProject (repository.GlobalProject);
}
//-------------------------------------------------------------------------------------------
// M A I N
//-------------------------------------------------------------------------------------------
// Call the various sample functions
//-------------------------------------------------------------------------------------------
static void Main(string[] args)
{
RepositorySamples sample = new RepositorySamples();
sample.DataFieldUsageStandAloneForm ();
sample.FetchFormLayoutStandAloneForm ();
sample.IterateProjects ();
sample.IterateFormLayoutsRepository ();
sample.IterateDataFieldsStandAloneForm();
sample.IterateDataSources ();
sample.IterateDataSourcesStandAloneForm();
}
} // class RepositorySamples
Provides access to a ComputedField which is referenced by a DataSource.
Definition: ComputedField.cs:54
ComputedField Next
Gets the next ComputedField defined in the DataSource.
Definition: ComputedField.cs:315
DSFieldMapping defines the field-mappings between a DataSource and the DataFields used in a Formlayou...
Definition: DSFieldMapping.cs:20
DSFieldMapping Next
Gets the next DSFieldMapping in the DataSource.
Definition: DSFieldMapping.cs:137
Provides access to DataField information.
Definition: DataField.cs:57
DataField Next
Gets the next DataField defined in the Project.
Definition: DataField.cs:416
string Name
Gets/Sets the name of the DataField.
Definition: DataField.cs:174
override string ToString()
Returns a string representation of the instance.
Definition: DataField.cs:520
Specialized DataSource for CSV data (character separated values).
Definition: DataSourceText.cs:17
Abstract class for a DataSource.
Definition: DataSource.cs:56
DataSource Next
Gets the next DataSource instance defined in the Project.
Definition: DataSource.cs:370
Specialized DataSource for ODBC data.
Definition: DataSourceODBC.cs:17
Provides access to properties of a DataSourceParameter.
Definition: DataSourceParameter.cs:17
DataSourceParameter Next
Gets the next DataSourceParameter defined in the DataSource.
Definition: DataSourceParameter.cs:245
Specialized DataSource for XML data.
Definition: DataSourceXML.cs:17
Provides access to a FormLayout which is referenced by a Repository or available as stand-alone FormL...
Definition: FormLayout.cs:66
DataFieldUsage GetDataFieldUsage(string dataFieldName)
Retrieves the usage of a specific DataField in a FormLayout.
Definition: FormLayout.cs:367
FormLayout Next
Gets the next FormLayout in the Project.
Definition: FormLayout.cs:307
override string ToString()
Returns a string representation of the instance.
Definition: FormLayout.cs:532
Provides access to Project information of a Repository or a stand-alone link FormLayout.
Definition: Project.cs:22
FormLayout FirstFormLayout
Gets the first FormLayout of the Project.
Definition: Project.cs:295
DataSource GetDataSource(string name)
Gets the DataSource information from the Project.
Definition: Project.cs:613
DataSource FirstDataSource
Gets the first DataSource defined in the Project.
Definition: Project.cs:255
DataField FirstDataField
Gets the first DataField of the Project.
Definition: Project.cs:215
Project Next
Gets the next Project defined in the Repository.
Definition: Project.cs:193
override string ToString()
Returns a string representation of the instance.
Definition: Project.cs:648
Opens or creates a Repository, opens a stand-alone FormLayout.
Definition: Repository.cs:24
Project GlobalProject
Gets the global Project of the Repository.
Definition: Repository.cs:478
Project FirstProject
Gets the first Project stored in the Repository.
Definition: Repository.cs:456
DataFieldUsage
Describes the usage of a DataField within a FormLayout.
Definition: FormLayout.cs:15

© 2006-2023 - all rights reserved by TEC-IT Datenverarbeitung GmbH
Generated on Thu Dec 28 2023 18:45:19 for TFORMer SDK - NET with doxygen 1.9.4