Elegant way for lookup data in xbrowse

Elegant way for lookup data in xbrowse

Postby Marc Venken » Fri Feb 02, 2018 2:20 pm

Hello,

I have a browse with lots of rowse (dbf 300.000) and I want to have a result from a colomnheader that I click on.

Image

So if I click M7 then the calculation should begin and display the result as

Total Result

Send 2400
Uit 250
Bounce 110
...

So for every occurence of data, the same data should be added with 1

In my programming way, I would start a function,
select the master database
create a temp database
start the loop from masterdbf
every new item is added to temp, or cummulated with 1
afther the loop, display a browse with the result.

Works ok...

But Ive seens samples where there are functions being used like

AEval(), .... and others that seems to be able to do this stuff in only some small lines of code..

Any samples for this kind of statistic data retrieving ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1431
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Elegant way for lookup data in xbrowse

Postby nageswaragunupudi » Sat Feb 03, 2018 12:58 pm

Please try this code.
Code: Select all  Expand view

#include "fivewin.ch"

function Main()

   local oDlg, oBrw

   USE CUSTOMER SHARED
   DEFINE DIALOG oDlg SIZE 500,500 PIXEL TRUEPIXEL
   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CUSTOMER" ;
      COLUMNS "FIRST", "CITY", "STATE" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :City:bLClickHeader := { |r,c,f,oCol| ShowCount( oCol ) }
      :State:bLClickHeader := { |r,c,f,oCol| ShowCount( oCol ) }
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil

function ShowCount( oCol )

   local cFieldName  := oCol:cExpr
   local cSql, oRs

   cSql  := "SELECT " + cFieldName + ", COUNT(*) AS Num FROM <CTABLE> GROUP BY " + cFieldName
   oRs   := ( oCol:oBrw:cAlias )->( FW_DBFSQLQUERY( nil, cSql, nil, .t. ) )
   XBROWSER oRs
   oRs:Close()
   oRs:ActiveConnection:Close()

return nil
 


Try clicking headers "City" and "State"

If you like you may adapt the logic.
Regards

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

Re: Elegant way for lookup data in xbrowse

Postby Marc Venken » Sat Feb 03, 2018 9:25 pm

Thanks !!

Works absolut perfect...in just 2 lines of code.

Very interesting sample ! Combination of Sql with dbf. This gives lot of potentials I think.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1431
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

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