Quintiq file version 2.0
#parent: #root
Method ExportAll () id:Method_ApplicationLibMacroPlanner_ExportAll
{
  #keys: '[108486.0.1580753051]'
  Body:
  [*
    //Export xls files to specified location
    path := Application.GetSaveFileName();
    
    if( path <> '' )
    {
      pos := 0;
      last := 0;
    
      while( pos > -1 )
      {
        last := pos + 1;
        pos := path.FindString( '\', last );
      }
    
      path := path.SubString(0, last );
    }
    
    importbrokers := selectset( Domain,
                                EDIDefinitionManager.BrokerDefinitions,
                                broker,
                                broker.Name().LikeUserLocale( 'MP_Import' ) );
    
    if( path <> '' )
    {
      traverse( Domain,
                EDIDefinitionManager.BrokerDefinitions,
                broker,
                broker.Name().LikeUserLocale( 'MP_Export' ) )
      {
    
        //find corresponding import broker
        importbrokername := broker.Name().ReplaceAll( 'MP_Export', 'MP_Import' );
        importbroker := select( importbrokers, Elements, e, e.Name() = importbrokername );
    
        xlsname := broker.Name().SubString( 9, broker.Name().Length() - 15 ) + '.xlsx';
        if ( not isnull( importbroker ) )
        {
          xlsname := importbroker.Source().astype( EDIXLSLinkDefinition ).FileName();
        }
    
        filename := path + xlsname;
    
        mdsdefinition := broker.MDSDefinition();
        mdshandle := this.MDSHandle(mdsdefinition.Name())
    
        clientfile := Application.GetClientFile( filename );
    
        data := broker.GetFullDestinationData(mdshandle.MDSID().MDSKey());
    
        tablegroup := TableGroupHandle::Create(data);
        XLS::SaveTableGroup( tablegroup, clientfile.LocalFileName(), true )
    
        Application.TransferToClient(clientfile);
        Application.RemoveLocalCopy(clientfile);
    
      }
      info('xls file exported to:', path );
    }
  *]
}
