#include "fivewin.ch"
REQUEST DBFCDX
FIELD ICODE
//----------------------------------------------------------------------------//
function Main()
CreateArticleTable()
CreateStockTable()
DoBrowse()
BrowseAsPivotTable()
return nil
//----------------------------------------------------------------------------//
static function DoBrowse()
local oDlg, oFont, oBrw
USE ARTICLE NEW SHARED VIA "DBFCDX"
SET ORDER TO TAG ICODE
GO TOP
USE STOCK NEW SHARED VIA "DBFCDX"
SET RELATION TO ICODE INTO ARTICLE
GO TOP
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 700,200 PIXEL FONT oFont ;
TITLE "USING RDD"
@ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
DATASOURCE "STOCK" ;
COLUMNS "ARTICLE->INAME", ;
"IF( WH_ID == 'W1', QTY, 0 )", ;
"IF( WH_ID == 'W2', QTY, 0 )", ;
"IF( WH_ID == 'W3', QTY, 0 )" ;
HEADERS "Article", "STK1", "STK2", "STK3" ;
CELL LINES NOBORDER
WITH OBJECT oBrw
:lDisplayZeros := .f.
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function CreateArticleTable()
local aCols := { { "ICODE", 'C', 2, 0 }, { "INAME", 'C', 20, 0 } }
local aData := { { "01", "Computers" }, { "02", "Laptops" }, { "03", "Printers" }, { "04", "UPS" } }
DBCREATE( "ARTICLE.DBF", aCols, "DBFCDX", .t., "MAS" )
INDEX ON ICODE TAG ICODE
FW_ArrayToDBF( aData )
CLOSE MAS
return nil
//----------------------------------------------------------------------------//
static function CreateStockTable()
local aCols := { { "ICODE", 'C', 2, 0 }, { "WH_ID", 'C', 2, 0 }, { "QTY", 'N', 5, 0 } }
local aData := { { "01", "W1", 10 }, { "02", "W2", 5 }, { "03", "W3", 5 } }
DBCREATE( "STOCK.DBF", aCols, "DBFCDX", .t., "STK" )
INDEX ON ICODE TAG ICODE
FW_ArrayToDbf( aData )
CLOSE STK
return nil
//----------------------------------------------------------------------------//
static function BrowseAsPivotTable()
local cPath := cFilePath( ExeName() ) // file path of DBF tables
local oCn, cSql, aPivot, oRs
oCn := FW_OpenAdoConnection( cPath )
if oCn == nil
? "Ado Connect fail"
return nil
endif
TEXT INTO cSql
SELECT A.INAME AS ARTICLE, WH_ID AS WAREHOUSE, QTY
FROM STOCK S
LEFT OUTER JOIN ARTICLE A ON S.ICODE = A.ICODE
ENDTEXT
aPivot := FW_AdoPivotArray( oCn, cSql, "Article", "WareHouse", "QTY", "SUM" )
XBROWSER aPivot SETUP oBrw:lDisplayZeros := .f. ;
TITLE "FWH ADO POWER"
oCn:Close()
return nil
//----------------------------------------------------------------------------//