haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Quintiq file version 2.0
#parent: #root
Method NewScenario (
  internal[GUIComponent] parent,
  ScenarioManager owner,
  ScenarioNode scenarionode,
  Boolean enableautoimport
) as Scenario id:Method_ScenarioManager_DialogCreateEditMPScenario_NewScenario
{
  #keys: '[11122.0.37341038]'
  Body:
  [*
    // New scenario
    this.SetAdvanced();
    
    strategy := select(ScenarioManager, Strategy, strategy, strategy.Name() = Translations::MP_GlobalParameters_DefaultStrategyName() );
    if( not isnull( strategy ) )
    {
      SelectionStrategy.Data( strategy );
    }
    
    result := this.DoModal( parent );
    scenario := null ( Scenario );
    
    if ( result > 0 )
    {
      scenario := owner.CreateScenarioMP( scenarionode,
                                          EditorScenarioName.Text(),
                                          EditorAssumption.Text(),
                                          EditorComment.Text(),
                                          RadioButtonGroupStorageState.BoundValue(),
                                          '',
                                          guard( SWF_DataHolderCurrentUser.Data().Name(), '' ) );
    
      kbfullid := SelectionKBBranch.Data();
      if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_New() )
      {
        this.InstantiateAndSelectKB( scenario );
      }
      else if ( RadioButtonGroupMode.BoundValue() = GlobalParameters_MP::GetKB_CreateCopy() )
      {
        this.CopyAndSelectKB( SelectionKBBranch.Data(), scenario );
      }
      else
      {
        ApplicationLibMacroPlanner.SelectKB( scenario, kbfullid );
      }
      
      if( not isnull( SelectionStrategy.Data() ) )
      {
        scenario.SelectedStrategy( relset, SelectionStrategy.Data() );
      }
      
      // Set user preference on supply chain wizard launch
      owner.LaunchInitializationWizardAtScenarioCreation( Dialog.CheckBoxLaunchSupplyChainWizard().Checked() );
      
    }
    
    isselected := ApplicationLibMacroPlanner.SelectScenario( scenario );
    if ( isselected )
    {
      /* Is important to set active dataset on FormScenario.
         Without setting it, the auto import will import data to the previous scenario instead of the new one.
         This happend because some propagation in Quintiq it not yet done while we fire the import method.
      */
      ApplicationLibMacroPlanner.SelectScenario( scenario, this );
    
      ApplicationLibMacroPlanner.SupplyChainDiagramSetSupplyChainView( MacroPlan );
      if ( not isnull( DataHolderView.Data() ) )
      {
        feedback := ''
        DataHolderView.Data().RestoreDefaultLayout( feedback );
      }
    }
    
    return scenario;
  *]
}