;** RE_0007  *******************************************************************
;*  Digitacao de Etiquetas Tecidos Andrade                                     *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 17/12/2003 por Karen Lauar Nery
;Ultima Alteracao: 23/01/2004 por Karen Lauar Nery
;Motivo Alteracao: Aumento do Nome
;Ultima Alteracao: 08/12/2009 por Bruno Carvalho
;Motivo Alteracao: Adicionado Rendimento e Pe‡as
;Ultima Alteracao: 15/12/2009 por Bruno Carvalho
;Motivo Alteracao: Excluido o Campo Representante
;Ultima Alteracao: 22/02/2010 por Cleber Alves
;Motivo Alteracao: Ajustes p/ imprimir Super Martins
;Ultima Alteracao: 09/11/2011 por Bruno Carvalho
;Motivo Alteracao: Inclusao Modelo ET_0260
;Ultima Alteracao: 09/11/2011 por Bruno Carvalho
;Motivo Alteracao: Ajustes para 2 Modelos de ImpressÆo de Etiquetas "0260" e "110"
;Ultima Alteracao: 16/03/2012 por Bruno Carvalho
;Motivo Alteracao: Novo layout, rela‡oes de todas etiquetas de TECIDOS
;Ultima Alteracao: 05/04/2012 por Bruno Carvalho
;Motivo Alteracao: Add Etiqueta "06" Aquarela
;Ultima Alteracao: 13/04/2012 por Karina Andrade
;Motivo Alteracao: Ajustes op‡äes de impressÆo 
;                  (Add etiquetas especificas - GW Entretelas/Andrade Textil/Uai Textil,etc.)
;Ultima Alteracao: 19/09/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Substitui‡Æo Editor novo arquivo por FileWrite
;Ultima Alteracao: 21/09/2012 por Bruno Carvalho
;Motivo Alteracao: Adicionado "Modelo 08" p/ Uai Textil (Formato 12,3 x 7,3)
;Ultima Alteracao: 04/02/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes LimpaRodape()                  
;Ultima Alteracao: 24/07/2013 por Bruno Carvalho
;Motivo Alteracao: Add modelo 09 empresa #0343#
;Ultima Alteracao: 28/04/2014 por Luis Gustavo
;Motivo Alteracao: Add modelo 10 empresa #0260#
;Ultima Alteracao: 23/07/2014 por Andrey Fillipe
;Motivo Alteracao: Add modelo 11 empresa #0352#
;Ultima Alteracao: 29/12/2015 por Kamila Gomes
;Motivo Alteracao: Add modelo 12 empresa #0370#
;Ultima Alteracao: 30/12/2015 por Kamila Gomes
;Motivo Alteracao: Add modelo 13 empresa #0370# e modelo 14 empresa #0376# 
;Ultima Alteracao: 19/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 15/05/2017 por Bruno Carvalho
;Motivo Alteracao: Alterado Dispositivo() -> DispositivoEtq()                   
;Ultima Alteracao: 21/12/2017 por Bruno Carvalho
;Motivo Alteracao: Add Modelo 15 #0404#
;Ultima Alteracao: 19/01/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ConfOpcoes()
;Ultima Alteracao: 22/01/2018 por Bruno Carvalho
;Motivo Alteracao: Ajustes 0404
;Ultima Alteracao: 15/06/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes getrecord        
;Ultima Alteracao: 29/11/2018 por Bruno Carvalho
;Motivo Alteracao: Adicionado modelo 16 #0382# -> 10,0x4,0
;Ultima Alteracao: 23/05/2019 por Bruno Carvalho
;Motivo Alteracao: Adicionado modelo 17 #0382# -> 10,0x4,0 
;Ultima Alteracao: 23/05/2019 por Bruno Carvalho
;Motivo Alteracao: Novo layout com p‡äes da aba tecido do cadastro de itens
;Ultima Alteracao: 27/05/2019 por Bruno Carvalho
;Motivo Alteracao: Alterado filtro da aba tecido no showdialog, numerico para string  
;Ultima Alteracao: 29/05/2019 por Bruno Carvalho
;Motivo Alteracao: Ajustes no modelo "17" -> Altera‡Æo de 3,5cm para 4,0cm na altura da etiqueta
;Ultima Alteracao: 04/02/2020 por Bruno Carvalho             
;Motivo Alteracao: Adicionado proc ListaRegra_Funcao(), onde foi ajustado ListaRegra_TGAtivado
 
;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc Seleciona()
ClearAll

Switch
  Case MODETIQ="01" Or
       MODETIQ="02" Or     
       MODETIQ="03" Or 
       MODETIQ="04" Or 
       MODETIQ="05" Or 
       MODETIQ="06" Or 
       MODETIQ="07" Or 
       MODETIQ="08" Or   
       MODETIQ="09" Or
       MODETIQ="10" Or
       MODETIQ="11" Or
       MODETIQ="12" Or
       MODETIQ="13" Or
       MODETIQ="14" Or  
       MODETIQ="15" Or
       MODETIQ="16" Or
       MODETIQ="17"  :       
       {Ask} {\\Sistemas\\Estoque\\Itens} Check
       Moveto [Codigo do Item   ] TypeIn "~VSDGITEM.."
       Moveto [Inativo          ] TypeIn "Not S"
       Do_It!
       ClearAll
