BROWSE - Agregando items

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

BROWSE - Agregando items

Post by edufloriv »

Saludos compañeros, esperando todos se encuentren bien de salud:

Siempre he preferido trabajar con BROWSE (aunque sé que recomiendan usar GRID) pero lo hago por el tema que se me hace más fácil realizar mantenimiento, ya que si un cliente me pide agregar una columna, es bien sencillo realizarlo, mientras el GRID al trabajar con matrices implica el movimiento de más código fuente.

El tema es que, ya lo había notado antes, pero no me dediqué tiempo a tratar de solucionarlo, cuando defino un BROWSE de más de 14 o 15 líneas pasa que al agregar un ítem más, al realizar el refresh, el primer item del browse se desplaza hacia arriba y se esconde, a pesar de que abajo hay mucho espacio disponible. No sé como puedo controlar o evitar esto:
browse-1.png
browse-1.png (108.34 KiB) Viewed 1125 times
browse-2.png
browse-2.png (126.69 KiB) Viewed 1125 times
Bueno, solo por si acaso coloco el código que arma el browse:

Code: Select all

*
*    BOTONES DETALLES
*
   @ 210 , 008 BUTTON BotAgregar ;
   PICTURE 'imagen\agregar.bmp' ;
   ACTION Cotiza_ItemAdd() ;
   WIDTH 32 ;
   HEIGHT BOT_ITEMH

   @ 210+BOT_ITEMH+10 , 008 BUTTON BotEditar ;
   PICTURE 'imagen\editar.bmp' ;
   ACTION Cotiza_ItemEdit() ;
   WIDTH 32 ;
   HEIGHT BOT_ITEMH

   @ 210+(BOT_ITEMH*2)+20 , 008 BUTTON BotBorrar ;
   PICTURE 'imagen\borrar.bmp' ;
   ACTION Cotiza_ItemDel() ;
   WIDTH 32 ;
   HEIGHT BOT_ITEMH
*
*    BROWSE DE DETALLES
*
   @ 210 , 050 BROWSE BrwArticulos ;
   WIDTH  nAGW ;
   HEIGHT nAGH ;
   FONT "Arial" SIZE 12 ;
   HEADERS {'Artículo'        , 'Marca'          ,'Unids.'         ,'Lote'           ,'Vence'                   ,'Prec.Uni.'       ,'Total'           } ;
   WIDTHS  aAGA ;
   FIELDS  {'ODTMP->OD_ARTNOM','ODTMP->OD_ARTLAB','ODTMP->OD_UNIDS','ODTMP->OD_LOTE' ,'ODTMP->(STOC(OD_VENCE))' ,'ODTMP->OD_PRCUNI','ODTMP->OD_PRCVAL'} ;
   JUSTIFY { BrwL             , BrwL             , BrwC            , BrwL            , BrwL                     , BrwR             , BrwR             } ;
   WORKAREA ODTMP ;
   BACKCOLOR Mi_Celeste_Claro ;
   ON DBLCLICK Cotiza_ItemEdit()
   
Y el código para agregar el item:

Code: Select all

*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------

PROC Cotiza_ItemAdd

LOCAL aArtiCodigo
LOCAL aArtiDatos
LOCAL aArtiNuevos

   IF ! CTZ_EDIT = .T.
      RETURN
   ENDIF
   
   SELE ODTMP
   COUNT FOR ODTMP->(DELETED()) = .F. TO nDetalles
   IF nDetalles = 20
      MsgInfo('Ya no se pueden agregar más items.')
      RETURN
   ENDIF

   aArtiCodigo := Ayuda_Arti()
   IF LEN(aArtiCodigo) > 0
      IF Cotiza_GetItem( 'Agregar' , aArtiCodigo[1] )
         nNewRec := ODTMP->(RECNO())
         Cotiza_CalculaTotal()
         SELE ODTMP
         DBGOTOP()
         Win_Cotiza.BrwArticulos.Value := ODTMP->(RECNO())
         Win_Cotiza.BrwArticulos.Refresh
         Win_Cotiza.BrwArticulos.Value := nNewRec
      ENDIF
   ENDIF

   IF IsWindowDefined( Win_Cotiza )
      Win_Cotiza.BotAgregar.SetFocus
   ENDIF

RETURN
Estaré atento a sus comentarios. Cordiales saludos a todos.

Eduardo Flores Rivas


LIMA - PERU
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: BROWSE - Agregando items

Post by AUGE_OHR »

hi,

you are moving Pointer of DBF

Code: Select all

         DBGOTOP()
         Win_Cotiza.BrwArticulos.Value := ODTMP->(RECNO())
         Win_Cotiza.BrwArticulos.Refresh
         Win_Cotiza.BrwArticulos.Value := nNewRec
have fun
Jimmy
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: BROWSE - Agregando items

Post by edufloriv »

Thanks for your time Auge,

You are right, I have changed the code thus:

Code: Select all

*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------

PROC Cotiza_ItemAdd

