by Patricio Avalos Aguirre » Tue Aug 28, 2007 7:43 pm
En el Ejemplo nº 1 de la clase de wBrowse de hernan esta lo que necesitas
por si no lo tienes
- Code: Select all Expand view RUN
#include "fivewin.ch"
Function Main()
LOCAL aTotal:= {0,0,0, Nil, Nil, Nil}
LOCAL aDatos:= {} // Array MultiDimensional
// Cod.Art. Descrip. Cantidad $Unitario $Total MarcaDeNuevo
LOCAL l3d:= .F.
LOCAL oDlg, oLbx, cPic:= "@ze 999,999.99", oFont
LOCAL hBmp:= ReadBitMap( 0, "finger.bmp" ) // Dedicado a mi amigo Mario Goanzalez
If Alert("Quiere verlo en 3D ??", {"Aceptar","Cancelar"}) == 1
l3D:= .T.
EndIf
DEFINE FONT oFont NAME "Times New Roman" SIZE 0,-15 BOLD
DEFINE DIALOG oDlg FROM 0,0 TO 21,55 TITLE "::bEdit's TWBrowse Power !!!"
TWBrowse():lHScroll:= .F.
@2,2 LISTBOX oLbx FIELDS "" ;
HEADER "Id","Articulo", "Descripcion", "Cantidad", ;
"Unitario", "Total" ;
OF oDlg SIZE 207,100 PIXEL ;
SIZES 25,50, 130, 67,60,60
oLbx:bLine:= {|nAt| nAt:= oLbx:nAt, ;
If( Len(aDatos)<1 .or. nAt>Len(aDatos),;
Array(6), ;
{ If( oLbx!=Nil .and. oLbx:lSelect, hBmp, 0 ),;
If( aDatos[nAt,1]==0,Space(4),StrZero( aDatos[nAt,1], 4 ) ), ;
aDatos[nAt,2], ;
Transform( aDatos[nAt,3], cPic ), ;
Transform( aDatos[nAt,4], cPic ), ;
Transform( aDatos[nAt,5], cPic ) } ) }
oLbx:aJustify:= { 2, 2, .f., .t., .t. , .t. }
oLbx:SetArray( aDatos )
oLbx:lAdjLastCol:= .f.
oLbx:lAutoEdit := .t.
oLbx:lAutoSkip := .t.
oLbx:nLineStyle := 2
oLbx:nHeaderStyle:= 2
oLbx:bBkColor:= {|nRow,nCol,nStyle| ;
if( nStyle==1,if( nCol%2==0, CLR_RED , CLR_GREEN ),) }
oLbx:bTextColor:= {|nRow,nCol,nStyle| ;
if( nStyle==1,if( nCol%2==0, CLR_YELLOW, CLR_WHITE ),) }
If l3D
oLbx:Set3DStyle()
EndIf
oLbx:bEdit:= {|nCol, cBuffer, lFirstEdit|;
EditaCelda( oLbx, nCol, cBuffer, aDatos, lFirstEdit, aTotal ) }
@105, 110 SAY "Neto Gravado " OF oDlg PIXEL
@115, 110 SAY "I.V.A. 21% " OF oDlg PIXEL
@125, 110 SAY "Total " OF oDlg PIXEL
@105, 150 SAY aTotal[4] PROMPT aTotal[1] PICTURE '@ZE 999,999.99' OF oDlg PIXEL RIGHT SIZE 50,10
@115, 150 SAY aTotal[5] PROMPT aTotal[2] PICTURE '@ZE 999,999.99' OF oDlg PIXEL RIGHT SIZE 50,10
@125, 150 SAY aTotal[6] PROMPT aTotal[3] PICTURE '@ZE 999,999.99' OF oDlg PIXEL RIGHT SIZE 50,10
@137,10 BUTTON "Agrega" OF oDlg PIXEL ;
ACTION ( NewReg( aDatos, oLbx ), oLbx:Edit() ) SIZE 50,Nil
@137,80 BUTTON "Modifica" OF oDlg PIXEL ;
ACTION If( Len(aDatos) > 0 .and. ;
oLbx:nAt <= Len(aDatos) .and. oLbx:nAt > 0,;
oLbx:Edit(), ) SIZE 50,Nil
@137,150 BUTTON "Elimina" OF oDlg PIXEL ;
ACTION If( Len(aDatos) > 0 .and. ;
oLbx:nAt <= Len(aDatos) .and. oLbx:nAt > 0 .and. ;
Alert("Borra ?",{"ok","Cancela"}) == 1, ;
DelReg( aDatos, oLbx, aTotal ),) SIZE 50,Nil
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
ReleaseDC( hBmp )
return Nil
//----------------------------------------------------------------------------//
Function GetSysFont() ; return "MS Sans Serif"
//----------------------------------------------------------------------------//
STATIC Function EditaCelda( oLbx, nCol, cBuffer, aDatos, lFirstEdit, aTotal )
LOCAL aResult, nAt:= oLbx:nAt, uBuffer, lContinue:= .t.
LOCAL bValid, nColReal:= nCol
nCol-- // Para que sea como si no exisiera BitMap
uBuffer:= aDatos[nAt,nCol]
While .t.
Do Case
Case ( nCol == 2 .or. nCol == 5 ) .and. lFirstEdit
Alert( "Columnas NO EDITABLES" )
return .f.
Case nCol == 1
bValid:= {|| If( Empty( aResult:= SeekItem( uBuffer ) ), ;
(Alert( "Codigo Articulo Inexistente :-("),.F.) , .T. ) }
If lContinue:= oLbx:lEditCol( nColReal, @uBuffer, "@ZE 9999", bValid,,CLR_YELLOW )
aDatos[nAt,1]:= uBuffer
aDatos[nAt,2]:= aResult[1]
aDatos[nAt,4]:= aResult[2]
EndIf
Case nCol == 3 // Cantidad
If lContinue:= oLbx:lEditCol( nColReal, @uBuffer, "@ZE 999,999.99",,,CLR_YELLOW )
If uBuffer <= 0
Alert("Debe Especificar una cantidad !!!")
Loop
EndIf
aDatos[nAt,3]:= uBuffer
EndIf
Case nCol == 4 // Unitario
If lContinue:= oLbx:lEditCol( nColReal, @uBuffer, "@ZE 999,999.99",,,CLR_YELLOW )
aDatos[nAt,4]:= uBuffer
aDatos[nAt,6]:= .f. // Ya no es un Nuevo Registro !!!
EndIf
Case nCol == 5 .and. ! lFirstEdit .and. Len( aDatos ) == nAt
NewReg( aDatos, oLbx )
EndCase
If ! lContinue .and. aDatos[nAt,6] // Se habia agregado un nuevo Item !!!
If Alert( "Cancela este Nuevo Registro", { "Ok","Cancelar" } ) == 1
DelReg( aDatos, oLbx, aTotal )
return .f.
Else
Loop
EndIf
EndIf
Exit
EndDo
If Len( aDatos ) > 0
aDatos[nAt,5]:= Round( aDatos[nAt,3] * aDatos[nAt,4], 2 )
Suma( aDatos, aTotal )
EndIf
If lContinue
Do Case
Case oLbx:nLastKey == VK_UP
return If( !GetKeyState(VK_SHIFT), -3, -2 )
Case oLbx:nLastKey == VK_DOWN
return If( !GetKeyState(VK_SHIFT), 3, 2 )
Case oLbx:nLastKey == VK_TAB
return If( GetKeyState(VK_SHIFT), -1, 1 )
EndCase
EndIf
return lContinue
//----------------------------------------------------------------------------//
STATIC Function SeekItem( nCod ) // Simulamos busqueda en Base de Datos :-)
If nCod >= 1 .and. nCod <= 500
return { "Producto " + StrZero( nCod, 4 ), nCod + 0.55 }
EndIf
return ""
//----------------------------------------------------------------------------//
STATIC Function NewReg( aDatos, oLbx )
Aadd( aDatos, {0,"",0,0,0,.t.} )
oLbx:Refresh()
oLbx:lHitBottom:= .f.
oLbx:GoBottom()
SysRefresh()
return Nil
//----------------------------------------------------------------------------//
STATIC Function DelReg( aDatos, oLbx, aTotal )
ADel( aDatos, oLbx:nAt )
ASize( aDatos, Len( aDatos ) - 1 )
oLbx:GoUp()
oLbx:Refresh()
Suma( aDatos, aTotal )
return Nil
//----------------------------------------------------------------------------//
STATIC Function Suma( aDatos, aTotal )
aTotal[1]:= 0
AEval( aDatos, {|aItem| aTotal[1]+= aItem[5] } )
aTotal[1]:= Round( aTotal[1], 2 )
aTotal[2]:= Round( aTotal[1] * 0.21, 2 )
aTotal[3]:= Round( aTotal[1] + aTotal[2],2 )
AEval( aTotal, {|oSay| oSay:Refresh(.F.) }, 4 )
return Nil
//----------------------------------------------------------------------------//
Saludos
Patricio
__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl