Kevin Kok Khah Whey
2023-09-25 34d29be6a3eb0c025da50b77f2107c4ad259c6c0
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
Quintiq file version 2.0
#parent: #root
Method DeleteScenario (
  structured[ScenarioNode] scenarionodes
) id:Method_FormScenarioManager_DeleteScenario
{
  #keys: '[134266.1.2130318926]'
  Body:
  [*
    // Delete selected scenarios
    trash := select ( ScenarioManager, ScenarioNode.astype( ScenarioFolder ), s, s.IsRecycleBin(), true );
    if ( not isnull( trash ) )
    { 
      if( exists( scenarionodes, Elements, e, not e.IsDeleted() ) )
      {
        ScenarioNode::Delete( scenarionodes, ScenarioManager )
        ListScenario.SelectByKey( trash.Key() );
    
        if( not isnull( MacroPlan ) // Dont need to delected scenario if there is no active scenario
            and exists( scenarionodes, Elements.astype( ScenarioMP ), smp,
                        smp.DatasetMDSID() = MacroPlan.MDSID() ) ) // Do not deselect the active scenario if it is not deleted.
        {
          DataHolderActiveScenario.Data( null( Scenario ) );
          ApplicationMacroPlanner.DeselectScenario();
          
          // Get active scenario
          activescenarios := selectset( ScenarioManager, ScenarioNode, node, not node.IsDeleted() );
          activescenarios := activescenarios.Difference( scenarionodes );
          // Get the remaining active ScenarioMP
          activescenario := maxselect( activescenarios, Elements.astype( ScenarioMP ), e,
                                       true, // e.IsVisible( DataHolderUserGroup.Data(), false, ApplicationMacroPlanner.GetUserName() ),
                                       e.CreatedOn() );
          // Select the scenario if found any
          if( not isnull( activescenario ) )
          {
            ApplicationMacroPlanner.SelectScenario( activescenario );
          }
        }
      }
      else
      {
        ScenarioNode::Delete( scenarionodes, ScenarioManager );
        ListScenario.SelectByKey( trash.Key() );
      }
    }
  *]
}