;** Altcbar  *******************************************************************
;*  Alteracao de Itens com Codigo de Barras                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/04/2009 por Anivel Augusto Rodrigues
;Ultima Alteracao: 25/11/2009 por Bruno Carvalho
;Motivo Alteracao: AlteraÆo da DigitaÆo dos Dig. A-EAN13 e A-EAN8
;Ultima Alteracao: 01/07/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes CdBarr J_EAN13 = 78+Codigo do Item
;Ultima Alteracao: 05/05/2011 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes somente itens ATIVOS
;Ultima Alteracao: 26/07/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes fim do intervalo       

;*******************************************************************************
;* Rotina Processa                                                             *
;*******************************************************************************
Proc Processa()

AGUARDE("Selecionando Registros")
{Ask} {Itens} Check
Moveto [Codigo do Item         ] TypeIn ">=~VSDGCODIGOI, <=~VSDGCODIGOF"
Moveto [Tipo do Item           ]
Switch
   Case VSDGTIPOEST = "1"       : TypeIn "E or M or O or A or S"
   Case VSDGTIPOEST = "2"       : TypeIn "P or T"
   Case Not IsBlank(VSDGTIPOEST): TypeIn "~VSDGTIPOEST"
   OtherWise                    : TypeIn "Not C, Not D, Not F, Not G, Not H, Not I"
EndSwitch
Moveto [Codigo da Familia] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo  ] TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca  ] TypeIn "~VSDGMARCA.."
If Not CheckTG_OPNUMCBAR[1]
   Then Moveto [Codigo de Barras] TypeIn "Blank"
EndIf
Moveto [Inativo          ] TypeIn "Not S"
Do_It!
ClearAll

If IsEmpty("Answer")
   Then LimpAguarde()
        Return
EndIf

{Ask} {Answer} TypeIn "Fast"
Moveto [Flag ] TypeIn "Changeto Blank"
Do_It!
ClearAll


{Tools} {Copy} {JustFamily} {Itens} {Answer} {Replace}
ClearAll
LIMPAGUARDE()

Sort "Answer" On "Codigo do Item"
ClearAll

CoEdit "Answer"
{TableAdd} {Itens}
{TableAdd} {Itens_CB}
Moveto "Answer"
PickForm "5"

Moveto "Answer"
Moveto [Codigo de Barras]
While True
  PAGINA("Answer","MRNS")
  If EDITAR="S"
     Then Editar()
     Else If EXCLUIR="S"
             Then If QuerExcluir("este item desta relao")
                     Then Del
                          Echo Normal
                          Echo Off
                     Else UnLockRecord
                  EndIf
             Else If GERACAOOK
                     Then CONFGERAL("Desejar atualizar os Itens com os novos CĒdigos de Barras ?")
                          If OK="S"
                             Then CONFGERAL("Tem certeza em atualizar os Itens com os novos CĒdigos de Barras ?")
                                  If OK="S"
                                     Then Atualizar()
                                  EndIf
                          EndIf
                  EndIf
                  QuitLoop
          EndIf
  EndIf
  SetaPosForm()
EndWhile
Do_It!
ClearAll
EndProc

;*******************************************************************************
;* Rotina para Digitacao dos Precos                                            *
;*******************************************************************************
Proc Editar()
TPCALCULO=""
Home
Moveto [Codigo de Barras]

