home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase Pro v7.0 / DATA1.CAB / Program_Core / Cat2prj.prg next >
Encoding:
Text File  |  1997-11-20  |  3.4 KB  |  130 lines

  1. //--------------------------------------------------------------
  2. //
  3. //  cat2prj.prg
  4. //
  5. //  This utility can convert a Visual dBASE 5.x catalogs to 
  6. //  a Visual dBASE 7.0 project file. You can call it as a 
  7. //  function with 2 optional parameters. If you call it with 
  8. //  no parameters, a dialog opens for selecting the catalog 
  9. //  to convert. The function returns true if it creates a 
  10. //  project file without error.
  11. //
  12. //  Syntax:
  13. //
  14. //      cat2prj( [<expC: Catalog file name>] [,<expL: overwrite] )
  15. //
  16. //  Example: To create equipmnt.prj from equipmnt.cat and 
  17. //           overwrite an existing equipmnt.prj without 
  18. //           confirmation.
  19. //              
  20. //  
  21. //      cat2prj( "equipmnt.cat", true )
  22. //
  23. //
  24. //  Visual dBASE Samples Group
  25. //
  26. //  $Revision:   1.2  $
  27. //
  28. //  Copyright (c) 1997, Borland International, Inc. 
  29. //  All rights reserved.
  30. //
  31. //---------------------------------------------------------------//
  32. // 
  33.  
  34. function cat2prj( sCat, bOverwrite )          
  35.    // Call create project function if catalog and 
  36.    // project file names are valid.
  37.    local   bOK, sPrj
  38.    private prCat
  39.    private prOverwrite
  40.  
  41.    bOK         = false
  42.    prCat       = sCat
  43.    prOverwrite = bOverwrite
  44.    filePrj     = new File()
  45.  
  46.    if ( PCOUNT() == 0 OR TYPE( "prCat" ) <> "C" )
  47.       sCat = UPPER( GETFILE("*.CAT", ;
  48.                             "Convert Catalog to Project", ;
  49.                              true,false) )
  50.    else
  51.       sCat = UPPER( sCat )
  52.    endif
  53.  
  54.    if ( PCOUNT()  < 2 OR TYPE( "prOverwrite" ) <> "L" )
  55.       bOverwrite = false
  56.    endif
  57.  
  58.    if ( FILE( sCat ) AND ( RIGHT( sCat, 4 ) == ".CAT") )
  59.       sPrj = SUBSTR( sCat, 1, LEN( sCat ) - 3 ) + "PRJ"
  60.  
  61.       if ( FILE( sPrj ) AND ( NOT bOverwrite ) )
  62.          bOK = ( MSGBOX( sPrj + ;
  63.                    " already exists. Overwrite it?", ;
  64.                    "Already Exists", ;
  65.                    4 + 32) == 6 )
  66.       else
  67.          bOK = true
  68.       endif
  69.  
  70.       if ( bOK )
  71.          bOK = createPrj( sCat, sPrj )
  72.       endif
  73.  
  74.    endif
  75.  
  76. return ( bOK )
  77.  
  78. function createPrj( sCat, sPrj )
  79.    // create a project file from a catalog table
  80.    local qCat, fPrj, sDefault
  81.  
  82.    sDefault = getDefault( sCat )
  83.    qCat = new Query()
  84.    qCat.sql = "SELECT * FROM '" + sCat + "'"
  85.    qCat.active = true
  86.    fPrj = new File()
  87.    fPrj.create( sPrj )
  88.    fPrj.writeLn( "Project File - generated "    + ;
  89.                  CMONTH( DATE() )              + " " + ;
  90.                  LTRIM( STR( DAY( DATE() ) ) ) + ", " + ;
  91.                  LTRIM( STR( YEAR( DATE() ) ) ) )
  92.    fPrj.writeLn( "" )
  93.    fPrj.writeLn( "[Project]" )
  94.    fPrj.writeLn( "DefaultDir=" + sDefault )
  95.    fPrj.writeLn( "MainProjectFileName=" )
  96.    fPrj.writeLn( "MostRecentSelectedFileName=" )
  97.    fPrj.writeLn( "" )
  98.    fPrj.writeLn( "[Contents]" )
  99.  
  100.    do while ( NOT qCat.rowset.endOfSet )
  101.       fPrj.writeLn( RTRIM( qCat.rowset.fields[1].value ) )
  102.       qCat.rowset.next()
  103.    enddo
  104.  
  105.    qCat.active = false
  106.    fPrj.close()
  107.  
  108. return FILE( sPrj )
  109.  
  110. function getDefault( sCat ) 
  111.    // get default project directory
  112.    local bFullpath, sDefault
  113.  
  114.    CREATE SESSION
  115.    bFullpath = SET("FULLPATH")=="ON"
  116.    SET FULLPATH ON
  117.    USE (sCat)
  118.    sDefault = LOWER( DBF() )
  119.    SET FULLPATH OFF
  120.    sDefault = SUBSTR( sDefault, 1, ;
  121.                       LEN(sDefault) -  ( LEN( DBF() ) - 1 ) )
  122.  
  123.    if ( bFullpath )
  124.       SET FULLPATH ON
  125.    endif
  126.  
  127.    CLOSE TABLES
  128.  
  129. return ( sDefault )
  130.