EndSwitch

EndProc  ;(Seleciona)

;*******************************************************************************
;* Rotina Impressao Manual da Etiqueta                                         *
;*******************************************************************************
Proc IMPRIME_MANUAL(PARAM) 
Private PARAM

Switch
  Case PARAM = 1 : 
       ;ART: XXXX        PCO:    
       ;COD.:
       ;NOME: XXXXXXXXXXXXXXXXXXXXXXXXX
       ;COMP: XXXXXXXXXXXXXXXXXXXXXXXXX
       ;RENDIMENTO: AAAAA KG 
       ;PECA......: AAAAA 
       ;LARGURA...: AAAAA MT

       ARQIMP=PrivDir()+"RE_0007.Txt"
       If IsFile(ARQIMP)
          Then Deleta_Arquivo(ARQIMP)
       EndIf
       ;Setando as Variaveis CI_CPP e CI_LPP
       Seta_Tipo_Impressora("Matricial")
       
       View "Answer"
       Scan
         Print File ARQIMP CI_8LPP
         Print File ARQIMP "\n\n"
         Print File ARQIMP CI_6LPP
         Print File ARQIMP "\n\n"
         ;Imprimindo tamanho 20 por‚m mais condensado, usando 12 caracteres por polegada
         Print File ARQIMP CI_12CPP
         Print File ARQIMP CI_8LPP
         Print File ARQIMP "\027E"
         Print File ARQIMP "\014"+"ART: "+Format("W4,AL",SubStr([Codigo do Item],7,4))+Spaces(8)
                                 +"PCO: "+"\n\n"   
                                 ;+SubStr(Format("W9.2,EIC",VSDGPRECO),1,9)+"\n\n"
         Print File ARQIMP "\014"+"COD: "+Format("W4,AL",SubStr(VSDGCOD,1,4))+"\n\n"
         Print File ARQIMP "\014"+"NOME: "+SubStr(VSDGNOME,1,22)+"\n\n"
         Print File ARQIMP "\014"+"COMP: "+SubStr([Descricao do Item],1,22)+"\n\n"
         Print File ARQIMP "\014"+"RENDIMENTO: "+Format("W5,AR",Rtrim(SubStr(VSDGREND,1,5)))+" KG"+"\n\n"
         Print File ARQIMP "\014"+"PECA......: "+Format("W5,AR",Rtrim(SubStr(VSDGPEC,1,5)))+"\n\n"
         Print File ARQIMP "\014"+"LARGURA...: "+Format("W5,AR",Rtrim(SubStr(VSDGLARG,1,5)))+" MT"+"\n\n"
         Print File ARQIMP CI_6LPP
         Print File ARQIMP "\n"
         Print File ARQIMP CI_8LPP
         Print File ARQIMP "\n\n\n\n"
       EndScan
       ClearAll 

       ImpriArq(ARQIMP)
       
  Case PARAM = 2 :
       ;ART: XXXX        PCO:    
       ;COD.:
       ;NOME: XXXXXXXXXXXXXXXXXXXXXXXXX
       ;COMP: XXXXXXXXXXXXXXXXXXXXXXXXX
       ;RENDIMENTO: AAAAA KG 
       ;PECA......: AAAAA 
       ;LARGURA...: AAAAA MT

       ARQIMP=PrivDir()+"RE_0007.Txt"
       If IsFile(ARQIMP)
          Then Deleta_Arquivo(ARQIMP)
       EndIf
       ;Setando as Variaveis CI_CPP e CI_LPP
       Seta_Tipo_Impressora("Matricial")
       
       View "Answer"
       Scan
         ;Print File ARQIMP CI_8LPP
         ;Print File ARQIMP "\n"
         ;Print File ARQIMP CI_6LPP
         ;Print File ARQIMP "\n"
         ;Imprimindo tamanho 20 por‚m mais condensado, usando 12 caracteres por polegada
         ;Print File ARQIMP CI_12CPP
         Print File ARQIMP CI_20CPP
         ;Print File ARQIMP CI_8LPP
         ;Print File ARQIMP "\027E"
         Print File ARQIMP "\014"+"ART: "+Format("W4,AL",SubStr(VSDGITEM,7,4))+Spaces(8)
                                 +"PCO: "+"\n"   
                                 ;+SubStr(Format("W9.2,EIC",VSDGPRECO),1,9)+"\n\n"
         Print File ARQIMP "\014"+"COD: "+Format("W4,AL",SubStr(VSDGCOD,1,4))+"\n" 
         Print File ARQIMP "\014"+"NOME: "+SubStr(VSDGNOME,1,22)+"\n"
         Print File ARQIMP "\014"+"COMP: "+SubStr(VSDGNOMITEM,1,22)+"\n"
         Print File ARQIMP "\014"+"RENDIMENTO: "+Format("W5,AR",Rtrim(SubStr(VSDGREND,1,5)))+" KG"+"\n"
         Print File ARQIMP "\014"+"PECA......: "+Format("W5,AR",Rtrim(SubStr(VSDGPEC,1,5)))+"\n"
         Print File ARQIMP "\014"+"LARGURA...: "+Format("W5,AR",Rtrim(SubStr(VSDGLARG,1,5)))+" MT"+"\n"
         ;Print File ARQIMP CI_6LPP
         ;Print File ARQIMP "\n"
         ;Print File ARQIMP CI_8LPP
         Print File ARQIMP "\n\n"
       EndScan
       ClearAll 

       ImpriArq(ARQIMP)  
