陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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 OnOk () id:Method_DialogCreateEditScenario_OnOk
{
  #keys: '[134266.1.2021821381]'
  Body:
  [*
    // Disabled button to prevent the possibility of multiple firing
    btnOK.Enabled( false, '' )
    
    // On ok execution, create new scenario, copy or edit
    this.ApplyChanges();
    
    data := DataHolderDialogData.Data();
    newscenario := null( Scenario );
    strategy := null( Strategy );
    
    // Copy scenario
    if( isnull( data.WrappedInstance() ) )
    {
      if(  DataHolderActionCopy.Data() )
      { 
        scenario := data.Parent().astype( ScenarioMP );
        strategy := data.SelectedStrategy();
             
        newscenario:= scenario.Copy( data.Parent(), data.Name(), edtAssumption.Text(),
                                     data.Comment(), data.State() );
        
                                  
      }
      // If DatasetMDSID is set, it means the scenario
      // will be linked to an existing dataset
      else if( data.DatasetMDSID() <> Key::ZeroKey() )
      {
        ScenarioManager.CreateScenarioMPFromDataset( data.Parent(),
                                                     data.Name(),
                                                     edtAssumption.Text(),
                                                     data.Comment(),
                                                     '',
                                                     data.DatasetName(),
                                                     data.DatasetMDSID(),
                                                     data.State() );
        
      }
      else
      {
        newscenario := ScenarioManager.CreateScenarioMP( data.Parent(),
                                                         data.Name(),
                                                         edtAssumption.Text(),
                                                         data.Comment(),
                                                         data.State(),
                                                         '',
                                                         ApplicationMacroPlanner.GetUserName() );
        
        strategy := data.SelectedStrategy();
      }
    }
    // Edit scenario
    else
    {
      data.WrappedInstance().Update( data.Name(), data.Comment(), data.State() );
      data.WrappedInstance().SelectedStrategy( relset, data.SelectedStrategy() );
    }
    
    // Post scenario creation
    // Set kb and strategy after creation of scenario and set the scenario as active
    if( not isnull( newscenario ) )
    {           
      newscenario.SelectedStrategy( relset, strategy ); 
      if ( not DataHolderActionCopy.Data() )
      {                                                                                                    
        ApplicationMacroPlanner.SelectScenario( newscenario.astype( ScenarioMP ) );
      }  
    }
    
    this.Close();
  *]
}