#include "fivewin.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
field ORDINE
local oDlg, oBrw, oFont, oServizi
local cSwapFields:="id,name,breve,price,image,struttura,unit,a4,pos,multiple,islock" //,ordine"
SET DELETED ON
BuildDBF()
oServizi := TDatabase():Open( , "SERVIZI", "DBFCDX", .T. )
oServizi:bTrigger := { || If( Empty( ORDINE ), ORDINE := RECNO(), nil ) }
oServizi:SetOrder( 0 )
oServizi:GoTop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 900,300 PIXEL TRUEPIXEL FONT oFont TITLE "SERVIZI.DBF"
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oServizi AUTOCOLS ;
LINES NOBORDER
WITH OBJECT oBrw
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:AutoFit()
:SetChecks()
:bChange := { || oDlg:AEvalWhen() }
//
:CreateFromCode()
END
@ 15, 20 BUTTON "ADD" SIZE 100,40 PIXEL OF oDlg ACTION AddRec( oBrw )
@ 15,240 BUTTON "UP" SIZE 100,40 PIXEL OF oDlg ;
WHEN oBrw:KeyNo > 1 ;
ACTION SwapRec( oBrw, VK_UP, cSwapFields )
@ 15,350 BUTTON "DOWN" SIZE 100,40 PIXEL OF oDlg ;
WHEN oBrw:KeyNo < oBrw:nLen ;
ACTION SwapRec( oBrw, VK_DOWN, cSwapFields )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function SwapRec( oBrw, nKey, cList )
local nRec, aRows
WITH OBJECT oBrw:oDbf
if nKey == VK_UP
:Skip( -1 )
if :Bof()
:GoTop()
else
nRec := :RecNo()
aRows := :DbfToArray( cList, nil, nil, 2 )
:GoTo( nRec )
if Len( aRows ) == 2
AINS( aRows, 1, aRows[ 2 ] )
:ArrayToDBF( aRows, cList, nil, .T. )
:GoTo( nRec )
endif
endif
elseif nKey == VK_DOWN
nRec := :RecNo()
aRows := :DbfToArray( cList, nil, nil, 2 )
:GoTo( nRec )
if Len( aRows ) == 2
AINS( aRows, 1, aRows[ 2 ] )
:ArrayToDBF( aRows, cList, nil, .T. )
:GoTo( nRec )
:Skip( 1 )
endif
endif
END
oBrw:Refresh()
oBrw:SetFocus()
return nil
//----------------------------------------------------------------------------//
static function AddRec( oBrw )
local oRec := oBrw:oDbf:Record( .t. )
oRec:oBrw := oBrw
oRec:FieldReadOnly( "ORDINE", .t. )
oRec:Edit()
return nil
//----------------------------------------------------------------------------//
Function BuildDbf()
field ID,NAME,ORDINE
local oDbf
local aCols := { ;
{ "id" , "C", 4, 0 },;
{ "name" , "C", 30, 0 },;
{ "breve" , "C", 10, 0 },;
{ "price" , "N", 9, 2 },;
{ "image" , "C", 30, 0 },;
{ "struttura","C", 30, 0 },;
{ "unit" , "N", 4, 0 },;
{ "a4" , "L", 1, 0 },;
{ "pos" , "L", 1, 0 },;
{ "multiple", "L", 1, 0 },;
{ "islock" , "L", 1, 0 },;
{ "ordine" , "N", 2, 0 } }
//sample data
local aData := { ;
{ "0001","Lettino","ser1",10,".\images\1.png","",100,.t.,.t.,.f.,.t.,1 }, ;
{ "0002","Sdraio","ser2",10,".\images\2.png","",100,.t.,.t.,.f.,.t.,2 }, ;
{ "0003","Regista","ser3",10,".\images\3.png","",100,.t.,.t.,.f.,.t.,3 }, ;
{ "0004","Parcheggio","parcheggio",10,".\images\4.png","",100,.t.,.t.,.f.,.t.,4 }, ;
{ "0005","Lettino+sdrario+regista","ser5",18,".\images\5.png","[lettino][sdraio][regista]",0,.t.,.t.,.t.,.t.,5 }, ;
{ "0006","sdrario+lettino","ser6",12,".\images\6.png","[sdraio][lettino]",0,.t.,.t.,.t.,.t.,6 }, ;
{ "0007","regista+lettino","ser7",16,".\images\7.png","[regista][lettino]",0,.t.,.t.,.t.,.t.,7 } }
oDbf := TDatabase():Create( "SERVIZI.DBF", aCols, "DBFCDX", "*" )
oDbf:ArrayToDbf( aData )
oDbf:Close()
RETURN NIL