admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Quintiq file version 2.0
#parent: #root
Method SelectImportExportDatasetIfExists () id:Method_LibCal_GlobalState_SelectImportExportDatasetIfExists
{
  #keys: '[131094.1.1070484365]'
  Body:
  [*
    // Get the name of the ImportExport-dataset based on the name of planning-dataset.
    componentMDS := null( ComponentMDSBase, owning );
    mdsInstance  := null( ComponentMDSInstance );
    importExport := dhImportExport.Data();
    
    if( not isnull( importExport ) )
    {
      // Get the full name of the dataset.
      datasetName := LibCal_ImportExportDataset::GetFullName( importExport.GetDatasetName() );
      
      // Find the ImportExport-dataset.
      // Create a handle to the componentMDS, refresh it.
      // An explicit refresh is required to see the ImportExport-dataset when it was just loaded by EnsureImportExportDataset().
      componentMDS := ApplicationScope.ComponentMDS();
      componentMDS.Refresh();
      
      mdsInstance := select( componentMDS, ComponentMDSKinds.ComponentMDSInstances, instance,
                             instance.ComponentMDSKind().Kind() = LibCal_ImportExportDataset::DATASETKIND()   and
                             instance.Parent().Name()           = LibCal_ImportExportDataset::DATASETFOLDER() and
                             instance.Name()                    = datasetName );
    }
    
    // Select the dataset if it exists...
    if( not isnull( mdsInstance ) )
    {
      // Explicitly check if the dataset is loaded, otherwise the Software will do it for you (and throw an error).
      if( mdsInstance.IsLoaded() )
      {
        mdsInstance.ComponentMDSKind().SelectInstance( mdsInstance );
        componentMDS.Apply();
      }
    }
    else
    {
      // ... deselect the currenly selected ImportExport-dataset otherwise, because it belongs to a different planning-dataset.
      mdsInstance := select( componentMDS, ComponentMDSKinds.ComponentMDSInstances, instance,
                             instance.ComponentMDSKind().Kind() = LibCal_ImportExportDataset::DATASETKIND() and
                             instance.IsSelected() );
      if( not isnull( mdsInstance ) )
      {
        mdsInstance.ComponentMDSKind().DeselectAll();
        componentMDS.Apply();
      }
    }
  *]
}