Quintiq file version 2.0
#parent: #root
Method ExportDataToExcelOrDataManager (
  internal[GUIComponent] parent
) id:Method_DialogEDIExport_ExportDataToExcelOrDataManager
{
  #keys: '[108486.1.1111206054]'
  Body:
  [*
    // Export data to excel
    
    Dialog.ConfigureComponentsForExport();
    defaultImportProfile := shadow( MPSync.DefaultImportProfile() );
    Dialog.Data( defaultImportProfile );
    result := Dialog.DoModal( parent );
    
    // UserData is set by text box responses depending on whether there is a user-specified path.
    exportpath := ifexpr( EditorImportExportPath.UserData() = 0 , EditorImportExportPath.Text(), '' );
    binaryvalues := construct( BinaryValues);
    brokernames := construct( Strings );
    smbinaryvalues := construct( BinaryValues );
    smbrokernames := construct( Strings );
    userimportprofilevalues := construct( BinaryValues );
    userimportprofilebrokers := construct( Strings );
    
    isbinaryexport := true ;
    //Format to correct format
    Dialog.FormatPath( exportpath );
    
    if( result > 0 )
    {
      Dialog.Data().Commit();
      
      is3DDrive := RadioButtonGroupExcelOrDataManager.BoundValue() = MPSyncUtility::ID_Source_3DDrive();
      isDEF := RadioButtonGroupExcelOrDataManager.BoundValue() = MPSyncUtility::ID_Source_DEF();
    
      if( isDEF )
      {
        Dialog.ExportToDataManager();
      }
      else // Export to Excel or 3DDrive
      {
        //Preset calendarimportexport.ExportData
        if ( Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Capacities() ))
        {
          exportid := Key::NextPersistentKey();
          ApplicationLibMacroPlanner.LabelExportID().Text([String] exportid );
          MacroPlan.CalendarImportExport().Export( exportid, MacroPlan.CalendarRegistry().GetAllCalendars() );
        }
       MacroPlan.Export( Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_SupplyChainParameters() ),   // general
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_GlobalParameters() ),        // globalparameters
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Periods() ),                 // periods
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_InventorySpecifications() ), // inventoryspecifications
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_InventorySupplies() ),       // inventorysupplies
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Products() ),                // products
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Recipes() ),                 // recipes
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Forecast() ),             // salesdemands
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_ServiceLevels() ),           // servicelevels
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Campaigns() ),               // campaigns and transitions
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Entities() ),                // entities
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Costs() ),                   // entitiescosts
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Lanes() ),                   // lanes
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Routings() ),                // routings
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Capacities() ),              // stockingpointcapacities and unitcapacities
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_SupplySpecifications() ),    // supplyspecifications
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Actuals() ),                 // actuals pispip and actual unit periods
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Feedback() ),                // feedbacks
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_OptimizerPuzzle() ),           // optimier puzzles
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_PostponementSpecAndFulfillmentRestriction() ),           // Postponement and fulfillment restriction
                          Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_CustomerOrder() ),           // Customer order
                          isbinaryexport, //isbinaryexport
                          is3DDrive,
                          DataHolderDirectoryFileItem.Data(),
                          binaryvalues,
                          brokernames
                        );  
        
        ScenarioManager.Export( Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Strategies() ), 
                                Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Accounts() ), 
                                Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_Bookmarks() ), 
                                Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_KPISetting() ),  
                                isbinaryexport, is3DDrive, DataHolderDirectoryFileItem.Data(), 
                                smbinaryvalues, smbrokernames );
    
        MPSync.Export( Dialog.GetIsIncluded( MPSyncUtility::ID_ObjectGroup_ImportProfiles() ),
                                             is3DDrive, DataHolderDirectoryFileItem.Data(),
                                             userimportprofilevalues, userimportprofilebrokers );
                                             
        if( not is3DDrive ) // 3DDrive already exported on server side
        {         
          // Macroplan dataset                        
          this.WriteToDestinationFile( exportpath, binaryvalues, brokernames );
          // ScenarioManager dataset
          this.WriteToDestinationFile( exportpath, smbinaryvalues, smbrokernames );
          // MPSync dataset
          this.WriteToDestinationFile( exportpath, userimportprofilevalues, userimportprofilebrokers );
        }
      }
    
    }
  *]
}
