Page 1 of 1

Report group and header

Posted: Mon Feb 24, 2025 1:33 pm
by Silvio.Falconi
On report sample 10 (rep10.prg)

I saw there is the command for make a group

Code: Select all | Expand

 GROUP ON Test->State ;
           FOOTER "Total State "+oReport:aGroups[1]:cValue+ ;
                  " ("+ltrim(str(oReport:aGroups[1]:nCounter))+")" ;
           FONT 2 ;
           EJECT

If I wish create a dialog before the rep10.prg and make a selection by user for select with a combobox the group comand How I must make ?

sample

Code: Select all | Expand

@ 12, 10 COMBOBOX oRag[2] VAR nGroup ITEMS  aGroup  OF oDlgOptions SIZE 300, 30 PIXEL FONT oFont HEIGHTGET 16 

How do I connect the user's choice to the group that has to make the report class?

then on header ( rep10)

Code: Select all | Expand

  REPORT oReport TITLE  "*** My First Report ***"  ;
          FONT oFont1, oFont2 ;
          PREVIEW
I with insert the pages and the total pages

I tried with

local nTotalpages:= oReport:oDevice:cLastPage

HEADER ' ', "Data: "+dtoc(date())+ " Pagina.: "+str(oReport:nPage,3)+"/"+nTotalpages

But not run

Re: Report group and header

Posted: Mon Feb 24, 2025 4:58 pm
by Antonio Linares
Dear Silvio,

Using the xcommand you get the oGroup object:

Code: Select all | Expand

#xcommand GROUP [ <oRptGrp> ] ;
                [ ON <bGroup> ] ;
                [ HEADER <bHead> ] ;
                [ FOOTER <bFoot> ] ;
                [ FONT <uFont> ] ;
                [ <lEject:EJECT> ] ;
        => ;
        [ <oRptGrp> := ] RptAddGroup( <{bGroup}>, <{bHead}>, ;
                <{bFoot}>, <{uFont}>, <.lEject.> )
So you can modify the oGroup DATAs:

Code: Select all | Expand

     DATA oReport
     DATA aTotal
     DATA bGroup, bHeader, bFooter, bHeadFont, bFootFont
     DATA cValue, cOldValue
     DATA nCounter, nHeaderHeight, nFooterHeight, nOrder
     DATA lEject, lNeedStart, lHeader, lFooter
     DATA Cargo

Re: Report group and header

Posted: Tue Feb 25, 2025 10:34 am
by Silvio.Falconi
Antonio Linares wrote: Mon Feb 24, 2025 4:58 pm Dear Silvio,

Using the xcommand you get the oGroup object:

Code: Select all | Expand

#xcommand GROUP [ <oRptGrp> ] ;
                [ ON <bGroup> ] ;
                [ HEADER <bHead> ] ;
                [ FOOTER <bFoot> ] ;
                [ FONT <uFont> ] ;
                [ <lEject:EJECT> ] ;
        => ;
        [ <oRptGrp> := ] RptAddGroup( <{bGroup}>, <{bHead}>, ;
                <{bFoot}>, <{uFont}>, <.lEject.> )
So you can modify the oGroup DATAs:

Code: Select all | Expand

     DATA oReport
     DATA aTotal
     DATA bGroup, bHeader, bFooter, bHeadFont, bFootFont
     DATA cValue, cOldValue
     DATA nCounter, nHeaderHeight, nFooterHeight, nOrder
     DATA lEject, lNeedStart, lHeader, lFooter
     DATA Cargo
as I already explained to you, it's not that I don't know how to do the GROUP in the REPORT CLASS

the problem is different


Image


I want to let the user select the group to group through a combobox, I use Tdatabase

1) if I use the xbrowse bsetup ( oBrw:report)

Code: Select all | Expand

AAdd(oRep:aGroups,trGroup():New( bCampo2( afields, nGroup,oDbf ),; //field
{|| aGroup[nGroup]+" :"+oRep:aGroups[1]:cValue},; //header
{|| "Total "+aGroup[nGroup]+": "+oRep:aGroups[1]:cValue+" ("+ltrim(str(oRep:aGroups[1]:nCounter))+")"},; //footer
{|| 1 },; // Font
.f.,oRep))


Code: Select all | Expand

Static function bCampo2( aCampos, nFor,oDbf ) //tdatabase
return (fieldWBlock(aCampos[nFor],oDbf:nArea ))

2) if I use the Report class directly
I have difficulty inserting a Macro example:

Code: Select all | Expand

fieldname:= agroup[nselect][1]
fieldtitle:= agroup[nselect][2]

GROUP ON ::oDbf:&fieldname;
HEADER fieldtitle +"» "+::oReport:aGroups[1]:cValue ;
FOOTER fieldtitle +"» "+::oReport:aGroups[1]:cValue +;
"("+ltrim(str(::oReport:aGroups[1]:nCounter))+")" ;
FONT 1

Re: Report group and header

Posted: Tue Feb 25, 2025 1:10 pm
by Silvio.Falconi
now i changed the selection combobox putting "none" in third place

Image

then before to call oBrw:report() I made

Code: Select all | Expand

 
    If nGroup>1
         aGroupby  := {nGroup}
      elseif  nGroup==3   //none
         aGroupby  := {}
      Endif

//index the dbf
   IF  oDbf != NIL
      If nGroup >1  .and.  nGroup < 3
        oDbf:setorder(nGroup)
        oDbf:gotop()
        oBrw:oDbf:SetOrder(nGroup)
        oBrw:oDbf:Gotop()
        xbrowser oBrw:odbf
        xbrowser oDbf

     elseif  nGroup==3    //none
        oBrw:SetOrder()
      Endif
  Endif
  
  

call oBrw:report

oBrw:Report( cTitle, , , ;
{ |oRep, oBrw| MySetUp( oRep, oBrw, oDbf,aGroup,nGroup,lEject,aCampi ) },,,aCols )

this is the result of group

Image


two questions

1) I wish a line after the header of group where you see the orange arrow

Image


2) the alternate lines do not work, I tried with the normal report class and with these commands it seems to work

on report normal

Code: Select all | Expand


oReport:oShdBrush  := TBrush():New(,nRgb(219,229,241))
     AEval( oReport:aColumns, { | o | o:lShadow := ! o:lShadow } )
    oReport:bStartLine := { || IF(oReport:nCounter % 2 = 0 , oReport:lShadow :=.F.,oReport:lShadow :=.T.)   }

If I insert the same lines on mysetup of xbrowse

Code: Select all | Expand

 
    oRep:oShdBrush := TBrush():New(,nRgb(219,229,241))
     AEval( oRep:aColumns, { | o | o:lShadow := ! o:lShadow } )
     oRep:bStartLine := { || IF(oRep:nCounter % 2 = 0 , oRep:lShadow :=.F.,oRep:lShadow :=.T.)   }
Not run, why ?


but I discovered a bug a long time ago

I 'm talking of MakeRepCol( oRep, oXCol ) function

I discovered when call RptAddColumn() shadow value is .f.

Code: Select all | Expand

oCol := RptAddColumn( aHeader, nil ,;
                            { bData }, nSize, nil ,;
                            nil, nil, nil ,;
                            "RIGHT", .F., .F., nil, ;
                            nil, nil, ;
                            nil, nil, nil, nil, nil, ;
                            nil, nil, nil, nil, nil, nil, ;
                            nil, ;
                            XEval( oxCol:nProgTot , oxCol ), aClr )
the lshadow is the ten value and it is FALSE

question
how can it work if the value is always false?

Re: Report group and header

Posted: Tue Feb 25, 2025 1:37 pm
by Silvio.Falconi
Solution for me


Report( cTitle, lPreview, lModal, bSetUp, aGroupBy, cPDF, aCols , lShadow )

local oRep, oPrn, oFont, oBold, uRet
local nFor, uBookMark
local oBrw := Self
local lAddCols := .T.
local nRows, nSel, n
local lEof := .f.
local lSetUpTwice := .f.
local nLevels
local nRowSel := ::nRowSel

DEFAULT cTitle := If( ::oWnd:ClassName == 'TPANEL', ::oWnd:oWnd:cTitle, ::oWnd:cTitle )
DEFAULT lPreview := .T.
DEFAULT lModal := .T.
DEFAULT lShadow :=.f.


....


for nFor := 1 to Len( aCols )
if AScan( aGroupBy, { |o| o:nCreationOrder == aCols[ nFor ]:nCreationOrder } ) == 0
MakeRepCol( oRep, aCols[ nFor ], lShadow )
endif


static function MakeRepCol( oRep, oXCol,lshadow )
....
oCol := RptAddColumn( aHeader, nil ,;
{ bData }, nSize, nil ,;
nil, nil, nil ,;
"RIGHT", lShadow, .F., nil, ;
nil, nil, ;
nil, nil, nil, nil, nil, ;
nil, nil, nil, nil, nil, nil, ;
nil, ;
XEval( oxCol:nProgTot , oxCol ), aClr )


suggestions ?