EndSwitch

EndProc ;IMPRIME_MANUAL()

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc Seleciona_Etiqueta_Dialog(Disparo,Campo,Evento,Elemento)
Private 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
            ;** Selecao **
            Case Campo="TG_NREQ"           : Campo="NO"
            Case Campo="TG_NPED"           : Campo="TG_NREQ"
            Case Campo="TG_TIPOEST"        : Campo="TG_NPED"
            Case Campo="TG_FAMI"           : Campo="TG_TIPOEST"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_REFERENCIA"     : Campo="TG_MARCA"
            Case Campo="TG_CODIGOI"        : Campo="TG_REFERENCIA"
            Case Campo="TG_CODIGOF"        : Campo="TG_CODIGOI"
            Case Campo="TG_QUANTIDADE"     : Campo="TG_CODIGOF"

            ;** Imprimir **
            Case Campo="TG_OPETIQUETA"     : Campo="NO"
            ;Case Campo="TG_OPRELCODALFDIG" : Campo="TG_OPETIQUETA"

            Case Campo="YES" Or Campo="NO" :
                 If OP_SHOW="S"
                    Then Campo="TG_TIPOEST"
                    Else Campo="TG_OPETIQUETA"
                 EndIf
          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
                    ;** Selecao **
                    Case Campo="TG_NREQ"     : 
                         VSDGNREQ=ControlValue("TG_NREQ")
                         If Not IsBlank(VSDGNREQ)
                            Then VSDGNREQ=AlinhM(VSDGNREQ,6)
                                 Campo="YES"
                            Else Campo="TG_NPED"
                         EndIf   
                    Case Campo="TG_NPED"     :
                         VSDGNPED=ControlValue("TG_NPED")
                         If Not IsBlank(VSDGNPED)
                            Then VSDGNPED=AlinhM(VSDGNPED,6)
                                 Campo="YES"
                            Else Campo="TG_TIPOEST"
                         EndIf   
                    Case Campo="TG_TIPOEST"  : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"     : Campo="TG_GRP"
                    Case Campo="TG_GRP"      : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"    : Campo="TG_REFERENCIA"
                    Case Campo="TG_REFERENCIA" : Campo="TG_CODIGOI"
                    Case Campo="TG_CODIGOI"  : Campo="TG_CODIGOF"
                    Case Campo="TG_CODIGOF"  : Campo="TG_QUANTIDADE"
                    Case Campo="TG_QUANTIDADE"  :
                         VSDGQUANTIDADE=ControlValue("TG_QUANTIDADE")
                         If Not Isblank(VSDGQUANTIDADE)
                            Then Campo="YES"
                         EndIf
                    Case Campo="TG_TABELA"  :
                         VSDGTABELA=ControlValue("TG_TABELA")
                         If Not Isblank(VSDGTABELA)
                            Then Campo="YES"
                         EndIf


                    ;** Imprimir **
                     Case Campo="TG_OPETIQUETA"     : Campo="YES"
                    ;Case Campo="TG_OPETIQUETA"     : Campo="TG_OPRELCODALFDIG"
                    ;Case Campo="TG_OPRELCODALFDIG" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPETIQUETA":
     MSG_CAMPO="Selecione o op‡„o desejada !"
     TECLA    ="=Selecionar  "
  Case Campo="TG_QUANTIDADE":
     MSG_CAMPO="Informe a quantidade de repeti‡„o da etiqueta"
  Case Campo="TG_TABELA":
     MSG_CAMPO="Informe a tabela de pre‡o a ser utilizada"
  Case Campo="TG_NREQ":
     MSG_CAMPO="Informe o Lan‡amento de Requisi‡„o de entrada de produ‡„o"

EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc ;Seleciona_Etiqueta_Dialog

;*******************************************************************************
;* Rotina Impressao                                                            *
;*******************************************************************************
Proc Seleciona_Etiqueta()
LimpaRodape(0)
Do_It!
ClearAll

