Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CleanUp ( 
 | 
  String selectedkb 
 | 
) id:Method_FormKBManagement_CleanUp 
 | 
{ 
 | 
  #keys: '[11660.0.301399095]' 
 | 
  Body: 
 | 
  [* 
 | 
    //clean up 
 | 
    dlg := construct( DialogNumberOfKBToKeep ); 
 | 
    dlg.LabelSelectedKB().Text( selectedkb ); 
 | 
     
 | 
    retvalue := dlg.DoModal(  this ); 
 | 
     
 | 
    if ( retvalue > 0 and not isnull( MacroPlan ) ) 
 | 
    { 
 | 
      nr :=  ApplicationLibMacroPlanner.FormatStringToReal( dlg.EditorNr().Text() ); 
 | 
      strings := StringListKnowledgeBase.GetSelectedLine().Tokenize( ':'); 
 | 
     
 | 
      if ( strings.Size() = 4 and nr >= 0 ) 
 | 
      { 
 | 
        name := strings.Element( 1 ); 
 | 
        editor := CKBEditor::Create(); 
 | 
     
 | 
        kb := select( MacroPlan.MDSMacroPlan(), MDSKBs, kb, kb.Name().ToUpper() = ScenarioManager.CompanyKBName().ToUpper() ); 
 | 
        kbfullid := KBFullID::Create( kb.Domain(), kb.Name(), kb.Branch(), kb.Version(), kb.ChangeNr() ); 
 | 
     
 | 
        infos := editor.GetKBStructure( kbfullid.KBID() ); 
 | 
        highestid := max( infos, Elements.KBFullID, i, i.Branch() = name and i.ChangeNr().IsFinite() and i.ChangeNr() > 0, i.ChangeNr() ); 
 | 
     
 | 
        if ( highestid.IsFinite() and highestid > 0 ) 
 | 
        { 
 | 
          toberemoved := highestid - nr; 
 | 
          tobedeletedset := selectset ( infos, Elements.KBFullID, i, i.Branch() = name and i.ChangeNr() <= toberemoved, true ) 
 | 
          traverse ( tobedeletedset, Elements, el ) 
 | 
          { 
 | 
            editor.DeleteKBChange( el ); 
 | 
          } 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |