operaciones entre campos en un xBrowse

operaciones entre campos en un xBrowse

Postby José Camilo » 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
José Camilo
 
Posts: 210
Joined: Wed Apr 07, 2021 3:56 pm

Re: operaciones entre campos en un xBrowse

Postby cmsoft » Thu Sep 09, 2021 3:26 pm

Code: Select all  Expand view

oBrw:aCols[5]:bStrData := {||  if (base->impapag=0,base->importe - base->monto, base->impapag - base->monto)}
 
User avatar
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: operaciones entre campos en un xBrowse

Postby cnavarro » Thu Sep 09, 2021 7: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: operaciones entre campos en un xBrowse

Postby nageswaragunupudi » Tue Sep 14, 2021 3:08 am

We recommend a very simple way.
Directly include the expression in your columns clause like this:
Code: Select all  Expand view

@ 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 view

#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 view

#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
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: operaciones entre campos en un xBrowse

Postby cmsoft » 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: Select all  Expand view

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
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: operaciones entre campos en un xBrowse

Postby nageswaragunupudi » Wed Sep 15, 2021 11:36 am

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

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


modify as
Code: Select all  Expand view

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
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: operaciones entre campos en un xBrowse

Postby cmsoft » Wed Sep 15, 2021 1:49 pm

Mr. Rao, gracias por la respuesta.
Perdon mi ignorancia pero seguro algo estoy haciendo mal
Me da este error
Code: Select all  Expand view

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 view

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: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: operaciones entre campos en un xBrowse

Postby cmsoft » Wed Sep 15, 2021 1:55 pm

nageswaragunupudi wrote:
Code: Select all  Expand view

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


modify as
Code: Select all  Expand view

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
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: operaciones entre campos en un xBrowse

Postby nageswaragunupudi » Wed Sep 15, 2021 5:36 pm

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 view

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 view

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
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: operaciones entre campos en un xBrowse

Postby cmsoft » Thu Sep 16, 2021 4:17 pm

Mr. Rao, desde que version de Fivewin funciona esta capacidad?
Porque me da un error, pero tengo la versión 16...
User avatar
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests