;** SETPASTA *******************************************************************
;*  Configurador de caminho padrao        
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 10/06/2011 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /     por 

;*******************************************************************************
;* Rotina ShowDialog para Imprimir em arquivo                                  *
;*******************************************************************************
Proc SD_PASTA(Disparo,Campo,Evento,Elemento)
Private Disparo,Campo,Evento,Elemento

Temp=True
TECLA    =""
MSG_CAMPO=""

If Disparo="OPEN"
   Then AoCriarShowDialog()
        Campo="TG_PASTA"
EndIf
If Disparo="SELECT"
   Then Switch
          Case Campo="TG_DRIVES"      : Campo="TG_PASTAS"
               VSDGDRIVE=ControlValue("TG_DRIVES")
               VSDGPASTA=VSDGDRIVE+"\\"
          Case Campo="TG_PASTAS"    :
               If SearchFrom("..\\",ControlValue("TG_PASTAS"),1)>0
                  Then pospasta=3
                       For ipasta From (Len(VSDGPASTA)-1) to 1 Step -1
                         If SubStr(VSDGPASTA,ipasta,1)="\\"
                            Then pospasta=ipasta
                                 QuitLoop
                         EndIf
                       EndFor
                       VSDGPASTA=SubStr(VSDGPASTA,1,SearchFrom("\\",VSDGPASTA,pospasta))
                  Else If SearchFrom("\\",ControlValue("TG_PASTAS"),1)>0
                          Then VSDGPASTA=VSDGPASTA+ControlValue("TG_PASTAS")
                       EndIf
               EndIf
        EndSwitch
EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Temp=False
   Switch
     Case Evento["KeyCode"] =  27:
          Switch
            Case Campo="TG_PASTA"           : Campo="NO"
            Case Campo="TG_DRIVES"          : Campo="TG_PASTA"
            Case Campo="TG_PASTAS"          : Campo="TG_DRIVES"
            Case Campo="YES" Or Campo="NO"  : Campo="TG_PASTA"
          EndSwitch
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_PASTA"       : Campo="YES"
                         VSDGPASTA=ControlValue("TG_PASTA")
                    Case Campo="TG_DRIVES"      : Campo="TG_PASTAS"
                         VSDGDRIVE=ControlValue("TG_DRIVES")
                         VSDGPASTA=VSDGDRIVE+"\\"
                    Case Campo="TG_PASTAS"    :
                         If SearchFrom("..\\",ControlValue("TG_PASTAS"),1)>0
                            Then pospasta=3
                                 For ipasta From (Len(VSDGPASTA)-1) to 1 Step -1
                                   If SubStr(VSDGPASTA,ipasta,1)="\\"
                                      Then pospasta=ipasta
                                           QuitLoop
                                   EndIf
                                 EndFor
                                 VSDGPASTA=SubStr(VSDGPASTA,1,SearchFrom("\\",VSDGPASTA,pospasta))
                            Else If SearchFrom("\\",ControlValue("TG_PASTAS"),1)>0
                                    Then VSDGPASTA=VSDGPASTA+ControlValue("TG_PASTAS")
                                 EndIf
                         EndIf
                  EndSwitch
          EndIf
   EndSwitch
EndIf
RefreshDialog

If SubStr(ControlValue("TG_PASTA"),Len(ControlValue("TG_PASTA")),1)<>"\\"
   Then VSDGPASTA=ControlValue("TG_PASTA")+"\\"
   Else VSDGPASTA=ControlValue("TG_PASTA")
EndIf

If SubStr(VSDGPASTA,2,1)=":"
   Then VSDGDRIVE=SubStr(VSDGPASTA,1,2)
   Else VSDGPASTA=VSDGDRIVE+VSDGPASTA
EndIf

Switch
  Case Campo="TG_PASTA":
       MSG_CAMPO="Informe o caminho padrĈo desejado !"
  Case Campo="TG_DRIVES":
       MSG_CAMPO="Selecione o drive desejado !"
       TECLA=""+"=Selecionar  "
  Case Campo="TG_PASTAS":
       MSG_CAMPO="Selecione a pasta desejda !"
       TECLA=Chr(27)+""+Chr(26)+"=Selecionar  "
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
;AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
;;Setar antes de chamar este script a variavel Tipo_ext
;;Tipo_Ext =".XXX"

If Not IsAssigned(VSDGPASTA)   Then VSDGPASTA=""   EndIf
If Not IsAssigned(Tipo_Ext)    Then Tipo_Ext=""    EndIf

DynArray Array_Drives[]

SysInfo Drives To Array_Drives
Switch
  Case SubStr(VSDGPASTA,2,1)=":" : VSDGDRIVE=SubStr(VSDGPASTA  ,1,2)
  OtherWise                      : VSDGDRIVE=SubStr(Directory(),1,2)
EndSwitch

ShowDialog "Configurador de caminho padrĈo" Proc "SD_PASTA"
 Trigger "OPEN","ARRIVE","SELECT"
  Key "ENTER","ESC"
   @ 03,12   Height 20 Width 78

  Label  @ 01,00 "Caminho padrĈo para arquivos de ~r~etorno:"  For "TG_PASTA"
  Accept @ 02,01 Width 73 "A70"  Picture "!*!" Tag "TG_PASTA" To VSDGPASTA

  Label  @ 04,00 "~D~rives: " For "TG_DRIVES"
  PickDynArrayIndex @ 05,01 Height 10 width 06
   Columns 1
    Array_Drives
     Tag "TG_DRIVES"
      To VSDGDRIVE

  Label  @ 04,08 "~P~asta/Arquivos"  For "TG_PASTAS"
  PickFile @ 05,09 Height 10 Width 65
   Columns 4 
    VSDGPASTA+Tipo_Ext SHOWDIRS NOEXT
     Tag "TG_PASTAS"
      To VSDGPASTAS

  Pushbutton @ 16,25 width 11 "~O~k"         OK     Default Value "Ok" Tag "YES"        To BottonValue
  Pushbutton @ 16,38 width 11 "~C~ancela"    CANCEL                    Tag "NO"         To BottonValue

EndDialog
If Retval
  Then ConfOpcoes("Gravar")
EndIf
 
Release Vars Array_Drives 
Release Procs SD_PASTA
