2 questions 1

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
citro
Posts: 52
Joined: Wed Dec 22, 2010 3:45 pm

2 questions 1

Post by citro »

I set up a grid (GRID ) detail orders where items that make it appear . The Item code column has a VALID validation that calls a function that checks whether a code exists in the event that there is no open another form where I deploy the list of items that are to choose one. The first thing I see is that on the form that displays the list , where the list is armed with a BROWSE, although the table to open the BROWSE so:

use stock new shared
ordsetfocus ( 1) / / Order by item code
go top

when the list displays the first screen shot shows the records in the order established , but ends positioning itself in any code , not the first in the order . That would be a question, and the other is that if you do not select any items that form is displayed , when I return to the main form if I want to go thereof either by closing the window or by pressing the exit button , I still displaying the form with the items to select .
Antonio
Sistemas
Resipol
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: 2 questions 1

Post by Javier Tovar »

Hola citro,

1.- Necesitas que se seleccione en el primer Item: Cuando definas la Grid pon VALUE 1 o VALUE {1,1} según sea el caso.
2.- No entiendo lo que quieres hacer.
2.1.- De un formulario llamas a la Grid para seleccionar un registro y quieres que se pasen los datos al formulario?
2.2.- O quieres borrar los Items de la Grid?
2.3.- O...?

Saludos
citro
Posts: 52
Joined: Wed Dec 22, 2010 3:45 pm

Re: 2 questions 1

Post by citro »

Hola Javier, es algo simple, cuando el código no existe que despliegue una grilla para poder seleccionar el código del artículo (en este caso). Está en VALUE 1, es un BROWSE, porque cuando usé un GRID se quedó colgado el programa, el BROWSE es así:

@ 35,200 BROWSE broInsp ;
WIDTH 440 ;
HEIGHT 245 ;
HEADERS aHeaders ;
WIDTHS aWidths ;
WORKAREA insp ;
FIELDS aFields ;
VALUE 1 ;
BACKCOLOR {255,255,200} ;
INPUTMASK aCtrl ;
JUSTIFY aJustify ;
ON GOTFOCUS {|| bGotFocus( q ),lGrid:=.t. } ;
ON LOSTFOCUS {|| lBrowse:=.f.,lGrid:=.f.,lExit:=.f. }

Como la idea es usar ese mismo BROWSE para mostrar no solo artículos, sino clientes, proveedores, cuentas bancarias, etc., está armado de esta manera, ya que la tabla "insp", es el alias de una tabla cualquiera, por ej.:

use stock alias insp
o
use clientes alias insp

según lo que quiera mostrar. Al márgen de esto. lo que ocurre es que en este caso no se porque en lugar de mostrarme desde el artículo "000000" que es el primero de los 27000 que hay en la tabla me aparece seleccionado uno con código "VG990099" que no es el último según el orden pero si estaría dentro de la última tanda de artículos. La función bGotFocus habilita o deshabilita determinados botones:

/***/
static Function bGotFocus( opc )

lBrowse:=.t.
if opc = OPARTICULOS .or. opc = CLIENTES .or. opc = VENDEDOR .or. opc = PROVEEDO
forminspecto.btnDetalle.enabled:=.t.
forminspecto.btnAltk.enabled:=.t.
end if

retu Nil
Antonio
Sistemas
Resipol
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: 2 questions 1

Post by Javier Tovar »

Bueno Citro,

Tratando de entender lo que quieres hacer, lo que crees que no es correcto es que se posiciona en un registro que no es el primero?, si es así entonces tienes que llamar primero a la base de datos a usar, después al indice adecuado y por ultimo hacer un GoTop() y ya de esa manera con seguridad se va a posicionar en el primero. También puedes hachar mano de Goto(1).

Te recomiendo que uses el alias con el mismo nombre de la DBF, de esa manera sabrás que Base de datos esta llamando.

use stock alias stock

Antes del Browse:

Code: Select all

   DBSELECTAREA( "stock" )    //Lama a la Base de Datos "Stock"
   DBSETORDER('ICodigo')       // Le dice a la BD que use el indice "ICodigo"
   Stock->(DBGoTop())         // Le dice al apuntador de la BD que se posicione al Primer registro, de acuerdo al indice usado.
   Stock->(DBGoto(1))   // aquí este sale sobrando ya que DBGoTop() se posiciona en el primero.
Siempre debes de hacer esto, para asegurar en que tabla estas trabajando.

Espero que te sirva :D

Saludos
Last edited by Javier Tovar on Thu Apr 17, 2014 5:10 pm, edited 1 time in total.
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: 2 questions 1

Post by Javier Tovar »

Citro,

También puedes poner en el Browse cualquier Base de Datos poniendo en el Browse:

WORKAREA &Ficher


Siendo Ficher := "Stock" o
Siendo Ficher := "Clientes"

Esto lo hacer antes de llamar al Browse.

Seria algo así:

Code: Select all

   LlamoBrowse('Stock')

   PROCEDURE LlamoBrowse(Ficher)
      ..........
       @ 35,200 BROWSE broInsp ;
       WIDTH 440 ; 
       HEIGHT 245 ;	
       HEADERS aHeaders ;
       WIDTHS aWidths ;
       WORKAREA &Ficher ;        //   <<<<================================
       FIELDS aFields ;
       VALUE 1 ;
       BACKCOLOR {255,255,200} ;
       INPUTMASK aCtrl ;
       JUSTIFY aJustify ;
       ON GOTFOCUS {|| bGotFocus( q ),lGrid:=.t. } ;
       ON LOSTFOCUS {|| lBrowse:=.f.,lGrid:=.f.,lExit:=.f. }
       ..........

   RETURN NIL
Espero haberme explicado :D

Saludos
citro
Posts: 52
Joined: Wed Dec 22, 2010 3:45 pm

Re: 2 questions 1

Post by citro »

Acá arme un ejemplo compilable de lo que hace el BROWSE con una tabla de 1000 registros ordenada por 2 campos (rubro+clave)

#include "hmg.ch"

/***/
Function Main()

REQUEST DBFCDX , DBFFPT
RDDSETDEFAULT( "DBFCDX" )
SET NAVIGATION EXTENDED

DBCREATE( "Test1", ;
{ {"Rubro", "C", 2, 0}, ;
{"Clave", "C",14, 0}, ;
{"detalle","C",25, 0} } )

USE Test1 NEW

i:=999
whil i >= 0
APPEND BLANK
REPLACE rubro WITH "AA"
REPLACE clave WITH '0000000000'+ STRzero( i,3 )
replace detalle with "AA" +strzero( i,3 )
i--
end whil
index on rubro+clave tag test1
go top

DEFINE WINDOW FormInspecto ;
AT 0,0 ;
WIDTH 700 ;
HEIGHT 410 ;
MAIN ;
NOSIZE ;
ON RELEASE {|| CierraTabla() } ;
BACKCOLOR {0,128,255}

aHeaders:={ "Artículo","Desc. Doc." }
aWidths :={ 150,240 }
aFields :={ 'rubro +clave','detalle' }

aJustify:={ BROWSE_JTFY_LEFT,BROWSE_JTFY_LEFT }
aCtrl :={ {'TEXTBOX','STRING',"!!!!!!!!!!!!!!!!" },Nil }

@ 35,200 BROWSE broInsp ;
WIDTH 440 ;
HEIGHT 245 ;
HEADERS aHeaders ;
WIDTHS aWidths ;
WORKAREA Test1 ;
FIELDS aFields ;
VALUE 1 ;
BACKCOLOR {255,255,200} ;
INPUTMASK aCtrl ;
JUSTIFY aJustify

END WINDOW

CENTER WINDOW FormInspecto
ACTIVATE WINDOW FormInspecto

return Nil

/***/
static Function CierraTabla()

DbCloseAll()

ferase( "test1.dbf" )
ferase( "test1.cdx" )

retu Nil

