;** Rc_0060 *******************************************************************
;*  Relacao de Clientes por Area                                               *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/95 por Anivel Augusto Rodrigues
;Ultima Alteracao: 11/12/2003 por Karen Lauar Nery
;Motivo Alteracao: Inclusao Status

;*******************************************************************************
;* Rotina para Selecionar Registros                                            *
;*******************************************************************************
Proc Seleciona()
ClearAll

{Ask} {Destinat} Check
Moveto [Tipo          ] TypeIn "C"
Moveto [Codigo da Area] TypeIn "~VSDGAREA.."
Moveto [Inativo]
Switch
  Case VSDGSTATUS="1": TypeIn "N"
  Case VSDGSTATUS="2": TypeIn "S"
EndSwitch
Do_It!
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_AREA"   :Campo="NO"
            Case Campo="TG_STATUS" :Campo="TG_AREA"
            Case Campo="YES" Or Campo="NO" : Campo="TG_AREA"
          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_AREA" :
                         VSDGAREA=ControlValue("TG_AREA")
                         If Not IsBlank(VSDGAREA)
                           Then VSDGAREA=ALINHM(VSDGAREA,2)
                                View NOWINDOW "\\Sistemas\\Cadastro\\Area"
                                Moveto [Codigo da Area]
                                Locate VSDGAREA
                                If Not RetVal
                                   Then MENSAGEM("Area n„o Cadastrada !")
                                        Valor=False
                                   Else VSDGNOMAREA=[Descricao da Area]
                                        Campo="TG_STATUS"
                                EndIf
                                ClearAll
                           Else VSDGNOMAREA="Todas"
                                Campo="TG_STATUS"
                         EndIf
                    Case Campo="TG_STATUS" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()
If Not IsAssigned(SYS_CODIGO_CLIENTE) Then SYS_CODIGO_CLIENTE="" EndIf

VSDGAREA    =""
VSDGNOMAREA =""
VSDGSTATUS  =""

While True

  ShowDialog "Rela‡„o de Clientes por µrea" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 06,12   Height 10 Width 50

    Label  @ 01,00 "Area"  For "TG_AREA"
    Accept @ 02,01 Width 05 "A2"  Picture "!*!" Tag "TG_AREA" To VSDGAREA
    Accept @ 02,07 Width 33 "A30"  Picture "#*#" Tag "TG_NOMAREA" To VSDGNOMAREA

    Label  @ 03,00 "Status do Cliente" For "TG_STATUS"
    Accept @ 04,01 Width 04 "A1"  Picture "1,2,3" Tag "TG_STATUS" To VSDGSTATUS
    Accept @ 04,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMSTATUS" To VSDGNOMSTATUS

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat˘rio")
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Loop
  EndIf

  IF SYS_CODIGO_CLIENTE="0092"
     Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0031" "3" "Answer" "R"
     Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "6" "Answer" "R"
  EndIf

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

