chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method UnloadDataset (
  structured[LibOpt_SnapshotReplannableCopyDataset] snapshots
) id:Method_LibOpt_GlobalState_UnloadDataset
{
  #keys: '[141860.2.581306648]'
  Body:
  [*
    // Unload the datasets that are attached to the LibOpt_SnapshotReplannableCopyDatasets
    loadedobjectinfos := ExternalMDSEditor::Editor().LoadedObjectInfos();
    infocurrentdataset := loadedobjectinfos.Find( snapshots.First().MDSID() );
    
    // Show a popup with a warning if you are trying to unload the currently selected dataset.
    traverse( snapshots,
              Elements,
              snapshot
              )
    {
      if( infocurrentdataset.Name() = snapshot.DatasetName() )
      {
        if ( MessageBox::Question( this, Translations::LibOpt_SnapshotReplannable_MessageBox_UnloadCurrentDataset(), '&Yes|&No' ) <> 0 )
        {
          snapshots.Remove( snapshot );
        }
      }
    }
    
    // The UnloadDatasetCopiesAndUpdateSnapshotStatus unloads all dataset copies.
    // When a dataset copy cannot be found, then the UnloadDatasetCopiesAndUpdateSnapshotStatus also updates all snapshots. 
    // We both unload the datasets and update the snapshots in a single method to ensure that we only start 1 server transaction.
    // We cannot use the 'Group server calls in 1 transaction' checkbox, because UI methods (like this one) cannot be used when that checkbox is checked.
    isanydatasetdeleted := LibOpt_SnapshotReplannableCopyDataset::UnloadDatasetCopiesAndUpdateSnapshotStatus( snapshots )
    if( isanydatasetdeleted )
    {
      // Show a popup warning explaining that the status of the snapshots has been updated.
      MessageBox::Warning( this,
                           Translations::LibOpt_SnapshotReplannable_MessageBox_UnexpectedStatus(),
                           Translations::LibOpt_MessageBox_OK()
                           );
    }
  *]
}