;** Pesq_Pal ******************************************************************
;*  Relacao de Script's que usam determinada Palavra                          *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 16/09/1996 por Anivel Augusto Rodrigues.
;Ultima Alteracao: 30/07/2003 por Anivel Augusto Rodrigues.
;Motivo Alteracao: Novos Recursos

;*******************************************************************************
;*  Rotina para mostrar as horas                                               *
;*******************************************************************************
Proc Tempohrs(tini)
private tini,hrs,seg,h,m,s, tfim

tfim=ticks()
if tfim<tini
   then seg=(86400000-tini)
        seg=(seg+tfim)/1000
   else seg=(tfim-tini)/1000
endif

h=seg/3600
m=(h-int(h))*60
s=(m-int(m))*60

hrs=AlinhM(StrVal(int(h)),2)+":"+
    AlinhM(StrVal(int(m)),2)+":"+
    AlinhM(StrVal(Round(s,0)),2)
return hrs
Endproc ; (Tempohrs)

;*******************************************************************************
;* MASCARA                                                                     *
;*******************************************************************************
Proc Mascara()
@ 04,3 ?? "                 0                       50                        100% "
@ 05,3 ?? "                +----------------------------------------------------+  "
@ 06,3 ?? "        Pastas: İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ  "
@ 07,3 ?? "                +----------------------------------------------------İ  "
@ 08,3 ?? "       Scripts: İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ  "
@ 09,3 ?? "                +----------------------------------------------------+  "
@ 12,3 ?? "+ Tempo -+      +----------------------------------------++ Script --+  "
@ 13,3 ?? "İ00:00:00İ      İ                                        İİ          İ  "
@ 14,3 ?? "+--------+      +----------------------------------------++----------+  "
Array Porcent[3]
Array Coluna[3]
EndProc

Proc Limpa_Pasta(wl,wa)
@ wl,20 ?? "İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ"
Porcent[wa]=0
Coluna[wa] =20
EndProc

Proc barra(wl,wa,vc,vt)
While Porcent[wa]<=Int(((vc/vt)*100))
  Coluna[wa]=Coluna[wa]+1
  @ wl, Coluna[wa] ?? "İ"
  Porcent[wa]=Porcent[wa]+2
EndWhile
EndProc    ; (Mascara)

;*******************************************************************************
; Rotina Restruturacao                                                         *
;*******************************************************************************
Proc Relaciona()
tini=ticks()

Empty("\\Sistemas\\Utilitar\\Pesq_Pal")
ClearAll

Mascara()
Limpa_Pasta(08,1)
@ 06,8 ?? Format("W2,AR",StrVal((PASTA_FIM+1)-PASTA_INI))
For wi From PASTA_INI to PASTA_FIM
  wcs=1
  Barra(06,1,wi,PASTA_FIM)

  For wis From 1 to wcs
    Aguarde("Aguarde, Verificando Scripts")
    Limpa_Pasta(08,3)
    Caminho=Diretorio[wi]
    @ 5,5 ?? spaces(2)
    @ 12,20 ?? " Pasta ["+StrVal(wi)+"] -----------------------"
    @ 13,20 ?? Completa(Caminho,40," ")
    If DirExists(Caminho)=0 Then Loop EndIf

    SetDir Caminho

    If IsTable("List") Then Delete "List" EndIf

    comando="del *.bak"
    @ 22,0 Run NoRefresh comando

    {Tools} {Info} {Inventory} {Scripts} {}

    If Not IsTable("List") Or
       IsEmpty("List")
       Then Loop
    EndIf

    NR = NRecords("List")
    @ 08,7 ?? Format("W2,AR",StrVal(NR))
    @ 08,7
    
    View "\\Sistemas\\Utilitar\\Pesq_Pal"
    Coedit "List"
    Scan For Not IsBlank([Name])
        @ 13,63 ?? Completa([Name],8," ")
        
        If MODO = "Menu" 
           Then If Upper([Name]) = "MENUPRI"
                   Then Loop 
                EndIf
        EndIf   

        If [Name]<>"Pesq_pal" And [Name]<>"Savevars"
           Then ENCONTRADO=False

                Editor Open Diretorio[wi]+"\\"+[Name]+".sc"
                If SysMode()="Script"
                   Then Editor Find PALAVRA
                        If RetVal
                           Then ENCONTRADO=True
                        EndIf
                        Menu {Cancel} {Yes}
                   Else Mensagem("N„o pode ser aberto este arquivo -> "+[Name])
                EndIf
                If ENCONTRADO
                   Then Moveto "\\Sistemas\\Utilitar\\Pesq_Pal"
                        End
                        Down
                        [Diretorio]=Diretorio[wi]
                        [Script   ]=Upper([List->Name])
                EndIf
        EndIf
        Moveto "List"
        Barra(08,3,Recno(),NR)
        @ 13,04 ?? Tempohrs(tini)
    EndScan
    
    Do_It!
    ClearAll
    Delete "List"
    @ 13,63 ?? Completa("Ok !",8," ")

  EndFor
EndFor
ClearAll
LimpAguarde()
EndProc    ; (Reestrutura)

;*******************************************************************************
; Rotina pegar posicao da linha                                                *
;*******************************************************************************
Proc Posicao()
Home
Editor Info to InfoArray
ci=InfoArraY["CHARPOS"]

