#define MSG_DBE_NOT_LOADED   " database engine not loaded"
#define MSG_DBE_NOT_CREATED  " database engine could not be created"

#include "inkey.ch"
#include "cdxdbe.ch"
#include "dbfdbe.ch"
#include "setcurs.ch"
#include "appevent.ch"

Procedure Main
*
*Begin
   Local bIns, bI, bEsc, bC, OP, cNOM, nCOD, G
   Local GETLIST :={}
   dbUseArea( .T., 'DBFCDX', 'ADUANA', 'AD01', .F. )
   If ( !File( 'ADUANA.CDX' ) )
      AD01->( ordCreate( 'ADUANA', 'IND01', 'NOMBRE', { || AD01->NOMBRE } ) )
    Else
      AD01->( dbSetIndex( 'ADUANA' ) )
   EndIF
   BIns := { || SetCursor( If( ReadInsert( !ReadInsert() ), SC_NORMAL, SC_INSERT ) ) }
   bI   := SetKey( K_INS, BIns )
   bC   := SetCursor( If( ReadInsert(), SC_INSERT, SC_NORMAL ) )
   bEsc := Set( _SET_ESCAPE, .f. )
   Scroll()
   nCOD := Space( 0 )
   cNOM := Space( 20 )
   OP   := ' '
   @  0, 0 Say 'Pantalla de Prueba de Manejos de Gets'
   @  2, 0 Say 'Ingrese Despacho de Aduana :' Get cNOM Picture '@!' Valid { || Valid001( @cNOM, @nCOD ) }
   @ 10, 0 Say 'Confirma Datos ? (S/N)' Get OP Picture '!' Valid { || OP $ 'SN' }
   @ 12, 0 Say Replicate( '-', MaxCol() )
   Read
   G := LastKey()
   SetKey(K_INS, bI ); Set(_SET_INSERT, .f. ); SetCursor( bC ); Set( _SET_ESCAPE, bEsc )
   If ( OP = 'S' .And. G != K_ESC )
      Alert( 'Dato Cargado !' )
   EndIF
   Return
*End;
*
*
Function Valid001( cNOM, nCOD )
*Begin
   Local lRET := .F., PAN
   AD01->( dbSeek( AllTrim( cNOM ), .T., 1 ) )
   PAN :=SaveScreen( 13, 0, 24, 79 )
   AD01->( dbEdit( 13, 0, 24, 40, { 'AD01->NOMBRE' }, { 'Aduanas' }, { '@!' } ) )
   If ( LastAppEvent() != xbeK_ESC )
      nCOD := AD01->CODIGO
      cNOM := AD01->NOMBRE
      lRET := .T.
   EndIF
   RestScreen( 13, 0, 24, 79, PAN )
   Return ( lRET )
*End;
*

Procedure AppSys()
*
*Begin
   Local oCrt
   oCrt := XbpCRT():New():Create( SetAppWindow(), AppDesktop(), { 100, 100 },,, 'Prueba' )
   SetAppWindow( oCrt )
   Return
*End;
*
Procedure DBESYS()
*
*Begin
   Local aDbes, aBuild, i
   SET DATE TO BRITISH
   SET CHARSET TO OEM
   SET COLLATION TO ASCII
   aDbes := { { "DBFDBE", .T.},;
              { "NTXDBE", .T.},;
              { "CDXDBE", .T.},;
              { "DELDBE", .F.},;
              { "SDFDBE", .F.} }
   aBuild :={ { "DBFCDX", 1, 3 } }
   For i  := 1 To Len( aDbes )
      If !( DbeLoad( aDbes[i,1], aDbes[i,2] ) )
         MsgBox( aDbes[i,1] + MSG_DBE_NOT_LOADED )
      EndIF
   Next i

   For i:= 1 TO Len( aBuild )
      If !( dbeBuild( aBuild[i,1], aDbes[ aBuild[i,2], 1 ], aDbes[ aBuild[i,3], 1 ] ) )
         MsgBox( aBuild[i,1] + MSG_DBE_NOT_CREATED )
      EndIF
   Next i
   dbeinfo( COMPONENT_DATA , DBFDBE_LOCKMODE, DBF_NOLOCK )
   dbeInfo( COMPONENT_ORDER, DBE_LOCKMODE    , LOCKING_STANDARD )
   Return
*End;
*
