;** Rc_0090 *******************************************************************
;*  Relatorio de Representantes                                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/95 por Anivel Augusto Rodrigues
;Ultima Alteracao: 05/04/04 por Davi Pereira Carrano
;Motivo Alteracao: ImpressÆo de Todos ou um £nico representante
;Ultima Alteracao: 20/05/2020 por Bruno Carvalho
;Motivo Alteracao: Alterado CopyReport "...\\Cadastro\\Represen" p/ "...\\Cadastro\\RM_0031"

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
If VSDGNOMREPR = "Todos"
  Then
      If VSDGOPRELCODALF = "2"
         Then {Modify} {Sort} {Represen} {Answer} Down  "1" Do_It!
              DORDEM="Alfabetica"
         Else {Modify} {Sort} {Represen} {Answer}       "1" Do_It!
              DORDEM="de Codigo"
      EndIf
  Else
      {ASK} {Represen} Check
      Moveto [Codigo do Representante] TypeIn "~VSDGREPRESEN.."
      Do_It!
EndIf

If VSDGOPRELLISTCAD = "1" Then CopyReport "\\Base\\Sistemas\\Cadastro\\RM_0031" "1" "Answer" "R" EndIf
If VSDGOPRELLISTCAD = "2" Then CopyReport "\\Base\\Sistemas\\Cadastro\\RM_0031" "2" "Answer" "R" EndIf

ClearAll
EndProc   ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog1(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9: Temp=False
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_REPRESEN"       : Campo="NO"
            Case Campo="TG_OPRELLISTCAD"   : Campo="TG_REPRESEN"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_OPRELLISTCAD"
            Case Campo="YES" Or Campo="NO" : Campo="TG_REPRESEN"
          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_REPRESEN"     :Campo="TG_OPRELLISTCAD"

                    Case Campo="TG_OPRELLISTCAD" :
                         Switch
                           Case VSDGOPRELLISTCAD="1":
                                VSDGNOMOPRELLISTCAD="LISTAGEM DOS REPRESENTANTES"
                           Case VSDGOPRELLISTCAD="2":
                                VSDGNOMOPRELLISTCAD="FICHA DOS REPRESENTANTES"
                           OtherWise:
                                VSDGOPRELLISTCAD   =""
                                VSDGNOMOPRELLISTCAD=""
                         EndSwitch
                         If Not IsBlank(VSDGOPRELLISTCAD)
                            Then
                                If VSDGNOMREPR = "Todos"
                                  Then
                                      Campo="TG_OPRELCODALF"
                                  Else
                                      Campo="YES"
                                EndIf
;                            Campo="TG_OPRELCODALF"
                         EndIf
                    Case Campo="TG_OPRELCODALF"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPRELLISTCAD":
     MSG_CAMPO="1-Listagem de Representantes  2-Ficha Cadastral de Representantes"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()

VSDGOPRELCODALF  =""
VSDGOPRELLISTCAD =""

While True

  ShowDialog "Relat¢rio de Representantes" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12 Height 12 Width 50

    Label  @ 01,00 "Repres" For "TG_REPRESEN"
    Accept @ 02,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN" To VSDGREPRESEN
    Accept @ 02,09 Width 30 "A30" Picture "!*!" Tag "TG_NOMREPR" To VSDGNOMREPR

    Label  @ 03,00 "Op‡„o" For "TG_OPRELLISTCAD"
    Accept @ 04,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELLISTCAD" To VSDGOPRELLISTCAD
    Accept @ 04,06 Width 30 "A30" Picture "!*!" Tag "TG_NOMOPRELLISTCAD" To VSDGNOMOPRELLISTCAD

    Label  @ 05,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 06,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 06,06 Width 23 "A20" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf  

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