End
Editor Info to InfoArray
cf=InfoArraY["CHARPOS"]

Editor Select ci cf
Editor Extract to ELinha
EndProc           ; (Posicao)

;*******************************************************************************
; Rotina Procura Diretorios                                                    *
;*******************************************************************************
Proc MontaDiretorios()
ClearAll
Aguarde("Aguarde, Verificando Pastas")
DynArray Diretorio[]
DynArray Array_Diretorios[]

Lista_Diretorio(SubStr(Directory(),1,2)+"\\Sistemas")
wc=0
While wc<DynArraySize(Array_Lista_Diretorios)
  wc=wc+1
  Array_Diretorios[wc]=Format("W3,AR",wc)+": "+Array_Lista_Diretorios[wc]
  Diretorio[wc]       ="\\SISTEMAS\\"+Array_Lista_Diretorios[wc]
EndWhile
Release Vars Array_Lista_Diretorios

EndProc    ; (MontaDiretorios)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA    =""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_TEXTO"         : Campo="NO"
            Case Campo="TG_INICIAL"       : Campo="TG_TEXTO"
            Case Campo="TG_FINAL"         : Campo="TG_INICIAL"
            Case Campo="YES" Or Campo="NO": Campo="TG_INICIAL"
          EndSwitch
     Case (Evento["KeyCode"] <= -104 And Evento["KeyCode"] >= -113) Or 
           Evento["KeyCode"]  = -139 Or  Evento["KeyCode"]  = -140:
           SYS_TECLA_ACIONADA=Evento["KeyCode"]
           Seta_Tecla_Acionada()
           CancelDialog
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_TEXTO"   :Campo="TG_INICIAL"
                         PALAVRA=ControlValue("TG_TEXTO")
                    Case Campo="TG_INICIAL" :Campo="TG_FINAL"
                         PASTA_INI=ControlValue("TG_INICIAL")
                    Case Campo="TG_FINAL"   :Campo="YES"
                         PASTA_FIM=ControlValue("TG_FINAL")
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
	Case Campo="TG_TEXTO":
			 MSG_CAMPO="Digite o Texto desejado"
  Case Campo="TG_INICIAL":
       MSG_CAMPO="Informe o n£mero da Pasta Inicial"
  Case Campo="TG_FINAL":
       MSG_CAMPO="Informe o n£mero da Pasta Final"
  Case Campo="TG_PASTAS":
       MSG_CAMPO="."
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc      ; (SD_Dialog)

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"
LimpAguarde()
If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="" EndIf

If NOMEMPRESA=""
   Then MODO = "Interno" 
   Else MODO = "Menu"
EndIf   

PassWord("s01avclvi")
PassWord("FechaSys")
PassWord("t01avivcl")
MontaDiretorios()
PASTA_INI=1
PASTA_FIM=wc
While True
  Janela_Show=1
  ShowDialog "Pesquisa Texto em Script's" Proc "SD_Dialog"
    Trigger "OPEN","ARRIVE"
    Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140    
     @ 05,09   Height 17 Width 68

     Label  @ 01,00 "Texto: " for "TG_TEXTO"
     Accept @ 01,08 Width 43 "A40" picture "!*!" Tag "TG_TEXTO" to PALAVRA

     Label  @ 03,00 "N§ Pasta Inicial"  For "TG_INICIAL"
     Accept @ 03,18 Width 05 "S" Picture "#*#" Tag "TG_INICIAL"   To PASTA_INI

     Label  @ 04,00 "N§ Pasta Final  "  For "TG_FINAL"
     Accept @ 04,18 Width 05 "S" Picture "#*#" Tag "TG_FINAL"   To PASTA_FIM

     PickDynArray @7,01 Height 05 width 63
      Columns 4
       Array_Diretorios
        Tag "TG_PASTAS"
         To ArrayElement
     Label @ 06,00 "Pastas"  For "TG_PASTAS"

       Pushbutton @ 13,17 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
       Pushbutton @ 13,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  PASTA_OK=True
  If PASTA_FIM<1 Or IsBlank(PASTA_FIM) Then PASTA_OK=False EndIf
  If PASTA_INI<1 Or IsBlank(PASTA_INI) Then PASTA_OK=False EndIf
  If PASTA_INI > wc                    Then PASTA_OK=False EndIf
  If PASTA_FIM > wc                    Then PASTA_OK=False EndIf
  If PASTA_INI > PASTA_FIM             Then PASTA_OK=False EndIf
  If Not PASTA_OK
     Then Mensagem("Pasta Inicial ou Final inv lida !")
          Loop
  EndIf

;;If Not Verifica_Usuario() Then Loop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf
  
  JANELAR("Pesquisa Texto",03,03,15,75)
  MontaDiretorios()
  Relaciona()

  If IsEmpty("\\Sistemas\\Utilitar\\Pesq_Pal")
     Then MENSAGEM("N„o existem script's com o texto")
          Loop
  EndIf

  IMPRIREL("\\Sistemas\\Utilitar\\Pesq_Pal","R")

  Empty"\\Sistemas\\Utilitar\\Pesq_Pal"
  Echo Normal
  Echo Off

EndWhile
ClearAll
Release Vars All
Release Procs All
SetDir "\\Sistemas\\Utilitar"