LOCAL aArtiCodigo
LOCAL aArtiDatos
LOCAL aArtiNuevos

   IF ! CTZ_EDIT = .T.
      RETURN
   ENDIF
   
   SELE ODTMP
   COUNT FOR ODTMP->(DELETED()) = .F. TO nDetalles
   IF nDetalles = 20
      MsgInfo('Ya no se pueden agregar más items.')
      RETURN
   ENDIF

   aArtiCodigo := Ayuda_Arti()
   IF LEN(aArtiCodigo) > 0
      IF Cotiza_GetItem( 'Agregar' , aArtiCodigo[1] )
         Cotiza_CalculaTotal()  
         Win_Cotiza.BrwArticulos.Refresh
      ENDIF
   ENDIF

   IF IsWindowDefined( Win_Cotiza )
      Win_Cotiza.BotAgregar.SetFocus
   ENDIF

RETURN
And now, when I add an item, the cursor appears before the last item added:
browse-3.png
browse-3.png (112.79 KiB) Viewed 1102 times
How could I put the cursor selecting the last item added without using Win_Cotiza.BrwArticulos.Value = ?

Best regards,

*-----------------------------------------------------------------------------------------------------------------------------------
*-----------------------------------------------------------------------------------------------------------------------------------
*-----------------------------------------------------------------------------------------------------------------------------------

Gracias por tu tiempe Auge,

Tienes razón, he cambiado el código así:

Code: Select all

*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------

PROC Cotiza_ItemAdd

LOCAL aArtiCodigo
LOCAL aArtiDatos
LOCAL aArtiNuevos

   IF ! CTZ_EDIT = .T.
      RETURN
   ENDIF
   
   SELE ODTMP
   COUNT FOR ODTMP->(DELETED()) = .F. TO nDetalles
   IF nDetalles = 20
      MsgInfo('Ya no se pueden agregar más items.')
      RETURN
   ENDIF

   aArtiCodigo := Ayuda_Arti()
   IF LEN(aArtiCodigo) > 0
      IF Cotiza_GetItem( 'Agregar' , aArtiCodigo[1] )
         Cotiza_CalculaTotal()  
         Win_Cotiza.BrwArticulos.Refresh
      ENDIF
   ENDIF

   IF IsWindowDefined( Win_Cotiza )
      Win_Cotiza.BotAgregar.SetFocus
   ENDIF

RETURN
Ahora, cuando agrego un item, el cursor se queda en el item anterior al item agregado:
browse-3.png
browse-3.png (112.79 KiB) Viewed 1102 times
¿ Como puedo seleccionar el último item agregado sin usar Win_Cotiza.BrwArticulos.Value = ?

Cordiales saludos,

Eduardo Flores Rivas


LIMA - PERU
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: BROWSE - Agregando items

Post by AUGE_OHR »

hi,

is a Index open on DBF :?:
oBrowse:Refresh() will re-read DBF so if you have a active Index it might be not last Record

---
not sure if this will help you

Code: Select all

old_Order := SETORDER(0) // no active Index
APPEND BLANK
DoEdit
SETORDER(old_Order)

Code: Select all

PROCEDURE DoEdit()
   cObj := "TEXT_" + STRZERO( i, 3 )
   ...
   DEFINE TEXTBOX &cObj
      ONCHANGE IF( lEdit = .T., DoChange( oBroEdit, This.Name, aStruc, cBroMacro ), )

Code: Select all

PROCEDURE DoChange( cForm, cObj, aStruc, cBroMacro )
LOCAL xValue, cFeld, cPosi, nItem
   cPosi := STRTRAN( cObj, "TEXT_", "" )
   cFeld := aStruc[ VAL( cPosi ) ] [ DBS_NAME ]
   xValue := GetProperty( cForm, cObj, "VALUE" )
   IF RLOCK()
      IF aStruc[ VAL( cPosi ) ] [ DBS_TYPE ] = "T" .OR. aStruc[ VAL( cPosi ) ] [ DBS_TYPE ] = "@"
         REPLACE &( cFeld ) WITH hb_StrToTS( xValue )
      ELSE
         REPLACE &( cFeld ) WITH xValue
      ENDIF
      UNLOCK
   ENDIF
#IFDEF Use_DataBrowse
   RefreshBrowseLine( cBroMacro, "BrowserView", aStruc )
#ELSE
   RefreshCurrent( cBroMacro, "BrowserView" )
#ENDIF
RETURN

Code: Select all

PROCEDURE RefreshBrowseLine( cForm, cBrowse, aStruc )
LOCAL i, iMax
LOCAL cField, cType, xValue
LOCAL h, nIdx, nRow
   nIdx := GetControlIndex( cBrowse, cForm )
   h := GetControlHandle( cBrowse, cForm )
   nRow := LISTVIEW_GETFIRSTITEM( h )  // this function returns current screen row number
   iMax := LEN( aStruc )
   FOR i := 1 TO iMax
      cField := aStruc[ i ] [ DBS_NAME ]
      cType := aStruc[ i ] [ DBS_TYPE ]
      xValue := &( cField )
      DO CASE
         CASE cType == "N" .OR. cType == "I"
            xValue := hb_ntos( xValue )
         CASE cType == "D"
            xValue := HB_VALTOSTR( xValue )
         CASE cType == "L"
            xValue := HB_VALTOSTR( xValue )
         CASE cType == "@" .OR. cType = "T"
            xValue := hb_TSToStr( xValue )
      ENDCASE
      SetProperty( cForm, cBrowse, "CELL", nRow, i, xValue )
   NEXT i
RETURN
this will "update" Browse "on-fly" when type into TEXTBOX
have fun
Jimmy
Post Reply