| Quintiq file version 2.0 | 
| #parent: #root | 
| Method DeleteScenario ( | 
|   structured[ScenarioNode] scenarionodes | 
| ) id:Method_ScenarioManager_FormScenario_DeleteScenario | 
| { | 
|   #keys: '[113694.1.1854608641]' | 
|   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() ); | 
|         ListScenario.ExpandSelection(); | 
|      | 
|         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. | 
|         { | 
|           Form.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, | 
|                                        e.IsVisible( DataHolderUserGroup.Data(), false, ApplicationLibMacroPlanner.GetUserName() ), | 
|                                        e.CreatedOn() ); | 
|           // Select the scenario if found any | 
|           if( not isnull( activescenario ) ) | 
|           { | 
|             Form.SelectScenario( activescenario ); | 
|           } | 
|           else | 
|           {    | 
|             DataHolderActiveScenario.Data( null( Scenario ) ); | 
|             ApplicationLibMacroPlanner.Optimizer_UpdateIconResultStatus(); | 
|           } | 
|         } | 
|       } | 
|       else | 
|       { | 
|         ScenarioNode::Delete( scenarionodes, ScenarioManager ); | 
|         ListScenario.SelectByKey( trash.Key() ); | 
|         ListScenario.ExpandSelection(); | 
|       } | 
|      | 
|     } | 
|   *] | 
| } |