#include "Fivewin.ch"
#include "xbrowse.ch"
REQUEST DBFCDX
Function main()
local nWd := GetSysMetrics(0) * .58
local nHt := GetSysMetrics(1) / 2.5
local oDlg,oFont,oBold
local oBrw,oBar
local oBtn:=array(3)
local aData:= {}
local cCod_temp:= "00001" // to demo
local oDbf
local cDir:= cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
RddSetDefault( "DBFCDX" )
SetHandleCount( 100 )
FWNumFormat( "E", .t. )
SET DATE FORMAT "dd-mm-yyyy"
SET DELETED ON
SET CENTURY ON
SET EPOCH TO year( date() ) - 20
SET MULTIPLE OFF
oFont := TFont():New( "Tahoma", 0, 18,, )
oBold := TFont():New( "Tahoma", 0, 16,,.t. )
// Creation Dbf for Demo test
Build_Dbf(cDir) // create dbf
// Open dDbf
oDbf:=TSample():New()
oDbf:setorder(1)
oDbf:Gotop()
// take the records for cCod_temp
aData := oDbf:DbfToArray( , { ||FIELD->cod == cCod_temp } )
DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL ; //TRUEPIXEL
TITLE "test numeric" ;
FONT oFont COLOR CLR_BLACK, CLR_WHITE ;
STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
WS_MINIMIZEBOX)
//---------------------------------------------------------------------//
DEFINE BUTTONBAR oBar OF oDlg SIZE 80,70 BOTTOM NOBORDER 2015
DEFINE BUTTON oBtn[1] OF oBar ;
FILENAME "DLG_NO";
PROMPT "Add" TOOLTIP "Esci" ;
ACTION Modify(oBrw,1,oFont)
DEFINE BUTTON oBtn[2] OF oBar ;
FILENAME "HLP_DLG";
PROMPT "Modify" TOOLTIP "Aiuto" ;
ACTION Modify(oBrw,2,oFont) GROUP
DEFINE BUTTON oBtn[3] OF oBar BTNRIGHT ;
FILENAME "DLG_OK";
PROMPT "Exit" ;
TOOLTIP "Conferma i dati" ;
ACTION ( oDlg:end( IDOK ) )
//--------------------------------------------------------------------------//
@ 2, 5 XBROWSE oBrw OF oDlg ;
COLUMNS 2,3,4,5;
HEADERS "Peso1","Peso2","Peso3","Peso4" ;
COLSIZES 90,90,90,90 ;
ARRAY aData ;
SIZE -5,-60 PIXEL STYLE FLAT NOBORDER
WITH OBJECT oBrw
:lHScroll := .f.
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oDlg:resize(), ChangeButtons( oBar ) )
return nil
//------------------------------------------------------------------//
function ChangeButtons( oBar )
AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
FUNCTION Modify(oBrowse,nMode,oFont) // cesar test
LOCAL oDlg1, oGet := array(4)
local nVar := {' 0',' 0',' 0',' 0'}, oBot1
local nRecord:= oBrowse:nArrayAt
local ntest1,ntest2,ntest3,ntest4
local cPicture:="@9" //"@Z 999.99"
local aGet:= array(4)
local nWd := GetSysMetrics(0) * .58
local nHt := GetSysMetrics(1) / 4
local oBtn1,oBtn2,oBar
IF nMode==2 //modify
ntest1 := STRTRAN(str(oBrowse:aArraydata[nRecord][2]), ".", ",")
ntest2 := STRTRAN(str(oBrowse:aArraydata[nRecord][3]), ".", ",")
ntest3 := STRTRAN(str(oBrowse:aArraydata[nRecord][4]), ".", ",")
ntest4 := STRTRAN(str(oBrowse:aArraydata[nRecord][5]), ".", ",")
Endif
SET CONFIRM ON
DEFINE DIALOG oDlg1 SIZE nWd, nHt PIXEL ;
TITLE "test numeric" ;
FONT oFont COLOR CLR_BLACK, CLR_WHITE ;
STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
WS_MINIMIZEBOX)
//-------------------------------------------------------------------//
DEFINE BUTTONBAR oBar OF oDlg1 SIZE 70,70 2015 BOTTOM NOBORDER
DEFINE BUTTON oBtn1 OF oBar ;
FILENAME "DLG_NO";
PROMPT "Annulla" TOOLTIP "Esci" ;
ACTION ( oDlg1:end( IDCANCEL ) )
DEFINE BUTTON oBtn2 OF oBar BTNRIGHT ;
FILENAME "DLG_OK";
PROMPT "Conferma" ;
TOOLTIP "Conferma i dati" ;
ACTION ( oDlg1:end( IDOK ) )
//-------------------------------------------------------------------//
@ 70, 20 GET aGet[1] VAR ntest1 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 82 GET aGet[2] VAR ntest2 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 245 GET aGet[3] VAR ntest3 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
@ 70, 295 GET aGet[4] VAR ntest4 OF oDlg1 SIZE 32, 12 PIXEL FONT oFont PICTURE cPicture UPDATE RIGHT
aGet[1]:bLostFocus := {|| (aGet[1]:Assign(),aGet[1]:cText := STR(VAL(aGet[1]:cText) /100,6,2), aGet[1]:Refresh()) }
aGet[2]:bLostFocus := {|| (aGet[2]:Assign(),aGet[2]:cText := STR(VAL(aGet[2]:cText) /100,6,2), aGet[2]:Refresh()) }
aGet[3]:bLostFocus := {|| (aGet[3]:Assign(),aGet[3]:cText := STR(VAL(aGet[3]:cText) /100,6,2), aGet[3]:Refresh()) }
aGet[4]:bLostFocus := {|| (aGet[4]:Assign(),aGet[4]:cText := STR(VAL(aGet[4]:cText) /100,6,2), aGet[4]:Refresh()) }
aGet[1]:bGotFocus := {|| (aGet[1]:cText := STR(VAL(aGet[1]:cText) *100,6), aGet[1]:Refresh(),aGet[1]:SelectAll()) }
aGet[2]:bGotFocus := {|| (aGet[2]:cText := STR(VAL(aGet[2]:cText) *100,6), aGet[2]:Refresh(),aGet[2]:SelectAll()) }
aGet[3]:bGotFocus := {|| (aGet[3]:cText := STR(VAL(aGet[3]:cText) *100,6), aGet[3]:Refresh(),aGet[3]:SelectAll()) }
aGet[4]:bGotFocus := {|| (aGet[4]:cText := STR(VAL(aGet[4]:cText) *100,6), aGet[4]:Refresh(),aGet[4]:SelectAll()) }
ACTIVATE DIALOG oDlg1 CENTERED ;
ON INIT ( oDlg1:resize(), ChangeButtons( oBar ) )
IF oDlg1:nresult == IDOK
oBrowse:aArraydata[nRecord][2]:= ntest1
oBrowse:aArraydata[nRecord][3]:= ntest2
oBrowse:aArraydata[nRecord][4]:= ntest3
oBrowse:aArraydata[nRecord][5]:= ntest4
endif
RETURN nil
//------------------------------------------------------------------------------------//
Function Build_Dbf(cDir)
local lAppend := .F.
FIELD cod
local aFields := { { "Cod", "C", 5, 0 },;
{ "test1", "N", 6, 2 },;
{ "test2", "N", 6, 2 },;
{ "test3", "N", 6, 2 },;
{ "test4", "N", 6, 2 }}
IF !lIsDir(alltrim(cDir))
IF !lMkDir(cDir)
MsgAlert("Attention")
ENDIf
ENDIf
if File( cdir+"sample.dbf" )
if !File( cdir+"sample.cdx" )
USE &(cdir+"sample") NEW EXCLUSIVE ALIAS DB
INDEX ON Cod TAG COD FOR !Deleted()
CLOSE DB
endif
else
DbCreate( cdir+"sample.dbf", aFields, "DBFCDX", .T., "DB" )
lAppend := .T.
INDEX ON Cod TAG COD FOR !Deleted()
CLOSE DB
endif
/// add test
if lAppend
USE &(cdir+"sample") NEW EXCLUSIVE ALIAS DB
INDEX ON Cod TAG COD FOR !Deleted()
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 0.10
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.70
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 0.75
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.50
APPEND BLANK
REPLACE COD WITH "00001"
REPLACE TEST1 WITH 1.2
REPLACE TEST2 WITH 0.20
REPLACE TEST3 WITH 3.60
REPLACE TEST4 WITH 0.4
CLOSE DB
Endif
RETURN NIL
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
CLASS TXData from TDatabase
DATA cDbfPath init cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
ENDCLASS
CLASS TSample from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TSample
Default lShared := .t.
::super:New(,::cDbfPath + "Sample" ,"DBFCDX", lShared)
if ::use()
::setOrder(1)
::gotop()
endif
RETURN Self
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//
//-----------------------------------------------------------------------------------//