FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour operaciones entre campos en un xBrowse
Posts: 212
Joined: Wed Apr 07, 2021 03:56 PM
operaciones entre campos en un xBrowse
Posted: Wed Sep 08, 2021 11:13 PM

Buenas tardes. necesito mostrar en un a columna de un xBrowse el resultado de la resta de campos de acuero a una determinada situacion.
algo asi : if (impapag=0,("importe" - "monto"),("impapag"-"monto")) donde tanto impapag como importe como monto son campos de la misma base.
gracias

Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: operaciones entre campos en un xBrowse
Posted: Thu Sep 09, 2021 03:26 PM
Code (fw): Select all Collapse
oBrw:aCols[5]:bStrData := {||  if (base->impapag=0,base->importe - base->monto, base->impapag - base->monto)}
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: operaciones entre campos en un xBrowse
Posted: Thu Sep 09, 2021 07:01 PM

Cesar prueba en su lugar la data :bEditValue

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operaciones entre campos en un xBrowse
Posted: Tue Sep 14, 2021 03:08 AM
We recommend a very simple way.
Directly include the expression in your columns clause like this:
Code (fw): Select all Collapse
@ r,c XBROWSE oBrw SIZE w,h OF oDlg ;
DATASOURCE Alias() ;
COLUMNS "IMPAPAG","IMPORTE","MONTO","IF(IMPAPAG=0,IMPORTE-MONTO,IMPAPAG-MONTO)" ;
HEADERS nil, nil, nil, "RESULT"


We highly recommend using this syntax.

This syntax is portable and can be used with any datasource DBF, TDatabase, ADO, MySql/MariaDB, etc.

Here is a working sample
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   FWNumFormat( "E", .t. )

   XBROWSER "invitems.dbf" ;
      COLUMNS "ITEMCODE", "QUANTITY", "PRICE", "QUANTITY*PRICE" ;
      SETUP ( oBrw:aCols[ 4 ]:cHeader := "VALUE", ;
              oBrw:aCols[ 4 ]:cEditPicture := NUMPICT(9,2) )

return nil


If your version of FWH is not very old, you can also write:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   FWNumFormat( "E", .t. )

   XBROWSER "invitems.dbf" ;
      COLUMNS "ITEMCODE", "QUANTITY", "PRICE", ;
         "QUANTITY*PRICE AS VALUE PICT '@E 999,999.99'"

return nil




The expression can be of any degree of complexity, but should be macro expandable.
Do not use alias names. XBrowse applies the correct alias.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: operaciones entre campos en un xBrowse
Posted: Tue Sep 14, 2021 10:55 PM
Mr. Rao, sieguiendo con el hilo, como podría hacer para reemplazar esto con el formato que ud. indica?
Code (fw): Select all Collapse
aTurno  := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
aEstado := {"Abierto","Cerrado","Abierto Parcial"}
aTipo   := {"Completo","Cortado"}
REDEFINE XBROWSE oBrw DATASOURCE oQry;
              COLUMNS "id","fecha","turno","nombre","tipo","estado","gnc","productos","ctacte","efectivo","tarjeta","retiros","faltante";
              HEADERS "#","Fecha","Turno","Playero","Tipo","Estado","GNC","Productos","Cta.Cte","Efectivo","Tarjeta","Retiros","Falt/Sobr";
              SIZES 50,70,90,120,70,90,70,70,70,70,70,70,70;
              ID 111 OF oDlg AUTOSORT ON DBLCLICK (VerCerrar(),oBrw:Refresh())
     REDEFINE SAY oBrw:oSeek PROMPT "" ID 113 OF oDlg
     oQry:bOnChangePage := {|| oBrw:Refresh() }
     oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
     oBrw:aCols[5]:bStrData := {|| IF(oQry:RecCount()> 0,aTipo[oQry:tipo]," ")}
     oBrw:aCols[6]:bStrData := {|| IF(oQry:RecCount()> 0,aEstado[oQry:estado]," ")}

En la base de datos, guardo el código del tipo de turno
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operaciones entre campos en un xBrowse
Posted: Wed Sep 15, 2021 11:36 AM
Code (fw): Select all Collapse
// PRIVATE not LOCAL
PRIVATE aTurno  := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo   := {"Completo","Cortado"}

