#include "FiveWin.ch"
#include "xbrowse.ch"
static oWnd
function MainTest()
local oMenu
set delete on
menu oMenu
menuitem "Dbfs..." action dbfs()
menuitem "Arrays..." action Arra()
menuitem "Salir" action oWnd:end()
endmenu
DEFINE WINDOW oWnd menu oMenu mdi
ACTIVATE WINDOW oWnd
return nil
procedure dbfs()
local oBrw, oWndChild, oBar, oCol
local nLast
local lAuto := .t.
set delete on
USE test
DEFINE WINDOW oWndChild of oWnd mdichild
define buttonbar oBar of oWndChild
define button of oBar prompt "ON" action( oBrw:lAutoappend := lAuto:= .t. ) top when !lAuto
define button of oBar prompt "OFF" action( oBrw:lAutoappend := lAuto:= .f.) top when lAuto
define button of obar prompt "Exit" action( oWndChild:end() ) top
@ 0, 0 XBROWSE oBrw OF oWndChild ALIAS "test"
oBrw:nMarqueeStyle = 3
oBrw:nColDividerStyle = LINESTYLE_BLACK
oBrw:nRowDividerStyle = LINESTYLE_BLACK
oBrw:lHScroll = .T.
oBrw:lColDividerComplete = .T.
oBrw:lAutoAppend = lAuto
oBrw:lFastEdit = .T.
oBrw:bPastEof = {|| Dbappend(), oBrw:refresh(), oBrw:aCols[ 1 ]:Edit() }
oBrw:bKeyDown = {|nKey| if( nKey == VK_DELETE ,;
( nLast:=recno(),test->( dbdelete() ), __Dbpack(), dbgoto(nLast) ),), oBrw:refresh() }
oCol = oBrw:AddCol()
oCol:bStrData = { || test->First }
oCol:cHeader = "First"
oCol:nEditType = EDIT_GET
oCol:bOnPostEdit = ;
{ | oCol, xVal, nKey | if( xVal == space( 20 ) .and. nKey == VK_ESCAPE,;
( nLast:=recno(),test->( dbdelete() ), __Dbpack(),dbgoto(nLast-1) ),;// Afirmacion
( If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), ;//Negativa
If( nKey == VK_RETURN, test->First := xVal,) )), oBrw:refresh() }
oCol:bEditValid = {|o| if ( o:value() == space(20), .f., .t.) }
oCol = oBrw:AddCol()
oCol:bStrData = { || test->Last }
oCol:cHeader = "Last"
oCol:nEditType = EDIT_GET
oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, DbAppend(),), If( nKey == VK_RETURN, ( test->Last := xVal, oBrw:Refresh() ),) }
oBrw:CreateFromCode()
oWndChild:oClient := oBrw
ACTIVATE WINDOW oWndChild
return
procedure arra()
local oWndChild, oBar, oB
local aBrw := {}
local lAuto := .f.
use test
test->( DbGoTop() )
do while !test->( eof() )
aadd( aBrw, { test->first, test->last } )
test->( dbskip() )
enddo
define WINDOW oWndChild of oWnd mdichild
define buttonbar oBar of oWndChild
define button of oBar prompt "ON" action( oB:lAutoappend := lAuto:= .t. ) top when !lAuto
define button of oBar prompt "OFF" action( oB:lAutoappend := lAuto:= .f.) top when lAuto
define button of obar prompt "Exit" action( oWndChild:end() ) top
@ 8,0 xBROWSE oB of oWndChild ;
columns 1,2 ;
headers "First", "Last" ;
picture "@!","@!";
sizes 150,150 array aBrw fastedit
oB:nMarqueeStyle := MARQSTYLE_HIGHLCELL
oB:nRowDividerStyle := 1
oB:nColDividerStyle := 1
oB:nRowHeight := 25
oB:lAutoAppend := lAuto
oB:bPastEof := ;
{|| if( oB:aRow[ 1 ] != space( 20 ) ,;
( aadd( oB:aArrayData, {space( 20 ), space( 20 )} ),;
oB:GoDown() ,;
oB:Refresh(),;
oB:GoLeftMost(),;
oB:aCols[ 1 ]:Edit() ),) }
oB:bKeyDown := {| nKey | if( nKey == VK_DELETE .and. oB:aRow[ 1 ] <> space( 20 ),;
if ( msgyesno("Desea eliminar el renglón") ,;
( aDel( oB:aArraydata, oB:nArrayAt ),;
ASize( oB:aArraydata, len( oB:aArrayData ) -1 ),;
oB:nArrayAt := MIN(oB:nArrayAt,LEN(oB:aArraydata)),;
oB:EraseData( oB:nArrayAt ) ),),),;
if ( len( oB:aArraydata ) == 0, ;
aadd( oB:aArraydata, {space( 20 ), space( 20 ) } ),),;
oB:refresh() }
oB:aCols[ 1 ]:nEditType := EDIT_GET
oB:aCols[ 1 ]:bEditvalid := { | oGet | if ( oGet:Value() == space( 20 ), .f., .t. ) }
oB:aCols[ 1 ]:bOnPostEdit:= ;
{|oBj, x, nKey| if ( x == space( 20 ) .and. len( oB:aArrayData ) > 1, ;
(if ( len( oB:aArrayData) = oB:nArrayAt .and. oB:aRow[ 1 ] == space( 20 ),;
(ADel( oB:aArraydata, oB:nArrayAt ),;
ASize( oB:aArraydata, len( oB:aArrayData ) -1 ),;
oB:nArrayAt := MIN(oB:nArrayAt,LEN(oB:aArraydata) ),;
oB:EraseData( oB:nArrayAt ),;
oB:refresh() ),) ), oB:aRow[ 1 ] := x ) }
oB:aCols[ 2 ]:nEditType := EDIT_GET
oB:aCols[ 2 ]:bOnPostEdit := {| oBj, x, nKey | if ( nKey == VK_RETURN, oB:aRow[ 2 ] := x,) }
oB:CreateFromCode()
oWndChild:oClient := oB
Activate WINDOW oWndChild
return