#include "fivewin.ch"
REQUEST DBFCDX
static cPath
Function test()
Local oDlg,oElementi,oGrid
Local aBrowse
cPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
oElementi := TDatabase():Open( ,cPath+ "ELEMENTI", "DBFCDX", .T. )
oElementi:SetOrder( 1 )
oElementi:GoTop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 400, 280 PIXEL;
FONT oFont TITLE "Elements"
aBrowse := { { "ELATTIVO", i18n("Attivo"),, 80, },;
{ "ELNOME", i18n("Descrizione elemento"),, 80, },;
{ "", i18n("Colore "),, 80, },;
{ "ELCOLORE", i18n("Descr. Colore"),, 80, },;
{ "ELORDINE", i18n("Ordine"),, 80, },;
{ "ELLOCK", i18n("Bloccato"),, 200,} }
@0,5 XBROWSE oGrid ;
SIZE 180,100 PIXEL;
OF oDlg ;
DATASOURCE oElementi COLUMNS aBrowse
WITH OBJECT oGrid
:nClrBorder := CLR_GRAY
:nMarqueeStyle := MARQSTYLE_HIGHLWIN7
:lHscroll := .F.
:l2007 := .F.
:l2015 := .T.
:nStretchCol := STRETCHCOL_WIDEST
:lAllowRowSizing := .F.
:lAllowColSwapping := .F.
:lAllowColHiding := .F.
:lRecordSelector := .F.
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_NOLINES
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:CreateFromCode()
END
@ 112,2 BTNBMP PROMPT "Order" SIZE 40,20 LEFT PIXEL OF oDlg ;
ACTION Ordine_Elementi(oGrid,oElementi)
activate dialog oDlg
return nil
//----------------------------------------------------------------------------//
function Ordine_Elementi(oGrid,oElementi)
local oDlg, oBrw, oFont
local cSwapFields:="ELNUMERO,ELORDINE,ELNOME,ELCOLORE,ELATTIVO,ELIMGLIB,ELIMGOCC,ELIMGALT,ELLOCK"
oElementi:setorder(0)
oElementi:gotop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 900,300 PIXEL TRUEPIXEL FONT oFont;
TITLE "ELEMENTI.DBF"
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oElementi 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:SetDefault( "ELORDINE", { || oBrw:oDbf:LastRec() + 1 }, .F. )
oRec:Edit()
return nil
//-----------------------------------------------------------------------------------------------//
Function BuildDbf()
field ID,NAME,ORDINE
local oDbf
local aCols := { ;
{ "ELNUMERO" , "C", 2, 0 },; //NUMERO
{ "ELORDINE" , "N", 2, 0 },; //ORDINE
{ "ELNOME" , "C", 30, 0 },;
{ "ELCOLORE" , "C", 30, 0 },;
{ "ELATTIVO" , "L", 1, 0 },;
{ "ELIMGLIB" , "C", 120, 0 },;
{ "ELIMGOCC" , "C", 120, 0 },;
{ "ELIMGALT" , "C", 120, 0 },;
{ "ELLOCK" , "L", 1, 0 }}
Local aData := { ;
{"01",1,"OMBRELLONE","lightgreen",.T.,".\images\ombrellone_verde.png",".\images\ombrelloneOccupato.png",".\images\ombrellone_bianco.png",.T.}, ;
{"02",2,"PALMA","red",.T.,".\images\palma.png",".\images\palmaOccupato.png",".\images\palma_arancio.png",.T.}, ;
{"03",3,"CABINA","thistle",.T.,".\images\cabina.png",".\images\cabinaOccupato.png",".\images\cabina_arancio.png",.T.}, ;
{"04",4,"TENDA","coral",.T.,".\images\tenda.png",".\images\tendaOccupato.png",".\images\tenda_blue.png",.T.}, ;
{"05",5,"BIDONE","gainsboro",.F.,".\images\bidone.png","","",.T. }, ;
{"06",6,"PASSERELLA A INCROCIO","burlywood",.F.,".\images\passerella_incrocio.png","","",.T. }, ;
{"07",7,"PASSERELLA A L","cadetblue",.F.,".\images\passerella_L.png","","",.T. }, ;
{"08",8,"PASSERELLA L DESTRA","darkgoldenrod",.F.,".\images\passerella_L_destra.png","","",.T.}, ;
{"09",9,"PASSERELLA L SINISTRA","darkturquoise",.F.,".\images\passerella_L_sinistra.png","","",.T. }, ;
{"10",10,"PASSERELLA L SOPRA","gold",.F.,".\images\passerella_L_sopra.png","","",.T. }, ;
{"11",11,"PASSERELLA ORIZONTALE","whitesmoke",.F.,".\images\passerella_orizzontale.png","","",.T. }, ;
{"12",12,"PASSERELLA A T SOPRA","deepskyblue",.F.,".\images\passerella_T_sopra.png","","",.T. }, ;
{"13",13,"PASSERELLA A T SOTTO","deepskyblue",.F.,".\images\passerella_T_sotto.png","","",.T. }, ;
{"14",14,"PASSERELLA VERTICALE","firebrick",.F.,".\images\passerella_verticale.png","","",.T.}, ;
{"15",15,"PALMA ORNAMENTALE","darkkhaki",.F.,".\images\palmaC.png","","",.T. }, ;
{"16",16,"GIOCHI","turquoise",.F.,".\images\giochi.png","","",.T. }, ;
{"17",17,"BAGNINO","darkorchid",.F.,".\images\torretta.png","","",.T.}}
oDbf := TDatabase():Create(cPath+ "ELEMENTI.DBF", aCols, "DBFCDX", "*" )
oDbf:ArrayToDbf( aData )
oDbf:Close()
RETURN NIL
//-----------------------------------------------------------------------------------//