yy
2023-09-25 232ba455849cce25063cea01638c3cbdac01bc98
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Quintiq file version 2.0
#parent: #root
Method OnOk () id:Method_DialogCreateEditScenario_OnOk #extension
{
  Body:
  [*
    // Disabled button to prevent the possibility of multiple firing
    
    macroPlanOld := MacroPlan;
    
    btnOK.Enabled( false, '' )
    
    // On ok execution, create new scenario, copy or edit
    this.ApplyChanges();
    
    data := DataHolderDialogData.Data();
    newscenario := null( Scenario );
    strategy := null( Strategy );
    
    // New version
    globalotdtable := GlobalOTDTable;
    testbusinesstype := "集团";
    if( data.IsCreateNewVersion() ){
      VersionControl::CreateNewSceneVersion( globalotdtable, testbusinesstype );
      }else{
        VersionControl::CopyVersion( globalotdtable, testbusinesstype );
        }
    versionname := VersionControl::GetVersionInfo( globalotdtable, testbusinesstype ).Element( 3 );
    
    // Get Version Name
    if( data.Name() = "" ){
      data.Name( versionname );
      }
    
    // 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() );
        scenario.EnableSync( data.EnableSync() );
        scenario.BusinessType( data.BusinessType() );
        scenario.IsKeyProduct( data.IsKeyProduct() );
        scenario.CreatePurchaseSupplyMaterial( data.CreatePurchaseSupplyMaterial() );
      }
      // If DatasetMDSID is set, it means the scenario
      // will be linked to an existing dataset
      else if( data.DatasetMDSID() <> Key::ZeroKey() )
      {
        sc := ScenarioManager.CreateScenarioMPFromDataset( data.Parent(),
                                                     data.Name(),
                                                     edtAssumption.Text(),
                                                     data.Comment(),
                                                     '',
                                                     data.DatasetName(),
                                                     data.DatasetMDSID(),
                                                     data.State() );
        sc.EnableSync( data.EnableSync() );
        sc.BusinessType( data.BusinessType() );
        sc.IsKeyProduct( data.IsKeyProduct() );
        sc.CreatePurchaseSupplyMaterial( data.CreatePurchaseSupplyMaterial() );
      }
      else
      {
        newscenario := ScenarioManager.CreateScenarioMP( data.Parent(),
                                                         data.Name(),
                                                         edtAssumption.Text(),
                                                         data.Comment(),
                                                         data.State(),
                                                         '',
                                                         ApplicationMacroPlanner.GetUserName() );
        newscenario.EnableSync( data.EnableSync() );
        newscenario.BusinessType( data.BusinessType() );
        newscenario.IsKeyProduct( data.IsKeyProduct() );
        newscenario.CreatePurchaseSupplyMaterial( data.CreatePurchaseSupplyMaterial() );
        strategy := data.SelectedStrategy();
      }
    }
    // Edit scenario
    else
    {
      data.WrappedInstance().Update( data.Name(), data.Comment(), data.State() );
      data.WrappedInstance().SelectedStrategy( relset, data.SelectedStrategy() );
      data.WrappedInstance().EnableSync( data.EnableSync() );
      data.WrappedInstance().BusinessType( data.BusinessType() );
      data.WrappedInstance().IsKeyProduct( data.IsKeyProduct() );
      data.WrappedInstance().CreatePurchaseSupplyMaterial( data.CreatePurchaseSupplyMaterial() );
    }
    
    // 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 ) );
      }  
    }
    
    macroPlanNew := MacroPlan;
    ManufactureLTImputation::Transfer( macroPlanOld, macroPlanNew );
    
    // sync data
    if( data.EnableSync() ) {
        MacroPlan::DoSync( macroPlanNew, 
                           data.BusinessType(), data.IsKeyProduct(), data.CreatePurchaseSupplyMaterial() ,GlobalOTDTable);
    }
    
    this.Close();
  *]
}