While True

  OP_SHOW="I"
  ShowDialog "Selecione o Modelo de Etiqueta" Proc "Seleciona_Etiqueta_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 01,01 Height 19 Width 80

    PickArray @2,01 Height 11 width 75
     Columns 1
      Array_OpEtiquetas
       Tag "TG_OPETIQUETA"
        To VSDGOPETIQUETA
    Label @ 00,00 "Op‡”es de Etiqueta"  For "TG_OPETIQUETA"
    Label @ 01,00 "Codigo  Col  Dimens„o/cm   Impressora          Descri‡„o"  For "TG_OPETIQUETA"

    ;Label  @ 13,00 "Ordem" For "TG_OPRELCODALFDIG"
    ;Accept @ 14,01 Width 04 "A1"  Picture "1,2,3" Tag "TG_OPRELCODALFDIG" To VSDGOPRELCODALFDIG
    ;Accept @ 14,06 Width 15 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALFDIG" To VSDGNOMOPRELCODALFDIG

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  MODETIQ=RTrim(SubStr(Array_OpEtiquetas[VSDGOPETIQUETA],1,3))
  
  VSDGCODMODELO = MODETIQ
  VSDGMODELO    = Rtrim(Ltrim(SubStr(Array_OpEtiquetas[VSDGOPETIQUETA],4,60)))
  
  If MODETIQ="---"
     Then Mensagem("Modelo Inv lido !")
          Loop
  EndIf
  ConfOpcoes("Gravar")           
  QuitLoop
EndWhile
ClearAll

EndProc ;Seleciona_Etiqueta() 
  
;*******************************************************************************
;* Rotina Impressao                                                            *
;*******************************************************************************
Proc Imprimir()
LimpaRodape(0)  

If Not IsAssigneD(MODETIQ) Then MODETIQ = VSDGCODMODELO EndIF

If MODETIQ="01" Or
   MODETIQ="02" Or     
   MODETIQ="03" Or 
   MODETIQ="04" Or 
   MODETIQ="05" Or 
   MODETIQ="06" Or 
   MODETIQ="07" Or
   MODETIQ="08" Or
   MODETIQ="09" Or
   MODETIQ="10" Or
   MODETIQ="11" Or
   MODETIQ="12" Or
   MODETIQ="13" Or
   MODETIQ="14" Or
   MODETIQ="15" Or
   MODETIQ="16" Or
   MODETIQ="17"  
   Then DispositivoEtq()

        If OK="" Then Return False EndIf

        AGUARDE("Aguarde, Gerando Relat¢rio")

        Switch
          Case MODETIQ="01" Or
               MODETIQ="02" Or     
               MODETIQ="03" Or 
               MODETIQ="04" Or 
               MODETIQ="05" Or 
               MODETIQ="06" Or 
               MODETIQ="07" Or 
               MODETIQ="08" Or
               MODETIQ="09" Or
               MODETIQ="10" Or
               MODETIQ="11" Or
               MODETIQ="12" Or
               MODETIQ="13" Or
               MODETIQ="14" Or
               MODETIQ="15" Or
               MODETIQ="16" Or
               MODETIQ="17"  :
               Seleciona()
                
               If IsEmpty("Answer")
                  Then MENSAGEM("N„o existem registros a processar")
                       Delete "Answer"
                       Return False
               EndIf
      
               CONT=1
               Coedit "Answer"     
               CopyToArray REG
               While (CONT < NumVal(VSDGQUAN))
                  End
                  Down
                  CopyFromArray Reg
                  CONT=CONT+1
               EndWhile
               Do_It!
               ClearAll  
     
               Switch
                 Case MODETIQ="01" : CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010C" "4" "Answer" "R"
                 Case MODETIQ="02" : CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010C" "6" "Answer" "R" 
                 Case MODETIQ="03" : Play "ET_0260" 
                 Case MODETIQ="04" : If SYS_CODIGO_CLIENTE="0130"
                                        Then CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010C" "2" "Answer" "R"
                                        Else Mensagem("Etiqueta Indispon¡vel!")
                                             Return True
                                     EndIf   
                 Case MODETIQ="05" : CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010C" "3" "Answer" "R"
                 Case MODETIQ="06" : CopyReport "\\Base\\Sistemas\\Estoque\\Re_0010C" "8" "Answer" "R"
                 Case MODETIQ="07" : Play "ET_ZT01"     
                 Case MODETIQ="08" : IMPRIME_MANUAL(1)
                 Case MODETIQ="09" : Play "ET_0343" 
                 Case MODETIQ="10" : IMPRIME_MANUAL(2)
                 Case MODETIQ="11" : Play "ET_0352"
                 Case MODETIQ="12" : Play "ET_0370"
                 Case MODETIQ="13" : Play "ET_0370B"
                 Case MODETIQ="14" : Play "ET_0376"
                 Case MODETIQ="15" : Play "ET_0404"
                 Case MODETIQ="16" : Play "ET_Z382M"
                 Case MODETIQ="17" : Play "ET_Z382P" 
               EndSwitch
               If MODETIQ<>"03" And 
                  MODETIQ<>"07" And 
                  MODETIQ<>"08" And 
                  MODETIQ<>"09" And 
                  MODETIQ<>"10" And 
                  MODETIQ<>"12" And 
                  MODETIQ<>"13" And 
                  MODETIQ<>"14" And
                  MODETIQ<>"15" And
                  MODETIQ<>"16" And
                  MODETIQ<>"17"      
                  Then IMPRIREL("Answer","R")
                       Delete "Answer"
               EndIf
        EndSwitch   
