hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
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
Quintiq file version 2.0
#parent: #root
Method EditKBBranch (
  Scenario scenario,
  String kbname
) id:Method_ApplicationLibMacroPlanner_EditKBBranch
{
  #keys: '[11122.0.58944389]'
  Body:
  [*
    //Edit a kb branch with active dataset
    componentmds := ComponentMDS::CreateForLoadedMDSsOnly( Application );
    mdsinstance := selectobject( componentmds, ComponentMDSKinds.ComponentMDSInstances, m, m.MDSID().Equals( scenario.DatasetMDSID() ) );
    mdshandle := mdsinstance.GetMDSHandle();
    
    kbinfo := null( MDSObjectKB );
    if ( scenario.istype( ScenarioMP ) )
    {
      kbinfo := select( mdsinstance.GetMDSHandle().AsMacroPlan().MDSMacroPlan(), MDSKBs, kb, kb.Name().ToUpper() = kbname.ToUpper() );
    }
    
    
    
    kbfullid := KBFullID::Create( kbinfo.Domain(), kbinfo.Name(), kbinfo.Branch(), kbinfo.Version(), kbinfo.ChangeNr() );
    editor := CKBEditor::Create();
    ckbhandle := editor.LoadNewestKBChange( kbfullid );
    
    // lock
    editor.LockKB( ckbhandle.CKB().ID(), mdshandle );
    
    // edit
    dlg := construct( dlgKnowledgeBaseEditor );
    result := dlg.EditKnowledgeBase( mdshandle, ckbhandle, this );
    if ( result > 0 and dlg.Data().NeedsSave() )
    {
      // save
      editor.SaveMDSKB( mdshandle, kbfullid.KBID(), 'Edit branch' );
    
      // delete old KB
      infos := editor.GetKBStructure( kbfullid.KBID() );
      traverse( infos, Elements.KBFullID, i, i.Branch() = kbinfo.Branch() and i.ChangeNr() < kbinfo.ChangeNr() )
      {
        editor.DeleteKBChange( i );
      }
    }
    else
    {
      editor.UnlockKB( ckbhandle.CKB().ID(), mdshandle );
    }
    
    //give some time for kbinfo.ChangeNr() to get updated
    Kernel.Sleep( 1000 );
    ScenarioManager.UpdateScenarioKBInfo( scenario, kbinfo.Name(), kbinfo.Branch(), kbinfo.ChangeNr(), scenario.State(), scenario.KBDescription() )
  *]
}