While True

  TECLA= " Esc=Retornar  Del=Excluir  F9=Gerar  "

  Prompt TECLA
  MSG=""

  Wait Field
    Message MSG
       Until "ESC","ENTER","DEL","FIELDVIEW","F35","UP","DOWN","PGUP","PGDN","HOME","END","DEL","RIGHT","LEFT","F9"

  Switch
  Case Retval="ESC":
       QuitLoop
  Case Retval="FIELDVIEW" or Retval="F35":
       EDITFIELD()
  Case Retval="DEL":
       If QuerExcluir("este Item desta relao")
          Then Del
               Echo Normal
               Echo Off
               If RecordStatus("New")
                  Then QuitLoop
               EndIf
       EndIf
  Case Retval="F9":

       Echo Normal
       Echo Off

       ShowPopup " Calculo CĒdigo de Barras " CENTERED
        "~A~-EAN13     ": " Ativar calculo EAN13                                      " : "A-EAN13",
        "~B~-EAN8      ": " Ativar calculo EAN8                                       " : "B-EAN8",
        Separator,
        "~G~-EAN13 II  ": " Ativar calculo EAN13 = 00+CĒdigo do Item                  " : "G-EAN13",
        "~J~-EAN13 III ": " Ativar calculo EAN13 = 78+CĒdigo do Item                  " : "J-EAN13",
        "~H~-EAN8 II   ": " Ativar calculo EAN8 = Ģltimos 7 dĄgitos do CĒdigo do Item " : "H-EAN8",
        "~I~-COD128 II ": " Ativar calculo COD128 Livre = CĒdigo do Item              " : "I-COD128",
        "~C~ancelar    ": " Cancelar a Operao                                       " : "CANCELAR"
       EndMenu
        To MenuVar

       Echo Off

       If MenuVar="CANCELAR" or MenuVar="Esc"
           Then Loop
           Else VSDGTPCOD=MenuVar
       EndIf

       Switch
         Case VSDGTPCOD="A-EAN13" : Selecao(VSDGTPCOD)
         Case VSDGTPCOD="B-EAN8"  : Selecao(VSDGTPCOD)
         OtherWise                : GeraNum()
       EndSwitch

  OtherWise:
       TECLAPRESS=RetVal

       If TECLAPRESS="LEFT"
          Then Loop
       EndIf
       If (TECLAPRESS="ENTER" or  TECLAPRESS="RIGHT")
          Then Down
               Moveto [Codigo de Barras]
          Else KeyPress TECLAPRESS
        EndIf
        If RecordStatus("New")
           Then QuitLoop
        EndIf
  EndSwitch
EndWhile
EndProc ; (Editar)


Proc GeraNum()

If Not ConfGeral("Confirma a gerao "+VSDGTPCOD+" a partir deste item "+[Codigo do Item]+" ?")
   Then Return
EndIf

If VSDGTPCOD="A-EAN13" Or
   VSDGTPCOD="B-EAN8"
   Then If VSDGOPCOD=1
           Then CDBARINI=VSDGCODINI
                CDBARFIM=VSDGCODINI
        EndIf
EndIf
Continua_Geracao=True

Aguarde("Gerando novos numeros")
Nreg=Recno()
While True

  If Not Continua_Geracao
     Then [Tipo Codigo_Barras]=""
          [Codigo de Barras  ]=""
          [Flag              ]=""
     Else Switch
            Case VSDGTPCOD="A-EAN13"  :
              Switch
                Case VSDGOPCOD=1: [Codigo de Barras]=Mod11_CalcEAN13("CALC",CDBARFIM)
                Case VSDGOPCOD=2: [Codigo de Barras]=Pega_CDBarras("EAN13")
              EndSwitch

            Case VSDGTPCOD="B-EAN8"   :
              Switch
                Case VSDGOPCOD=1: [Codigo de Barras]=Mod11_CalcEAN8("CALC",CDBARFIM)
                Case VSDGOPCOD=2: [Codigo de Barras]=Pega_CDBarras("EAN8")
              EndSwitch

            Case VSDGTPCOD="G-EAN13"  : [Codigo de Barras]=Mod11_CalcEAN13("CALC",[Codigo do Item])
            Case VSDGTPCOD="J-EAN13"  : [Codigo de Barras]=Mod11_CalcEAN13("CALC","78"+[Codigo do Item])

            Case VSDGTPCOD="H-EAN8"   : CDBARFIM          =SubStr([Codigo do Item  ],04,07)
                                        [Codigo de Barras]=Mod11_CalcEAN8("CALC",CDBARFIM)

            Case VSDGTPCOD="I-COD128" : [Codigo de Barras]=[Codigo do Item]
          EndSwitch
          CDBARFIM=[Codigo de Barras]
          If IsBlank(CDBARFIM)
             Then Continua_Geracao=False
                  Nreg=Recno()
                  [Tipo Codigo_Barras]=""
                  [Codigo de Barras  ]=""
                  [Flag              ]=""
             Else [Tipo Codigo_Barras]=VSDGTPCOD
                  [Flag              ]="A"
          EndIf
  EndIf
  UnLockRecord
  Skip
  If EOT()
     Then QuitLoop
  EndIf

  If (VSDGTPCOD<>"A-EAN13" And VSDGTPCOD<>"B-EAN8") Or
     Not Continua_Geracao
     Then Loop
  EndIf

  If VSDGOPCOD=1
     Then If SubStr(CDBARFIM,1,12)=VSDGCODFIM
             Then MSG="Fim do intervalo para este cĒdigo de Barras !//"
                  MSG=MSG+"Inicial = "+CDBARINI+"//"
                  MSG=MSG+"Final   = "+SubStr(CDBARFIM,1,12)+"// //"
                  MSG=MSG+"Informe um novo intervalo p/ os itens restantes, Verificar !"
                  Mensagem(MSG)
                  Continua_Geracao=False
                  Nreg=Recno()
             Else Switch
                    Case VSDGTPCOD="A-EAN13":
                         CDBARFIM=SubStr(CDBARFIM,1,8)+AlinhM(StrVal(NumVal(SubStr(CDBARFIM,9,4))+1),4)
                    Case VSDGTPCOD="B-EAN8" :
                         CDBARFIM=SubStr(CDBARFIM,1,3)+AlinhM(StrVal(NumVal(SubStr(CDBARFIM,4,4))+1),4)
                  EndSwitch
           EndIf
  EndIf