EndIf           

Return True

EndProc ;Imprimir()

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ConfOpcoes(Opcao)
Private Opcao

Switch
  Case Opcao="Ler":
       Array Array_OpEtiquetas[18]
       Array_OpEtiquetas[1] ="01      1                  Matricial                  [0110] " ;Andrade Textil
       Array_OpEtiquetas[2] ="02      1                  Matricial                  [0236] " ;Super Martins
       Array_OpEtiquetas[3] ="03      1                  Matricial                  [0260] " ;UAI Textil
       Array_OpEtiquetas[4] ="04      1                  Matricial                  [0130] " ;GW Intertelas
       Array_OpEtiquetas[5] ="05      1                  Matricial                         "
       Array_OpEtiquetas[6] ="06      1                  Matricial                  [0318] " ;Aquarela 
       Array_OpEtiquetas[7] ="08      1    12,3x7,3 cm   Matricial                  [0260] " ;UAI Textil
       Array_OpEtiquetas[8] ="09      1     8,9x4,9 cm   Matricial                  [0343] " ;Thardely
       Array_OpEtiquetas[9] ="------------------------------------------------------------------------"
       Array_OpEtiquetas[10]="07      1    10,0x4,0 cm   Termica/Zebra                     "
       Array_OpEtiquetas[11]="10      1    12,3x7,3 cm   Matricial                  [0260] " ;UAI Textil
       Array_OpEtiquetas[12]="11      1                  Laser                      [0352] " ;DECORART TECIDOS
       Array_OpEtiquetas[13]="12      2                  Laser                      [0370] " ;CHARMY TECIDOS
       Array_OpEtiquetas[14]="13      5     3,8x2,1 cm   Laser                      [0370] " ;CHARMY TECIDOS
       Array_OpEtiquetas[15]="14      2                  Laser                      [0376] " ;ATUAL TECIDOS
       Array_OpEtiquetas[16]="15      2                  Laser                      [0404] "
       Array_OpEtiquetas[17]="16      1    10,0x4,0 cm   Termica/Zebra              [0382] " ;TECIDOS JANON
       Array_OpEtiquetas[18]="17      1    10,0x4,0 cm   Termica/Zebra              [0382] " ;TECIDOS JANON
       VSDGQUANTIDADE=1

       If IsFile("OE_0011.sc")
           Then Play "OE_0011"
           Else VSDGOPETIQUETA       =1
                VSDGOPRELCODALFDIG   =""
                VSDGNOMOPRELCODALFDIG=""
       EndIf
       If IsAssigned(MODETIQ) 
          Then
               For wi From 1 to ArraySize(Array_OpEtiquetas)
                 If RTrim(SubStr(Array_OpEtiquetas[wi],1,3))=MODETIQ
                    Then VSDGOPETIQUETA=wi
                         QuitLoop
                 EndIf
               EndFor
       EndIF

  Case Opcao="Gravar":
       FileWrite        "OE_0011.sc" From ";****** Variaveis de Configura‡„o Modelo Etiqueta Vise Informatica"+"\n"
       FileWrite Append "OE_0011.sc" From "MODETIQ=\""+MODETIQ+"\""+"\n"
       FileWrite Append "OE_0011.sc" From "VSDGOPRELCODALFDIG="+Chr(34)+VSDGOPRELCODALFDIG+Chr(34)+"\n"