Cargué la tabla en orden inverso, porque si la cargo en forma ascendente, el problema no se ve. Cuando compilo y ejecuto este ejemplo el browse una vez cargado se posiciona en el último registro en lugar del primero, aún habiendo puesto un go top luego de generar el índice. Supongo que es una falla, y del browse, porque en el Grid no lo hace, pero el problema que hay con el Grid es que tarda el triple de tiempo en cargar la tabla, por lo menos eso me pasa en una red con puestos XP y servidor Windows 2008 Server.
Antonio
Sistemas
Resipol
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: 2 questions 1

Post by Javier Tovar »

Hola Citro,

Hay veces que nuestra lógica no esta bien y queremos ver cosas que no pueden ser.

En tu ejemplo es claro y esta bien que se seleccione el registro que esta:
ErrorCitro.jpg
ErrorCitro.jpg (58.76 KiB) Viewed 2911 times
Ya que este registro es el primero que se creo y se guardo en la DBF, o no?. Su valor de Recno() = 1

y forma ascendente:
Ascendente.jpg
Ascendente.jpg (67.26 KiB) Viewed 2911 times
Tambien esta bien, ya que el registro que esta seleccionado fue el primero que se creo.


NOTA: También toma en cuenta que el Browse tiene VALUE 1; , si le quitas esta sentencia será mejor, ya que aquí le dices que se posicione en el primero. Tienes que jugar con:

1.- Con Test1->(dbGoTop()) Despues obtienes el Numero de registro nRegistro := Recno()
2.- ConTest1->(dbGoBottom()) Despues obtienes el Numero de registro nRegistro := Recno()
3.- El valor del Browse, FormInspecto.broInsp.Value := nRegistro

Saludos :D
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: 2 questions 1

Post by Javier Tovar »

Codigo Ascendente:

Code: Select all


#include "hmg.ch"

/***/
Function Main()

PRIVATE nRegistro := 0

REQUEST DBFCDX , DBFFPT
RDDSETDEFAULT( "DBFCDX" )
SET NAVIGATION EXTENDED

DBCREATE( "Test1", ;
{ {"Rubro", "C", 2, 0}, ;
{"Clave", "C",14, 0}, ;
{"detalle","C",25, 0} } )

USE Test1 NEW 

i:=0
whil i <= 999
APPEND BLANK
REPLACE rubro WITH "AA"
REPLACE clave WITH '0000000000'+ STRzero( i,3 )
replace detalle with "AA" +strzero( i,3 )
i++
end whil
index on rubro+clave tag test1
Test1->(dbGoTop())                         // <<<<=================
*Test1->(dbGoBottom())                    // <<<<=================
*nRegistro := Recno()                        // <<<<=================

DEFINE WINDOW FormInspecto ;
AT 0,0 ; 
WIDTH 700 ;
HEIGHT 410 ;
MAIN ;
NOSIZE ;
ON RELEASE {|| CierraTabla() } ;
ON INIT VerBrowse() ;                    // <<<<=================
BACKCOLOR {0,128,255} 

aHeaders:={ "Artículo","Desc. Doc." }
aWidths :={ 150,240 }
aFields :={ 'rubro +clave','detalle' }

aJustify:={ BROWSE_JTFY_LEFT,BROWSE_JTFY_LEFT }	
aCtrl :={ {'TEXTBOX','STRING',"!!!!!!!!!!!!!!!!" },Nil }

@ 35,200 BROWSE broInsp ;
WIDTH 440 ; 
HEIGHT 245 ;	
HEADERS aHeaders ;
WIDTHS aWidths ;
WORKAREA Test1 ;
FIELDS aFields ;
BACKCOLOR {255,255,200} ;
INPUTMASK aCtrl ;
JUSTIFY aJustify

END WINDOW 

CENTER WINDOW FormInspecto
ACTIVATE WINDOW FormInspecto

return Nil	

/***/
static Function CierraTabla()

DbCloseAll()

ferase( "test1.dbf" )
ferase( "test1.cdx" )

retu Nil


PROCEDURE VerBrowse()                                                 // <<<<=================
*	FormInspecto.broInsp.Value := nRegistro
*	FormInspecto.broInsp.Refresh
RETURN NIL

Saludos :D
Post Reply