REDEFINE XBROWSE oBrw DATASOURCE oQry;
              COLUMNS "id","fecha","aTurno[turno]","nombre","aTipo[tipo]","aEstado[estado]","gnc","productos","ctacte","efectivo","tarjeta","retiros","faltante";
              HEADERS "#","Fecha","Turno","Playero","Tipo","Estado","GNC","Productos","Cta.Cte","Efectivo","Tarjeta","Retiros","Falt/Sobr";
              SIZES 50,70,90,120,70,90,70,70,70,70,70,70,70;
              SORT nil,nil,"TURNO",nil,"TIPO","ESTADO" ;
              ID 111 OF oDlg AUTOSORT ON DBLCLICK (VerCerrar(),oBrw:Refresh())
     REDEFINE SAY oBrw:oSeek PROMPT "" ID 113 OF oDlg
     oQry:bOnChangePage := {|| oBrw:Refresh() }


BUT

Please do not change your code.

In this particular case, I advise you to keep your existing code with this minor modification in the bStrData codeblock.

Instead of:
Code (fw): Select all Collapse
oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}


modify as
Code (fw): Select all Collapse
oBrw:aCols[3]:bStrData := {|x,o| aTurno[o:Value] }


Why this change?
Now your code does not refer to a specific oQry object.

Later if you want to change the software/browse to use ADO for MySql or FWH MariaLib libray, the same code works without any changes. This way the code is highly portable and can be used with any datasource.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: operaciones entre campos en un xBrowse
Posted: Wed Sep 15, 2021 01:49 PM
Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error
Code (fw): Select all Collapse
PROCEDURE TURNOS(cPermisos)
LOCAL oBar, hHand
PRIVATE aTurno  := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo   := {"Completo","Cortado"}

Code (fw): Select all Collapse
turnos.prg(12) Warning W0002  Ambiguous reference, assuming memvar 'ATURNO'
turnos.prg(13) Warning W0002  Ambiguous reference, assuming memvar 'AESTADO'
turnos.prg(14) Warning W0002  Ambiguous reference, assuming memvar 'ATIPO'
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: operaciones entre campos en un xBrowse
Posted: Wed Sep 15, 2021 01:55 PM
nageswaragunupudi wrote:
Code (fw): Select all Collapse
oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}


modify as
Code (fw): Select all Collapse
oBrw:aCols[3]:bStrData := {|x,o| aTurno[o:Value] }


Why this change?
Now your code does not refer to a specific oQry object.

Later if you want to change the software/browse to use ADO for MySql or FWH MariaLib libray, the same code works without any changes. This way the code is highly portable and can be used with any datasource.

Esto funciono perfecto!!!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operaciones entre campos en un xBrowse
Posted: Wed Sep 15, 2021 05:36 PM
cmsoft wrote:Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error
Code (fw): Select all Collapse
PROCEDURE TURNOS(cPermisos)
LOCAL oBar, hHand
PRIVATE aTurno  := {"06:00 a 14:00","09:00 a 13:00","14:00 a 22:00","16:00 a 20:00","22:00 a 06:00"}
PRIVATE aEstado := {"Abierto","Cerrado","Abierto Parcial"}
PRIVATE aTipo   := {"Completo","Cortado"}

Code (fw): Select all Collapse
turnos.prg(12) Warning W0002  Ambiguous reference, assuming memvar 'ATURNO'
turnos.prg(13) Warning W0002  Ambiguous reference, assuming memvar 'AESTADO'
turnos.prg(14) Warning W0002  Ambiguous reference, assuming memvar 'ATIPO'

Either
Add declaration MEMVAR aTurno, aEstado, aTipo

OR
much easier

Add -a compiler switch in your script
( -a stands for automatic memvar declaration)
Regards



G. N. Rao.

Hyderabad, India
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: operaciones entre campos en un xBrowse
Posted: Thu Sep 16, 2021 04:17 PM

Mr. Rao, desde que version de Fivewin funciona esta capacidad?
Porque me da un error, pero tengo la versión 16...

Continue the discussion