EndSwitch
EndProc ; ConfOpcoes()

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(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: Switch
                                     Case Campo="TG_CODMODELO" :
                                          ConfOpcoes("Ler")
                                          Seleciona_Etiqueta()
                                     OtherWise                 :
                                          Dialog_F1()
                                   EndSwitch
     Case Evento["KeyCode"] = -60: If Campo="TG_REPRESEN"
                                      Then ListaRegra_F2() 
                                   EndIf
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_ITEM"           : Campo="NO"
            Case Campo="TG_PEC_MED"        : Campo="TG_ITEM"
            Case Campo="TG_COD"            : Campo="TG_PEC_MED"
            Case Campo="TG_NOME"           : Campo="TG_COD"
            Case Campo="TG_REPRESEN"       : Campo="TG_NOME"
            Case Campo="TG_TABELA"         : campo="TG_REPRESEN"
            Case Campo="TG_ARTIGO"         : Campo="TG_TABELA" 
            Case Campo="TG_PEC"            : Campo="TG_ARTIGO"
            Case Campo="TG_LARG"           : Campo="TG_PEC"
            Case Campo="TG_LARGUTIL"       : Campo="TG_LARG"       
            Case Campo="TG_GRAMATURA"      : Campo="TG_LARGUTIL"  
            Case Campo="TG_REND"           : Campo="TG_GRAMATURA"
           ;Case Campo="TG_SIMBOLOGIA"     : Campo="TG_REND"
            Case Campo="TG_QUAN"           : Campo="TG_REND"
            Case Campo="TG_CODMODELO"      : Campo="TG_QUAN"
            Case Campo="YES" Or Campo="NO" : Campo="TG_ITEM"
          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_ITEM"           :
                         Switch
                           Case IsBlank(VSDGITEM) : Mensagem("Escolha um codigo !")
                           OtherWise              : Campo="TG_PEC_MED"  
                                If Not IsEmpty("Iten_Tec")
                                   Then AUX_PECA        = ""
                                        AUX_RENDIMENTO  = ""
                                        AUX_LARGURA     = ""
                                        AUX_ARTIGO      = ""     
                                        AUX_COMPOSICAO  = ""
                                        AUX_COMPOSICAO2 = ""
                                        AUX_GRAMATURA   = ""
                                        AUX_SIMBOLOGIA  = ""
                                        AUX_LARGTEXTIL  = ""
                                        AUX_UN          = ""
                                         
                                        GetRecord "Itens" VSDGITEM To REG_ITEM
                                        If RetVal
                                           Then AUX_UN = REG_ITEM["Unidade Fiscal"]
                                        EndIf
                                         
                                        GetRecord "Iten_Tec" VSDGITEM To REG_ITEM_TECIDO
                                        If RetVal
                                           Then AUX_PECA        = REG_ITEM_TECIDO["Peca"]
                                                AUX_RENDIMENTO  = REG_ITEM_TECIDO["Rendimento"]
                                                AUX_LARGURA     = REG_ITEM_TECIDO["Largura"]
                                                AUX_ARTIGO      = REG_ITEM_TECIDO["Artigo"]
                                                AUX_COMPOSICAO  = SubStr(REG_ITEM_TECIDO["Composicao"],01,35)
                                                AUX_COMPOSICAO2 = SubStr(REG_ITEM_TECIDO["Composicao"],36,35)
                                                AUX_GRAMATURA   = REG_ITEM_TECIDO["Gramatura"]
                                                AUX_SIMBOLOGIA  = REG_ITEM_TECIDO["Simbologia_Impressao"]
                                                AUX_LARGTEXTIL  = REG_ITEM_TECIDO["Largura Util"]        
                                        EndIf
                                        VSDGPEC         = AUX_PECA
                                        VSDGLARG        = AUX_LARGURA
                                        VSDGREND        = AUX_RENDIMENTO
                                        VSDGARTIGO      = AUX_ARTIGO
                                        VSDGCOMPOSICAO  = AUX_COMPOSICAO
                                        VSDGCOMPOSICAO2 = AUX_COMPOSICAO2
                                        VSDGGRAMATURA   = AUX_GRAMATURA
                                        VSDGSIMBOLOGIA  = AUX_SIMBOLOGIA
                                        VSDGLARGTEXTIL  = AUX_LARGTEXTIL
                                        VSDGPEC_MED     = AUX_UN
                                EndIf  
                         EndSwitch
                    Case Campo="TG_PEC_MED"        : Campo="TG_COD" 
                         VSDGPEC_MED=ControlValue("TG_PEC_MED")     
                    Case Campo="TG_COD"            :
                         VSDGCOD=ControlValue("TG_COD")
                         Campo="TG_NOME"
                    Case Campo="TG_NOME"           :
                         VSDGNOME=ControlValue("TG_NOME")
                         Campo="TG_REPRESEN"               
                    Case Campo="TG_REPRESEN"      : Campo="TG_TABELA"
                         If VSDGREPRESEN="" 
                            Then VSDGNOMREPR = "TODOS"
                         EndIf          
                    Case Campo="TG_TABELA"        : Campo="TG_ARTIGO"
                         If VSDGTABELA=""   Then VSDGNOMTAB = ""   EndIf
                    Case Campo="TG_ARTIGO"        : Campo="TG_PEC"     
                         VSDGARTIGO = ControlValue("TG_ARTIGO")     
                    Case Campo="TG_PEC"           : Campo="TG_LARG"
                         VSDGPEC=ControlValue("TG_PEC")
                    Case Campo="TG_LARG"          : Campo="TG_LARGUTIL"
                         VSDGLARG=ControlValue("TG_LARG")
                    Case Campo="TG_LARGUTIL"      : Campo="TG_GRAMATURA"
                         VSDGLARGTEXTIL = ControlValue("TG_LARGUTIL")       
                    Case Campo="TG_GRAMATURA"     : Campo="TG_REND"  
                         VSDGGRAMATURA=ControlValue("TG_GRAMATURA")
                    Case Campo="TG_REND"          : Campo="TG_QUAN"    
                         VSDGREND=ControlValue("TG_REND")
                    ;Case Campo="TG_SIMBOLOGIA"    : Campo="TG_QUAN"     
                    ;     VSDGSIMBOLOGIA=ControlValue("TG_SIMBOLOGIA")
                    Case Campo="TG_QUAN"          : Campo="TG_CODMODELO"
                         VSDGQUAN=ControlValue("TG_QUAN")
                    Case Campo="TG_CODMODELO"     : Campo="YES" 
                         VSDGCODMODELO = ControlValue("TG_CODMODELO")
                    Case Campo="YES"  :
                         If SYS_CODIGO_CLIENTE="0260" Or SYS_CODIGO_CLIENTE="0110" 
                           Then Echo Normal
                                Echo Off
                                ShowPopup " Fun‡äes " CENTERED
                                 "Modelo 1  -  2,3cm x 10,2cm ": "" : "MODELO1",
                                 "Modelo 2  -  7,3cm x 12,3cm ": "" : "MODELO2",
                                 Separator,
                                 "~C~ancelar     "       : "" : "CANCELAR"
                                EndMenu
                                To MenuVar   
                                Echo Off
                                
                                If MenuVar="MODELO2" 
                                   Then UAI_TEXTIL=True
                                EndIf   
                                
                                If MenuVar="CANCELAR" or MenuVar="Esc"
                                    Then CancelDialog
                                    Else AcceptDialog
                                EndIf                                         
                         EndIf                                               
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
   
EndIf
Switch
  Case Campo="TG_ITEM"       : MSG_CAMPO = "Codigo do Item"
  Case Campo="TG_PEC_MED"    : MSG_CAMPO = "MT ou KG"
  Case Campo="TG_COD"        : MSG_CAMPO = "Pre‡o Codificado"
  Case Campo="TG_NOME"       : MSG_CAMPO = "Nome do Tecido"
  Case Campo="TG_REPR"       : MSG_CAMPO = "Representante"
  Case Campo="TG_COMPOSICAO" : MSG_CAMPO = "Composi‡Æo"
  Case Campo="TG_ARTIGO"     : MSG_CAMPO = "Artigo" 
  Case Campo="TG_PEC"        : MSG_CAMPO = "Pe‡a"
  Case Campo="TG_LARG"       : MSG_CAMPO = "Largura"
  Case Campo="TG_LARGUTIL"   : MSG_CAMPO = "Largura étil"
  Case Campo="TG_GRAMATURA"  : MSG_CAMPO = "Gramatura"  
  Case Campo="TG_REND"       : MSG_CAMPO = "Informe o Rendimento"
  Case Campo="TG_SIMBOLOGIA" : MSG_CAMPO = "Simbologia"
  Case Campo="TG_QUAN"       : MSG_CAMPO = "Quantidade de Etiquetas a ser impressa"
  Case Campo="TG_CODMODELO"  : MSG_CAMPO = "Modelo de Etiqueta"
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp

EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01      1                  Matricial                  [0110] ") ;Andrade Textil
ModeloRelatoriosAdd("02      1                  Matricial                  [0236] ") ;Super Martins
ModeloRelatoriosAdd("03      1                  Matricial                  [0260] ") ;UAI Textil
ModeloRelatoriosAdd("04      1                  Matricial                  [0130] ") ;GW Intertelas
ModeloRelatoriosAdd("05      1                  Matricial                         ")
ModeloRelatoriosAdd("06      1                  Matricial                  [0318] ") ;Aquarela 
ModeloRelatoriosAdd("08      1    12,3x7,3 cm   Matricial                  [0260] ") ;UAI Textil
ModeloRelatoriosAdd("09      1     8,9x4,9 cm   Matricial                  [0343] ") ;Thardely
ModeloRelatoriosAdd("07      1    10,0x4,0 cm   Termica/Zebra                     ")
ModeloRelatoriosAdd("10      1    12,3x7,3 cm   Matricial                  [0260] ") ;UAI Textil
ModeloRelatoriosAdd("11      1                  Laser                      [0352] ") ;DECORART TECIDOS
ModeloRelatoriosAdd("12      2                  Laser                      [0370] ") ;CHARMY TECIDOS
ModeloRelatoriosAdd("13      5     3,8x2,1 cm   Laser                      [0370] ") ;CHARMY TECIDOS
ModeloRelatoriosAdd("14      2                  Laser                      [0376] ") ;ATUAL TECIDOS
ModeloRelatoriosAdd("15      2                  Laser                      [0404] ")
ModeloRelatoriosAdd("16      1    10,0x4,0 cm   Termica/Zebra              [0382] ") ;TECIDOS JANON
ModeloRelatoriosAdd("17      1    10,0x4,0 cm   Termica/Zebra              [0382] ") ;TECIDOS JANON
ModeloRelatoriosAdd("Fim")

EndProc ;ModeloRelatoriosCarregaLista

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Proc"
If Not IsAssigned(SYS_CODIGO_CLIENTE) Then SYS_CODIGO_CLIENTE="" EndIF
SYS_VALOR()
LimpAguarde()
           
VSDGITEM        = "" 
VSDGNOMITEM     = ""
VSDGPEC_MED     = ""
VSDGCOD         = ""
VSDGNOME        = ""
VSDGREPRESEN    = ""
VSDGNOMREPR     = ""
VSDGTABELA      = ""
VSDGNOMTAB      = ""
VSDGCOMPOSICAO  = ""
VSDGCOMPOSICAO2 = ""
VSDGARTIGO      = ""
VSDGPEC         = ""
VSDGLARG        = ""
VSDGLARGTEXTIL  = ""
VSDGGRAMATURA   = ""
VSDGREND        = ""
VSDGSIMBOLOGIA  = ""
VSDGQUAN        = BlankNum()

ModeloRelatoriosCarregaLista()

ListaRegra_Funcao("ListaRegra_TGAtivado","[TG_REPRESEN]") 

While True

  ShowDialog "Digitacao de Dados para Etiqueta" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB","F2",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140, -60  
  @ 05,05   Height 19 Width 80

    Label  @ 00,00 "Item"  For "TG_ITEM"
    Accept @ 01,01 Width 36 "A10"  Picture "#*#" Tag "TG_ITEM"    To VSDGITEM
    Accept @ 02,01 Width 36 "A33" Picture "!*!"  Tag "TG_NOMITEM" To VSDGNOMITEM

    Label  @ 03,00 "UN" For "TG_PEC_MED"
    Accept @ 04,01 Width 05 "A2"  Picture "MT,KG"  Tag "TG_PEC_MED"  To VSDGPEC_MED

    Label  @ 03,06 "Pre‡o Codificado" For "TG_COD"
    Accept @ 04,07 Width 30 "A7"  Picture "!*!" Tag "TG_COD"     To VSDGCOD

    Label  @ 05,00 "Nome"  For "TG_NOME"
    Accept @ 06,01 Width 36 "A28"  Picture "!*!" Tag "TG_NOME"   To VSDGNOME

    Label  @ 07,00 "Representante"  For "TG_REPRESEN"
    Accept @ 08,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN"   To VSDGREPRESEN
    Accept @ 08,07 Width 30 "A30" Picture "!*!" Tag "TG_NOMREPR" To VSDGNOMREPR
    
    Label  @ 09,00 "Tabela"  For "TG_TABELA"
    Accept @ 10,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA" To VSDGTABELA
    Accept @ 10,07 Width 30 "A40" Picture "!*!" Tag "TG_NOMTAB" To VSDGNOMTAB

    Label  @ 00,38 "Composi‡Æo" For "TG_COMPOSICAO"
    Accept @ 01,39 Width 38 "A35"  Picture "!*!"  Tag "TG_COMPOSICAO"  To VSDGCOMPOSICAO
    Accept @ 02,39 Width 38 "A35" Picture "!*!"  Tag "TG_COMPOSICAO2" To VSDGCOMPOSICAO2
    
    Label  @ 03,38 "Artigo" For "TG_ARTIGO"
    Accept @ 04,39 Width 18 "A10"  Picture "!*!"  Tag "TG_ARTIGO"  To VSDGARTIGO
    
    Label  @ 05,38 "Pe‡a" For "TG_PEC"
    Accept @ 06,39 Width 18 "A15"  Picture "!*!"  Tag "TG_PEC"   To VSDGPEC
    
    Label  @ 07,38 "Largura" For "TG_LARG"
    Accept @ 08,39 Width 18 "A15"  Picture "!*!"  Tag  "TG_LARG"  To VSDGLARG
    
    Label  @ 09,38 "Largura Util" For "TG_LARGUTIL"
    Accept @ 10,39 Width 18 "A15"  Picture "!*!"  Tag  "TG_LARGUTIL"  To VSDGLARGTEXTIL
    
    Label  @ 03,58 "Gramatura" For "TG_GRAMATURA"
    Accept @ 04,59 Width 18 "A13"  Picture "!*!"  Tag "TG_GRAMATURA"  To VSDGGRAMATURA

    Label  @ 05,58 "Rendimento" For "TG_REND"
    Accept @ 06,59 Width 18 "A15"  Picture "!*!"  Tag "TG_REND"  To VSDGREND

    Label  @ 07,58 "Simbologia" For "TG_SIMBOLOGIA"
    Accept @ 08,59 Width 18 "A23"  Picture "!*!"  Tag "TG_SIMBOLOGIA"  To VSDGSIMBOLOGIA

    Label  @ 09,58 "Quantidade" For "TG_QUAN"
    Accept @ 10,59 Width 18 "N"  Picture "#*#"  Tag  "TG_QUAN"  To VSDGQUAN
    
    Label  @ 12,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 13,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 13,06  Width 71 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Imprimir()
     Then Loop
  EndIf     
EndWhile
ClearAll
Release Vars All
Release Procs All
