Jump to content
Fivewin Brasil

Snippets ddos comandos de Fivewin para VSCode


giovanyvecchi

Recommended Posts

Crie um Snippet do projeto, não global para colocar os campos das suas tabelas DBF

Para gerar o snippet use o código abaixo

//Classe Dbf2Snippet / 13/05/20 - 17:38:59
#Include "FiveWin.ch"

FUNCTION DBF_TO_SNIPPET()
  Local lc_oDbf2Snippet

  lc_oDbf2Snippet := Dbf2Snippet():New()
  lc_oDbf2Snippet:Dbf2Snippet_Start()
  lc_oDbf2Snippet:End()

RETURN NIL

Class Dbf2Snippet

  Data aFilesDbfRota
  Data cSnippetTxt
  Data cTxtFileSalva


  Method New() Constructor
  Method End()

  Method Dbf2Snippet_Start()
  Method Dbf2Snippet_BuildTable(f_cDbfFile)

EndClass
//-----------------------------------------------------------------------------
Method New() Class Dbf2Snippet

    ::aFilesDbfRota         := {}
    ::cSnippetTxt           := ""

    ::cTxtFileSalva         := Hb_DirTemp()+"SnippetDBF.txt"

Return Self
//-----------------------------------------------------------------------------
Method End() Class Dbf2Snippet

Return Nil
//-----------------------------------------------------------------------------
Method Dbf2Snippet_Start() Class Dbf2Snippet
  Local lc_cTxtSelFiles
  Local lc_iFor := 0

  lc_cTxtSelFiles := "Selecione as Tabelas DBFs"

  ::aFilesDbfRota := MY_AGETFILES( "Tabelas DBFs (*.dbf)|*.dbf|",;
                                  lc_cTxtSelFiles,,"SeuProjeto.ini","lc_cPastaDbf2Snippet")

  If Len(::aFilesDbfRota) == 0
    MsgStop("Nenhum arquivo foi selecionado.",;
            "Procedimento Abortado.")
  
    Return Nil
  EndIf  
                                  
  //xbrowse(::aFilesDbfRota)

  For lc_iFor := 1 To Len(::aFilesDbfRota)
    ::cSnippetTxt += ::Dbf2Snippet_BuildTable(::aFilesDbfRota[lc_iFor])
  Next

  hb_memowrit(::cTxtFileSalva,::cSnippetTxt)

  WinExec("Notepad.exe "+::cTxtFileSalva)

Return Nil
//-----------------------------------------------------------------------------
Method Dbf2Snippet_BuildTable(f_cDbfFile) Class Dbf2Snippet
  Local lc_cSnippetCreate := ""
  Local lc_aStructDbf := {}, lc_aFieldNames := {}
  Local lc_iFor := 0
  Local lc_cDbfName := hb_FNameNameExt(f_cDbfFile)
  Local lc_cDbfDisp := hb_FNameName(f_cDbfFile)
  Local lc_cIndexName := StrTran(Lower(f_cDbfFile),".dbf",".cdx")

  MemVar TMPDBF

  //? lc_cIndexName

  If !File(lc_cIndexName)
    USE (f_cDbfFile) alias TMPDBF NEW EXCLUSIVE VIA "DBFCDX"
  Else
    USE (f_cDbfFile) INDEX (lc_cIndexName) alias TMPDBF NEW EXCLUSIVE VIA "DBFCDX"
  EndIf
    If NetErr()
    MsgStop("Erro ao tentar abrir o DBF "+f_cDbfFile,;
            "Procedimento abortado")
    Return Nil
  EndIf

  //XBROWSE("TMPDBF")

  lc_aStructDbf := TMPDBF->(dbStruct())

  For lc_iFor := 1 To Len(lc_aStructDbf)
    aadd(lc_aFieldNames,lc_aStructDbf[lc_iFor,1])
  Next

  lc_aFieldNames := ASort(lc_aFieldNames)

  lc_cSnippetCreate  := Space(2)+Chr(34)+"File "+lc_cDbfName+Chr(34)+":{"+CRLF
  lc_cSnippetCreate  += Space(2)+Chr(34)+"prefix"+Chr(34)+":"+chr(34)+"_DB_"+lc_cDbfDisp+chr(34)+","+CRLF
  lc_cSnippetCreate  += Space(2)+Chr(34)+"body"+Chr(34)+": ["+CRLF

  lc_cSnippetCreate  += Space(4)+Chr(34)+"${1|"

  For lc_iFor := 1 To Len(lc_aFieldNames)
    lc_cSnippetCreate += lc_aFieldNames[lc_iFor]
    If lc_iFor != Len(lc_aFieldNames)
      lc_cSnippetCreate += ","
    EndIf
  next

  lc_cSnippetCreate  += "|}"+Chr(34)+","+CRLF
  lc_cSnippetCreate  += Space(4)+"],"+CRLF

  lc_cSnippetCreate  += Space(4)+Chr(34)+"description"+Chr(34)+":"+Chr(34)+"Dbf "+lc_cDbfName+Chr(34)+CRLF
  lc_cSnippetCreate  += Space(2)+"},"+CRLF


  TMPDBF->(dbCloseArea())

Return lc_cSnippetCreate
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
FUNCTION MY_AGETFILES(f_cMask, f_cTitle, f_nDefaultMask, f_cInitialFile, f_cFlagDir ) 
  Local lc_aRetFiles := {}, cPastaDir := "", lc_cInitDir := ""

  If !Hb_IsNil(f_cInitialFile)
    f_cInitialFile := Dir_Prog()+f_cInitialFile
    lc_cInitDir := AllTrim(GetPvProfString( "PASTAS_SALVAS", f_cFlagDir, "", f_cInitialFile))
  EndIf 

  lc_aRetFiles := aGetFiles( f_cMask, f_cTitle, f_nDefaultMask, lc_cInitDir,,.T. )

  If !Hb_IsNil(f_cInitialFile) .and. Len(lc_aRetFiles) > 0
    //cPastaDir := Lfn2SfnEx(lc_aRetFiles[1])
    cPastaDir := Lfn2SfnEx(SubStr(lc_aRetFiles[1],1,Rat("\",lc_aRetFiles[1])))
    WritePProString( "PASTAS_SALVAS", f_cFlagDir, cPastaDir, f_cInitialFile)
  EndIf 
 

RETURN lc_aRetFiles

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...