operaciones entre campos en un xBrowse

Post Reply
José Camilo
Posts: 212
Joined: Wed Apr 07, 2021 3:56 pm

operaciones entre campos en un xBrowse

Post by José Camilo »

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
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: operaciones entre campos en un xBrowse

Post by cmsoft »

Code: Select all | Expand


oBrw:aCols[5]:bStrData := {||  if (base->impapag=0,base->importe - base->monto, base->impapag - base->monto)}
 
User avatar
cnavarro
Posts: 6558
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: operaciones entre campos en un xBrowse

Post by cnavarro »

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
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: operaciones entre campos en un xBrowse

Post by nageswaragunupudi »

We recommend a very simple way.
Directly include the expression in your columns clause like this:

Code: Select all | Expand


@ 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: Select all | Expand


#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: Select all | Expand


#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
 


Image

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
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: operaciones entre campos en un xBrowse

Post by cmsoft »

Mr. Rao, sieguiendo con el hilo, como podría hacer para reemplazar esto con el formato que ud. indica?

Code: Select all | Expand


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
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: operaciones entre campos en un xBrowse

Post by nageswaragunupudi »

Code: Select all | Expand

// 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: Select all | Expand


oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
 


modify as

Code: Select all | Expand


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
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: operaciones entre campos en un xBrowse

Post by cmsoft »

Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error

Code: Select all | Expand


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: Select all | Expand


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'
 
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: operaciones entre campos en un xBrowse

Post by cmsoft »

nageswaragunupudi wrote:

Code: Select all | Expand


oBrw:aCols[3]:bStrData := {|| IF(oQry:RecCount()> 0,aTurno[oQry:turno]," ")}
 


modify as

Code: Select all | Expand


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!!!
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: operaciones entre campos en un xBrowse

Post by nageswaragunupudi »

cmsoft wrote:Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error

Code: Select all | Expand


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: Select all | Expand


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
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: operaciones entre campos en un xBrowse

Post by cmsoft »

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