Xbrowse maketotals question

Xbrowse maketotals question

Postby Richard Chidiak » Wed Jul 21, 2010 4:04 pm

Hello

I have a xbrowse within a dialog , 12 value columns and a column containing the total ,

The 12 values can be edited , my xbrowse allows editing of these columns and i need to sum all columns

The columns are correctly shown

The last column can not be edited and i want it to be summed,

Adding a obrw:maketotals() to the update function produce a very strange result, the total column where the data is entered is doubled , editing the cell again without change , the column total is reset correctly. The last column is summed correctly in this case. Looks like the sum is evaluated twice ?

Removing the maketotals() from the update function, columns are correctly calculated but last column is not summed

I am using fwh 10.5

Any idea ?
Code: Select all  Expand view


REDEFINE XBROWSE oBrw ID 201 OF ODLG ;
         COLUMNS "LIBELLE","PREV01","PREV02","PREV03","PREV04","PREV05","PREV06","PREV07","PREV08","PREV09","PREV10","PREV11","PREV12","TOTPREV" ;
         HEADERS "Famille","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre","Total" ;
         PICTURES nil, "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99", "@Z 999 999 999.99", ;
                       "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99" , "@Z 999 999 999.99", "@Z 999 999 999.99", "@Z 999 999 999.99" ;
         COLORS {|| { CLR_BLUE, CLR_WHITE } } ;
         ALIAS FUSER lines FOOTERS AUTOSORT

oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
oBrw:lColDividerComplete := .t.
oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:bClrHEADER := {|| { CLR_BLUE, COULDLG("TD") } }

oBrw:nFreeze       := 1
oBrw:nCOLSEL       := 2

AEVAL(oBrw:aCols, { |DLIB,X | SETCOLBRW(X,OBRW,FUSER,ASIZE) } )

oBrw:aCols[1]:cFooter := "Total"


ODLG:bSTART := { || OBRW:MAKETOTALS(),OBRW:SETFOCUS() }


STATIC FUNCTION SETCOLBRW(x,OBRW,FUSER,ASIZE)
oBrw:aCols[X]:nWidth  := ASIZE[X]
IF X > 1
   oBrw:aCols[X]:nFooterType := AGGR_TOTAL
   IF X < 14
      oBrw:aCols[X]:nEditType   := 1
      oBrw:aCols[x]:bOnPostEdit := {|o, v, n| iif( n != VK_ESCAPE, UPDPREV(v,OBRW,X,@FUSER), ) }
   ENDIF
ENDIF
RETURN NIL

STATIC FUNCTION UPDPREV(DVAL,OBRW,NCOL,FUSER)
LOCAL ANCVAL  := 0, ;
      DT

DT     := "PREV" + STRTRAN(STR(NCOL-1,2)," ","0")
ANCVAL := (FUSER)->&DT

LOCKENR(FUSER)
(FUSER)->&DT     := DVAL
(FUSER)->TOTPREV += (DVal - ANCVAL)
(FUSER)->(DBUNLOCK())

// OBRW:MAKETOTALS()  //if i uncomment this line , last column is summed but all other colums are doubled !!!
OBRW:REFRESH()
RETURN NIL


 
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Xbrowse maketotals question

Postby nageswaragunupudi » Thu Jul 22, 2010 6:51 am

i suggest this way:
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'ord.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

function Main()

   local oDlg, oBrw

   RDDSetDefault( 'DBFCDX' )
   XbrNumFormat( 'A', .T. )

   CreateDbf()  // creating DBF for this test

   USE FUSER SHARED

   DEFINE DIALOG oDlg SIZE 950,200 PIXEL
   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS ;
      ALIAS 'FUSER' ;
      CELL LINES FOOTERS NOBORDER

   AEval( oBrw:aCols, { |oCol| SetColBrw( oCol ) }, 2, 12 )

   WITH OBJECT oBrw
      :PrevTot:nFooterType := AGGR_SUM
      :aCols[ 1 ]:cFooter  := 'TOTALS'
      :nFreeze             := 1
      :nColSel             := 2
      :MakeTotals()
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   CLOSE FUSER

return nil

static function SetColBrw( oCol )

   local oBrw  := oCol:oBrw

   WITH OBJECT oCol
      :nEditType     := EDIT_GET
      :nFooterType   := AGGR_SUM
      :bOnChange     := { | o, nOldValue | ;
                            FUSER->PREVTOT += ( o:Value - nOldValue ), ;
                            oBrw:MakeTotals( oBrw:PrevTot ), ;
                            oBrw:PrevTot:RefreshFooter() }
   END

return nil

static function CreateDbf()

   local aCols := {{"LIBELLE", "C", 10, 0 }}
   local n,m, nTot

   for n := 1 to 12
      AAdd( aCols, { "PREV" + StrZero( n, 2 ), 'N', 12, 2 } )
   next n
   AAdd( aCols, { "PREVTOT", 'N', 12, 2 } )

   DBCREATE( "FUSER.DBF", aCols )

   // Create data
   USE FUSER EXCLUSIVE
   for n := 1 to 5
      APPEND BLANK
      FieldPut( 1, 'Name' + STRZERO( n, 2 ) )
      for m := 2 to 13
         FieldPut( m, HB_RandomInt( 10,90 ) * 1000 )
         FieldPut( 14, FieldGet( 14 ) + FieldGet( m ) )
      next
   next
   CLOSE FUSER

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Xbrowse maketotals question

Postby Richard Chidiak » Thu Jul 22, 2010 12:09 pm

Thank you Mr RAO

The sample is OK, and i made a change to my program,

The bonchange code block made it work ok as expected,

Thank you for your help ,

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests