/*********************************************************************************************
ShowTable() : Muestra un array en un browse y permite opcionalmente escoger un valor
*********************************************************************************************/
function ShowTable( aTable, cTitle, aSize, aCoord, aCols, aCargo, bColor )
local oDlg, oLbx, oSay, vSay, aData, n, m, oFont[1], nRetVal := 0
local aColSize, aJustify, aRecord, aAction, nActiveCol := 0
default aCargo := { 0 }
bColor := if( bColor = nil, { || SelColor( oLbx:nAt, 2 ) }, &( bColor ) )
default aSize := { 160, 115 }
default aCoord := { oCfg:nRow+85, oCfg:nCol }
if ValType( aTable ) == "A"
define font oFont[1] name "Tahoma" size 0,-12
define dialog oDlg title cTitle font oFont[1]
oDlg:lHelpIcon := .F.
aData := {}
aColSize := {}
aHeader := {}
aJustify := {}
aAction := {}
for n := 1 to Len( aTable )
aRecord := {}
for m := 1 to Len( aCols )
AADD( aRecord, if( ValType( aTable[n,aCols[m,1]] ) = "D", DtoC( aTable[n,aCols[m,1]] ), ;
if( ValType( aTable[n,aCols[m,1]] ) = "N", Transform( aTable[n,aCols[m,1]], aCols[m,5] ), ;
aTable[n,aCols[m,1]] )) )
if n = 1
AADD( aHeader, aCols[m,2] )
AADD( aColSize, aCols[m,3] )
AADD( aJustify, aCols[m,4] )
AADD( aAction, { |Self, nRow, nCol| nLbxCol := oLbx:nAtCol(nCol), ;
if( oLbx:cargo[1] <> nLbxCol, ;
( cSearch := "", vSay := Space(200), oSay:Refresh(), ;
aData := ASort( aData,,, { |x,y| x[nLbxCol] < y[nLbxCol] } ), ;
oLbx:nColHPressed := nLbxCol, oLbx:cargo[1] := nLbxCol, ;
oLbx:Refresh() ), ;
nil ) } )
nActiveCol := if( Len(aCols[m]) >= 5 .and. aCols[m,5], m, nActiveCol )
endif
next
AADD( aRecord, Str(n,4) )
AADD( aData, AClone( aRecord ) )
next
// Se agrega otra columna para el control del orden original
AADD( aHeader, "No." )
AADD( aColSize, 10 )
AADD( aJustify, 1 )
AADD( aAction, { nil } )
vSay := ""
@ aSize[2]+3, 5 say oSay var vSay of oDlg size 100,12 pixel
oLbx := TWBrowse():New( 0, 0, aSize[1], aSize[2],,,,,,,,,,,,,,,,,,.t.,,,,, )
LbxConfig( oLbx )
oLbx:SetArray( aData )
oLbx:bLine := { |nAt| nAt := oLbx:nAt, ;
if( Len( aData ) < 1 .or. nAt > Len( aData ), ;
Array(6), ;
aData[nAt] ) }
oLbx:aHeaders := aHeader
oLbx:aColSizes := aColSize
oLbx:aJustify := aJustify
oLbx:aActions := aAction
oLbx:bUpdateBuffer := { || oLbx:cBuffer := Upper(oLbx:cBuffer), ;
vSay := if( Len(oLbx:cBuffer) > 0, PadR( "Buscando: " + oLbx:cBuffer, 200 ), Space(200) ), ;
oSay:Refresh() ;
}
oLbx:bSeek := { || if( oLbx:cargo[1] = 0, ;
MsgStop( 'Haga clic en el titulo de la columna' + CRLF + ;
'por la que desea buscar', 'Atención' ), ;
( cSearch := Upper( oLbx:cBuffer ), ;
nLen := Len( cSearch ), ;
vSay := if( Len(cSearch) > 0, PadR( "Buscando: " + cSearch, 200 ), Space(200) ), ;
oSay:Refresh(), ;
nCol := oLbx:cargo[1], ;
if( nLen > 0, ;
( nAt := AScan( aData, { |x,y| Upper( SubStr( x[nCol], 1, nLen )) == cSearch } ), ;
if( nAt > 0, ;
( oLbx:nAt := nAt, ;
if( oLbx:oVScroll != nil, oLbx:oVScroll:SetPos(nAt), nil ), ;
oLbx:Refresh() ), ;
nil )), ;
nil )) ) }
oLbx:nBuffer := 10
oLbx:lAutoEdit := .f.
oLbx:lAutoSkip := .f.
oLbx:lAdjLastCol := .t.
oLbx:cargo := { nActiveCol }
oLbx:nHeaderHeight := 18
oLbx:nLineStyle := 1
oLbx:nClrLine := nRGB( 200, 200, 215 )
oLbx:lDrawFocusRect := .f.
oLbx:nClrPane := bColor
oLbx:nClrLine := nRGB( 200, 200, 215 )
oLbx:nClrBackHead := nRGB( 215, 215, 215 )
oLbx:nClrForeHead := nRGB( 0, 0, 0 )
oLbx:nClrForeFocus := nRGB( 255, 255, 255 )
oLbx:nClrBackFocus := nRGB( 0, 0, 0 )
oLbx:nClrNFFore := nRGB( 0, 0, 0 )
oLbx:nClrNFBack := nRGB( 180, 180, 180 )
oLbx:bBkColor := { |nRow,nCol,nStyle| if( nCol = oLbx:cargo[1] .and. ( nStyle = 0 .or. nStyle = 1 ), ;
oCfg:aLbxColors[2], ;
nil ) }
oLbx:bKeyDown := { | nKey | if( nKey == VK_RETURN, ;
( nAt := oLbx:nAt, ;
nRetVal := Val( aData[nAt,Len(aData[nAt])] ), ;
oDlg:End() ), ;
nil ) }
oLbx:bLDblClick := { | nKey | nRetVal := oLbx:nAt, oDlg:End() }
activate dialog oDlg on init ( oDlg:SetSize( oLbx:nWidth+8, oLbx:nHeight+60 ), ;
oDlg:Move( aCoord[1],aCoord[2]), ;
oDlg:Update() )
AEval( oFont, {|o| o:End() } )
endif
return nRetVal