EndWhile
Moveto Record Nreg
Up
LimpAguarde()

GERACAOOK=True
EndProc

;*******************************************************************************
;* Rotina Pega Codigo de Barras                                                *
;*******************************************************************************
Proc Pega_CdBarras(Tipo)
Private Tipo, CODBAR

CODBAR="?"

Moveto "Tmp_CB"
Moveto [Tipo CdBarras]
Locate Tipo
If RetVal
   Then CODBAR=""
        While [Tipo CdBarras]=Tipo
          If IsBlank([Codigo do Item])
             Then If Not IsLockRecord()
                     Then CODBAR          =[Codigo_Barras]
                          [Codigo do Item]=[Answer->Codigo do Item]
                          UnLockRecord
                          QuitLoop
                     Else Loop
                  EndIf
          Endif

          Skip
          If EOT() Then QuitLoop EndIf

        EndWhile

        If Not IsBlank(CODBAR)
           Then Moveto [Codigo do Item]
                Locate [Answer->Codigo do Item]
                If RetVal
                   Then While [Codigo do Item]=[Answer->Codigo do Item]
                          If [Codigo_Barras ]<>CODBAR
                             Then [Codigo do Item   ]=""
                                  [Descricao do Item]=""
                                  UnLockRecord
                          EndIf
                          Skip
                          If Eot()
                            Then QuitLoop
                          EndIf
                          Locate Next [Answer->Codigo do Item]
                          If Not RetVal
                             Then QuitLoop
                          Endif
                        EndWhile
                EndIf
        EndIf

Endif
Moveto "Answer"
Switch
  Case CODBAR="?":
       Mensagem("No existe intervalo de cĒdigo disponĄvel na tabela para "+Tipo)
       Continua_Geracao=False
       NReg=Recno()
  Case CODBAR="" :
       Mensagem("Fim do intervalo de cĒdigo disponĄvel na tabela para "+Tipo)
       Continua_Geracao=False
       NReg=Recno()
EndSwitch

Return CODBAR
EndProc


;*******************************************************************************
;* Rotina para Atualizar Dados                                                 *
;*******************************************************************************
Proc Atualizar()
FormKey

