;** Simbolog *******************************************************************
;*  Manutencao Cadastro de Simbologias                                         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 12/03/2019 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()
while true
  Moveto [CodigoSimbologia]
  End
  SEQ  = [CodigoSimbologia]
  Down
  Down
  Moveto [CodigoSimbologia]
  
  While true
    SetaCorRegistro("Editar")
    
    TECLA=""
    AguardaTeclasPadrao()
    
    If Retval=-33
       Then
         ShowPopup " Fun‡”es " CENTERED
          "~A~tualiza Itens"  : " Aplicar as altera‡”es no cadastro de Itens" : "F5",
          "~C~ancelar"        : " Cancelar a Opera‡„o"                        : "CANCELAR"
         EndMenu
          To MenuVar
         Echo off
    
         If MenuVar="CANCELAR" or MenuVar="Esc"
             Then Loop
         EndIf
         RetVal=MenuVar
    EndIf  
  
    Switch
        Case RetVal="F3": SemFicha()
        Case RetVal="F5":
             ConfGeral("Aplicar as altera‡”es no cadastro de Itens ?")
             If Ok="S"
              Then Atualiza_Itens()
                   CHAVE=9
                   return         
             EndIf      
        Case RetVal=-94 : MsgTeclasPadrao()
        Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
             While True
               PAGINA("Simbolog","MR")
               If EDITAR="S"
                  Then CHAVE=0
                       Controla_EdicaoC()
                  Else If EXCLUIR="S"
                          Then If QuerExcluir("")
                                  Then Grava_LogEx("Simbolog")
                                       DEL
                                  Else UnLockrecord
                               EndIf
                          Else QuitLoop
                       EndIf
               EndIf
               SetaPosForm()
             EndWhile
             quitloop
        Case Retval="ESC":
             CHAVE=9
             Del
             return      
        Case Retval="ENTER": 
             If IsBlank([])
                Then If IsBlank(SEQ)
                        Then SEQ="1"
                        Else SEQ=StrVal(NumVal(SEQ)+1)
                     EndIf
                     []=SEQ
             EndIf
             []=ALINH()
             SEQ=[]
             Del
  
             Locate SEQ
             If Retval
                Then CHAVE=0
                Else CHAVE=1
                     End
                     Down Down
                     [CodigoSimbologia]=SEQ
             EndIf
             If IsLockRecord()
                then if chave=1 then del endif
                     quitloop
             EndIf
             return
        EndSwitch
  EndWhile
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************
Proc DIGITA()

Moveto [Simbologia_Impressao]
While True

      TECLA=" Esc=Retornar  "

      If CHAVE=0
         Then TECLA=TECLA+"Del=Excluir  "
      EndIf
      If Field()=""
         Then TECLA=TECLA+"F1=Tabelas  "
      EndIf
      Switch
        Case Field()="Simbologia_Impressao"     : MSGCAMPO="Consulte tabela impressa, exemplo: 001-015-025"
        Case Field()="DescricaoSimbologia"      : MSGCAMPO="Descri‡Æo da Simbologia"
        OtherWise                               : MSGCAMPO=Field()  
      EndSwitch

      Prompt TECLA
      SetaCorRegistro("Editando")
      Wait Field
        Message MSGCAMPO
           Until "ESC","ENTER","DEL","FIELDVIEW","F35","F1"

      Switch

      Case Retval="F1":
           If Field()=""
              Then ConsultaF1()
           EndIf
      Case Retval="ESC":
           If Field()="Simbologia_Impressao"
              Then If QuerDesfazer("")
                      Then If CHAVE=1
                              Then Del
                              Else Undo
                           EndIf
                           CHAVE=9
                           QuitLoop
                   EndIf
              Else Left
           EndIf
      Case Retval="ENTER":
           Switch
               Case Field() = "DescricaoSimbologia" :
                    QuitLoop
                    Right
               OtherWise : Right
           EndSwitch
      Case Retval="FIELDVIEW" or Retval="F35":
           EDITFIELD()
      Case Retval="DEL":
           If CHAVE=0
              Then If QuerExcluir("")
                      Then Grava_LogEx("Simbolog")
                           DEL
                           QuitLoop
                   EndIf
           EndIf
      EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Atualizar Itens                                                 *
;*******************************************************************************
Proc Atualiza_Itens()

Do_It!
ClearAll

NR = NRecords("Iten_tec")
CoEdit "Iten_tec"
Moveto [CodigoSimbologia]
Scan
  Barra(NR, RecNo())
  Aguarde("Aguarde, Atualizando Itens "+BARRA_STRING)
  If Busca_Lookup("CodigoSimbologia",[CodigoSimbologia],"SM")
     Then cod=[CodigoSimbologia]
          [CodigoSimbologia]=""
          [CodigoSimbologia]=cod
  EndIf
EndScan
Do_It!
ClearAll

EndProc

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoC()
DIGITA()
If RecordStatus("Locked") Then UnLockRecord EndIf         
Endproc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"
CoEdit "Simbolog"
PickForm "F"
While True
  CHAVE()
  If CHAVE=9
     Then QuitLoop
  EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll

Release Vars All
Release Procs All
