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;
using TECIT.TFORMer;


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

© 2006-2024 - all rights reserved by TEC-IT Datenverarbeitung GmbH
Generated on Wed Aug 7 2024 17:29:42 for TFORMer SDK - NET with doxygen 1.7.6.1