;** FRETE **********************************************************************
;*  PROGRAMA DE CADASTRO DE FRETES                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 15/03/99 por Cl udio Ant“nio de Faria Santos
;Ultima Alteracao: 23/05/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao Controla_Edicao
;Ultima Alteracao: 30/12/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Novo Layout de Teclas
;Ultima Alteracao: 18/02/2013 por Kamila Gomes
;Motivo Alteracao: Ajustes SetaCorRegistro()

;*******************************************************************************
;* Rotina para Localizar Registro                                              *
;*******************************************************************************
Proc CHAVE()

While True
      SetaCorRegistro("Editar")
      End
      SEQ=[Faixa]
      Down
      Moveto [Faixa]

  TECLA=""
  AguardaTeclasPadrao()

  Switch
      Case RetVal=-33 : SemFuncoes()
      Case RetVal="F3": SemFicha()
      Case RetVal=-94 : MsgTeclasPadrao()
      Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
           While True
             PAGINA("TABFRETE","MR")
             If EDITAR="S"
                Then CHAVE=0
                     Controla_EdicaoC()
                Else If EXCLUIR="S"
                        Then If QuerExcluir("")
                                Then DEL
                                Else UnLockRecord
                             EndIf
                        Else QuitLoop
                     EndIf
             EndIf
             SetaPosForm()
           EndWhile
      Case Retval="ESC":
           CHAVE=9
           Del
           QuitLoop
      Case RetVal="ENTER":
           If IsBlank([])
              Then If IsBlank(SEQ)
                      Then SEQ=1
                      Else SEQ=SEQ+1
                   EndIf
                   []=SEQ
            EndIf
            CODIGO=[]
            Del
            Locate CODIGO
            If Retval
               Then CHAVE=0
               Else CHAVE=1
                    End Down
                    [Faixa]=CODIGO
            EndIf
            If IsLockRecord()
               Then Loop
            EndIf
            Quitloop
      EndSwitch
EndWhile
EndProc

;*******************************************************************************
;* Rotina para Digitacao das Informacoes                                       *
;*******************************************************************************
Proc DIGITA()
Moveto [Km Inicial]
While True

      TECLA=" Esc=Retornar  "

      If CHAVE=0
         Then TECLA=TECLA+"Del=Excluir  "
      EndIf

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

      Switch
      Case Retval="ESC":
           If Field()="Km Inicial"
              Then If QuerDesfazer("")
                      Then If CHAVE=1
                              Then Del
                              Else Undo
                           EndIf
                           CHAVE=9
                           QuitLoop
                   Endif
              Else Left
           EndIf
      Case Retval="ENTER":
           If IsBlank([])
              Then Loop
           EndIf
           If Field() = "Valor Minimo"
              Then QuitLoop
              Else Right
           EndIf
      Case Retval="FIELDVIEW" or Retval="F35":
           EDITFIELD()
      Case Retval="DEL":
           If CHAVE=0
              Then If QuerExcluir("")
                      Then DEL
                           QuitLoop
                   EndIf
           EndIf
      EndSwitch
EndWhile
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 "TabFrete"
PickForm "F"
While True
  CHAVE()
  If CHAVE=9
     Then QuitLoop
  EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll
Release Vars All
Release Procs All
