lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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 DeleteDataset (
  structured[LibOpt_SnapshotReplannableCopyDataset] snapshots
) id:Method_LibOpt_GlobalState_DeleteDataset
{
  #keys: '[141860.2.581295660]'
  Body:
  [*
    // Delete 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 delete the currently selected dataset.
    // Show a different popup for each dataset that is currently loaded. 
    traverse( snapshots,
              Elements,
              snapshot,
              not snapshot.IsDatasetDeleted()
              )
    {
      if( infocurrentdataset.Name() = snapshot.DatasetName() )
      {
        if ( MessageBox::Question( this, Translations::LibOpt_SnapshotReplannable_MessageBox_DeleteCurrentDataset(), '&Yes|&No' ) <> 0 )
        {
          snapshots.Remove( snapshot );
        }
      }
      else if( not isnull( loadedobjectinfos.Find( snapshot.DatasetName() ) ) )
      {
        if ( MessageBox::Question( this, Translations::LibOpt_SnapshotReplannable_MessageBox_DeleteLoadedDataset( snapshot ), '&Yes|&No' ) <> 0 )
        {
          snapshots.Remove( snapshot );
        }
      }
    
    }
    
    // The DeleteDatasetCopiesAndUpdateSnapshotStatus unloads all dataset copies.
    // When a dataset copy cannot be found, then the DeleteDatasetCopiesAndUpdateSnapshotStatus also updates all snapshots. 
    // We both delete 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::DeleteDatasetCopiesAndUpdateSnapshotStatus( 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()
                           );
    }
  *]
}