NR = NRecords("Answer")
Scan For [Codigo de Barras]<>"" And [Flag]="A"
  Barra(NR, RecNo())
  Aguarde("Aguarde, Atualizando "+BARRA_STRING)

  TudoOk=False
  Moveto "Itens"
  Moveto [Codigo do Item]
  Locate [Answer->Codigo do Item]
  If Not RetVal
     Then MENSAGEM([Codigo do Item]+", Item no atualizado, verificar !")
     Else For ii From 1 To 5
            If Not IsLockRecord()
               Then TudoOk=True
                    QuitLoop
            EndIf
          EndFor
  EndIf

  If TudoOk
     Then [Codigo de Barras  ]=[Answer->Codigo de Barras  ]
          [Tipo Codigo_Barras]=[Answer->Tipo Codigo_Barras]
          UnLockRecord

          TIPBAR=[Answer->Tipo Codigo_Barras]

          If TIPBAR="A-EAN13" or
             TIPBAR="B-EAN8"
             Then 
                  TIPBAR=RTrim(SubStr([Answer->Tipo Codigo_Barras],3,5))

                  Moveto "\\Sistemas\\Estoque\\Itens_CB"
                  Moveto [Codigo do Item]
                  Locate [Answer->Codigo do Item]
                  If RetVal
                     Then While True
                            [Codigo do Item   ]=""
                            [Descricao do Item]=""
                            UnLockRecord
                            Skip
                            If Eot()
                               Then QuitLoop
                            EndIf
                            Locate Next [Itens->Codigo do Item]
                            If Not RetVal
                               Then QuitLoop
                            Endif
                          EndWhile
                  EndIf

                  Moveto [Tipo CdBarras]
                  Locate TIPBAR,[Answer->Codigo de Barras]
                  If Not RetVal
                     Then End
                          Down
                          [Tipo CdBarras]=TIPBAR
                          [Codigo_Barras]=[Answer->Codigo de Barras]
                  EndIf
                  [Codigo do Item   ]=[Answer->Codigo do Item]
                  UnLockRecord

          EndIf
  EndIf

  Moveto "Answer"
EndScan
Do_It!

LimpAguarde()
Mensagem("Itens Atualizados !")

Endproc


;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_DialogI(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_OPCOD"          : Campo="NO"
            Case Campo="TG_CODINI"         : Campo="TG_OPCOD"
            Case Campo="TG_CODFIM"         : Campo="TG_CODINI"
            Case Campo="YES" Or Campo="NO" : Campo="TG_OPCOD"
          EndSwitch
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    ;** Selecao **
                    Case Campo="TG_OPCOD"      :
                         VSDGOPCOD=ControlValue("TG_OPCOD")
                         If VSDGOPCOD=1
                            Then Campo="TG_CODINI"
                            Else VSDGCODINI=""
                                 VSDGCODFIM=""
                                 Campo="YES"
                         EndIf
                    Case Campo="TG_CODINI"     :
                         VSDGCODINI=ControlValue("TG_CODINI")
                         Campo="TG_CODFIM"
                    Case Campo="TG_CODFIM"     :
                         VSDGCODFIM=ControlValue("TG_CODFIM")
                         Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPCOD":
     MSG_CAMPO="Selecione a opo desejada !"
     TECLA    ="=Selecionar  "
  Case Campo="":
     MSG_CAMPO=""
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* Rotina Filtrar Registros                                                    *
;*******************************************************************************
Proc Selecao(TIT)
Private TIT
LimpAguarde()

VSDGCODINI=""
VSDGCODFIM=""

While True

  ShowDialog "Gerar CĒdigos "+TIT Proc "SD_DialogI"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140
   @ 01,01 Height 14 Width 47

    Frame Single From 01,00 to 04,44
    Label @ 01,01 "Opo para CĒdigo " For "TG_OPCOD"
    RadioButtons @ 02,01 Height 2 Width 40
      "Usar ~I~ntervalo a informar",
      "Usar cĒdigo ~L~ivre da tabela"
        Tag "TG_OPCOD"
        To VSDGOPCOD

    Label  @ 06,00 "Faixa de CĒdigo" For "TG_CODINI"
    Label  @ 07,01 "de" For "TG_CODINI"
    Accept @ 07,06 Width 15 "A12"  Picture "#*#" Tag "TG_CODINI" To VSDGCODINI
    Label  @ 08,01 "at" For "TG_CODFIM"
    Accept @ 08,06 Width 15 "A12"  Picture "#*#" Tag "TG_CODFIM" To VSDGCODFIM

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

  EndDialog
  If RetVal
     Then If Not Checa_Codigo()
             Then Loop
             Else
                  If VSDGOPCOD=2
                     Then Do_It!
                          ClearAll

                          If IsTable("Tmp_cb")
                             Then Empty("Tmp_cb")
                          EndIf
                          Copy "Itens_CB" "Tmp_cb"

                          CoEdit "Answer"
                          {TableAdd} {Itens}
                          {TableAdd} {Itens_CB}
                          {TableAdd} {Tmp_CB}
                          Moveto "Answer"
                          GeraNum()
                          PickForm "5"

                     Else GeraNum()
                  EndIf
          EndIf
  EndIf

  QuitLoop
EndWhile

Echo Normal
Echo Off

EndProc


;*******************************************************************************
;* Rotina Checagem de Codigos                                                  *
;*******************************************************************************
Proc Checa_Codigo()

If VSDGOPCOD=2
   Then Return True
EndIf

If IsBlank(VSDGCODINI) Or
   IsBlank(VSDGCODFIM)
   Then Mensagem("Faxia de CĒdigo Inv lida, em branco !")
        Return False
EndIf

If Not E_Numerico(VSDGCODINI) Or
   Not E_Numerico(VSDGCODFIM)
   Then Mensagem("Faxia de CĒdigo Inv lida, sĒ digitos !")
        Return False
EndIf
If SubStr(VSDGCODINI,1,Len(VSDGCODINI)-1)>
   SubStr(VSDGCODFIM,1,Len(VSDGCODFIM)-1)
   Then Mensagem("Faxia de CĒdigo Inv lida, Inicial>Final !")
        Return False
EndIf

CDBAROk=True
Switch
  Case VSDGTPCOD="A-EAN13" :
    Switch
      Case Len(VSDGCODINI)>12 Or
           Len(VSDGCODFIM)>12:
        CDBAROK=False
        Mensagem("Informado CĒdigo de Barras EAN13 >12 digitos !")
      Case Len(VSDGCODINI)<12 Or
           Len(VSDGCODFIM)<12:
        CDBAROK=False
        Mensagem("Informado CĒdigo de Barras EAN13 <12 digitos !")
;      Case Mod11_CalcEAN13("CHEC",SubStr(VSDGCODINI,1,12))="" Or
;           Mod11_CalcEAN13("CHEC",SubStr(VSDGCODFIM,1,12))="":
;        CDBAROK=False
;        Mensagem("Informado CĒdigo de Barras EAN13 Inv lido !")
;      Case Mod11_CalcEAN13("CHEC",SubStr(VSDGCODINI,1,12))<>numVal(SubStr(VSDGCODINI,13,1)) Or
;           Mod11_CalcEAN13("CHEC",SubStr(VSDGCODFIM,1,12))<>numVal(SubStr(VSDGCODFIM,13,1)):
;        CDBAROK=False
;        Mensagem("Informado digito verificador inv lido !")
    EndSwitch

  Case VSDGTPCOD="B-EAN8"  :
    Switch
      Case Len(VSDGCODINI)>7 Or
           Len(VSDGCODFIM)>7:
        CDBAROK=False
        Mensagem("Informado CĒdigo de Barras EAN8 >7 digitos !")
      Case Len(VSDGCODINI)<7 Or
           Len(VSDGCODFIM)<7:
        CDBAROK=False
        Mensagem("Informado CĒdigo de Barras EAN8 <7 digitos !")
;      Case Mod11_CalcEAN8("CHEC",SubStr(VSDGCODINI,1,7))="" Or
;           Mod11_CalcEAN8("CHEC",SubStr(VSDGCODFIM,1,7))="":
;        CDBAROK=False
;        Mensagem("Informado CĒdigo de Barras EAN8 Inv lido !")
;      Case Mod11_CalcEAN8("CHEC",SubStr(VSDGCODINI,1,7))<>numVal(SubStr(VSDGCODINI,8,1)) Or
;           Mod11_CalcEAN8("CHEC",SubStr(VSDGCODFIM,1,7))<>numVal(SubStr(VSDGCODFIM,8,1)):
;        CDBAROK=False
;        Mensagem("Informado digito verificador inv lido !")
    EndSwitch

EndSwitch
If CDBAROK
   Then Return True
   Else Return False
EndIf

EndProc

;*******************************************************************************
;* 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: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_TIPOEST"        : Campo="NO"
            Case Campo="TG_FAMI"           : Campo="TG_TIPOEST"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_CODIGOI"        : Campo="TG_MARCA"
            Case Campo="TG_CODIGOF"        : Campo="TG_CODIGOI"
            Case Campo="TG_OPNUMCBAR"      : Campo="TG_CODIGOF"
            Case Campo="YES" Or Campo="NO" : Campo="TG_TIPOEST"
          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_TIPOEST"  : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"     : Campo="TG_GRP"
                    Case Campo="TG_GRP"      : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"    : Campo="TG_CODIGOI"
                    Case Campo="TG_CODIGOI"  : Campo="TG_CODIGOF"
                    Case Campo="TG_CODIGOF"  : Campo="TG_OPNUMCBAR"
                    Case Campo="TG_OPNUMCBAR": Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO=""
     TECLA    =""
  Case Campo="TG_OPNUMCBAR":
     MSG_CAMPO="Defina a opo"
     TECLA="Barra de Espao=Marca/Desmarca  "
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGTIPOEST     = ""
VSDGDESCTIPOEST = ""
VSDGFAMI        = ""
VSDGMARCA       = ""
VSDGGRP         = ""
VSDGCODIGOI     = ""
VSDGCODIGOF     = ""

Array TG_OPNUMCBAR[1]
TG_OPNUMCBAR[1]="Incluir Itens que j  tenham CĒdigos de Barras"

Array CheckTG_OPNUMCBAR[ArraySize(TG_OPNUMCBAR)]
CheckTG_OPNUMCBAR[1]=False

While True
 OP_SHOW="S"
 GERACAOOK=False

 ShowDialog "Gerao de Numerao para CĒdigo de Barras" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
   Key "F1","ENTER","ESC","TAB",
    -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140
    @ 01,01 Height 17 Width 55

    Label  @ 00,00 "Tipo do Estoque"  For "TG_TIPOEST"
    Accept @ 01,01 Width 04 "A1"  Picture "!" Tag "TG_TIPOEST" To VSDGTIPOEST
    Accept @ 01,06 Width 25 "A30"  Picture "!*!" Tag "TG_DESCTIPOEST" To VSDGDESCTIPOEST

    Label  @ 02,00 "Familia"  For "TG_FAMI"
    Accept @ 03,01 Width 07 "A3"  Picture "#*#" Tag "TG_FAMI" To VSDGFAMI
    Accept @ 03,09 Width 28 "A25" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

    Label  @ 04,00 "Grupo"  For "TG_GRP"
    Accept @ 05,01 Width 07 "A3"  Picture "#*#" Tag "TG_GRP" To VSDGGRP
    Accept @ 05,09 Width 28 "A25" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 06,00 "Marca"  For "TG_MARCA"
    Accept @ 07,01 Width 07 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 07,09 Width 28 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 08,00 "Faixa de CĒdigo" For "TG_CODIGOI"
    Label  @ 09,00 "de" For "TG_CODIGOI"
    Accept @ 09,04 Width 13 "A10"  Picture "#*#" Tag "TG_CODIGOI" To VSDGCODIGOI
    Label  @ 09,17 "at" For "TG_CODIGOF"
    Accept @ 09,22 Width 13 "A10"  Picture "#*#" Tag "TG_CODIGOF" To VSDGCODIGOF


    CheckBoxes @ 11,00 Height 1 Width 50 Tag "TG_OPNUMCBAR"
    TG_OPNUMCBAR[1] to CheckTG_OPNUMCBAR[1]

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  Processa()
  If IsEmpty("Answer")
     Then MENSAGEM("No existem registros a processar")
  EndIf
  Echo Normal
  Echo Off

  If IsTable("Tmp_cb")
     Then Delete "Tmp_cb"
  EndIf

EndWhile
ClearAll
Release Vars All
Release Procs All
