https://drive.google.com/file/d/1r96D4lOEKS2j84Dpk0e0Ql8Px0ggD6JJ/view?usp=sharing
adjunto video con el problema. Gracias.
Saludos.
Estimado Ariel
Físicamente lo está grabando doble en la tabla?
O solo lo está mostrando doble?
Porque si sólo lo está mostrando quizás tenga que refrescar el browse.
ACuellar, gracias por contestar
si te fijas el video cuando refiltro desde SetFilterRegistro( oBrw ) se arregla.
Saludos.
/*
Duplicación de registro en xBrowse
luego de Agregar o Editar.
*/
// SELECT de Tabla
oQryBD:= ::oConn:RowSet( "SELECT * FROM clientes " + ;
"LEFT JOIN conceptos AS CONC ON CONC.idConcep = clientes.idConcep " + ;
"LEFT JOIN servicios AS SERV ON SERV.idService = clientes.idService " + ;
"WHERE NumeroDocumento LIKE ? and Apellidos LIKE ? and Nombres LIKE ? " + ;
"ORDER BY Apellidos", ;
{ ::cDocumento, ::cApellido, ::cNombre } )
// xBrowse
REDEFINE XBROWSE aO[_oBrw] ID BRW_XBRW OF oDlg AUTOSORT ;
COLUMNS "NumeroDocumento", "Apellidos", "Nombres" ;
HEADERS "DCTO", "Apellidos", "Nombres" ;
OBJECT ::oQryCli
WITH OBJECT aO[_oBrw]
:nColDividerStyle := LINESTYLE_DARKGRAY // Linea Tipo
:l2013 := TRUE
:nStretchCol := STRETCHCOL_LAST
:nMarqueeStyle := MARQSTYLE_HIGHLROWRC // linea señaladora
:lColDividerComplete:= TRUE // Linea de columna hasta final de Brw
:lAllowColHiding := FALSE // Anular menu pop Ocultar/Mostrar columna
:lHScroll := FALSE
:lMultiselect := FALSE // Cuando repsoiciona por busqueda cambia la barra de señalizacion
:SetColor( CLR_BLACK, CLR_BACKAMAR ) // colorea todo el browse
:bClrStd:= {|| {CLR_BLACK, CLR_BACKAMAR} }
:oHeaderFonts:= oSelf:oRutG:hFont["Calibri14"]
// Get de Cabecera
:lGetBar := .T.
:bClrEdits := { || { CLR_BLACK, CLR_BACKBLUE1 } }
:bLDblClick:= {|| Eval( aO[_oBrw]:bKeyDown, VK_F12 ) } //
:bKeyDown := {|nK| if( nK==VK_F12, if( lCaptura, ( Eval( bRetorno ), ( aO[_oBrw]:End(), oDlg:End(), ::oRutG:EndFont() ) ), ), ) }
// Menu Hamburguesa
:nRecSelHeadBmpNo := { 48, 48, { { "L", 0, 2, 16, 16, 2, 1, 2, 14 }, ;
{ "L", 0, 2, 16, 16, 7, 1, 7, 14 }, ;
{ "L", 0, 2, 16, 16,12, 1,12, 14 } } }
:bRecSelHeader:= "Menú"
:bRecSelClick := {|| ::MenuH( aO[_oBrw], oDlg, _MNCLIENTES,, lCaptura ) } // Menu de opciones
// PopUp
:bRClicked:= {|nRow, nCol| if( !lCaptura, ::PopMenu( aO[_oBrw], lCaptura, nRow, nCol ), msgBeep() ) }
END
WITH OBJECT aO[_oBrw]:DCTO
:cHeader:= "Dcto N°"
:nWidth := 110
//:cEditPicture:= PIC_DNI
:bStrData:= {|| Transform( ::oQryCli:NumeroDocumento, if( IsDigit(::oQryCli:NumeroDocumento) .and. Val(::oQryCli:NumeroDocumento)<= 99999999, ;
"@R 99.999.999", ;
if( !IsDigit(::oQryCli:NumeroDocumento), "@!", "@R 99.999.999" )) ) }
:Cargo:= "NumeroDocumento"
:bBarGetAction:= {|| ::SetFilterRegistro( aO[_oBrw], lCaptura ) }
END
WITH OBJECT aO[_oBrw]:Apellidos
:cHeader:= if(lCaptura, "Raz.Social", "Apellidos" )
:nWidth := if( lCaptura, 300, 260 )
:Cargo:= if( lCaptura, "RAZSOC", "Apellidos" )
:bBarGetAction:= {|| ::SetFilterRegistro( aO[_oBrw], lCaptura ) }
:cBarGetPic:= "@!"
END
WITH OBJECT aO[_oBrw]:aCols[3]
:cHeader:= if(lCaptura, "", "Nombres" )
:nWidth := 1
if !lCaptura
:Cargo:= "Nombres"
:bBarGetAction:= {|| ::SetFilterRegistro( aO[_oBrw] ) }
:cBarGetPic:= "@!"
end
END
// Default
aEval( aO[_oBrw]:aCols, { |o,n| IF(o:cargo <> Nil, ( o:uBarGetVal := if( n == 1 .and. !Empty( Token( ::cDocumento,"%" ) ), Token( ::cDocumento,"%" ), ;
if( n == 2 .and. !Empty( Token( ::cApellido,"%" ) ), Token( ::cApellido,"%" ), ;
if( n == 3 .and. !Empty( Token( ::cNombre,"%" ) ), Token( ::cNombre,"%" ), Space( 50 ) ))), ; // o:uBarGetVal:= uValBlank( ::FieldGet( n ) ), ;
o:cBarGetBmp := "bmp_Buscar (24x24)", ;
o:bBarGetValid:= {|| ::SetFilterRegistro( aO[_oBrw], lCaptura ) } ), ) } )
...
// Finb xBrowse
// Menu
METHOD MenuH( oBrw, oDlg, nOpcion, nFolder, lCaptura ) CLASS TBDatos
local oMenu
MENU oMenu POPUP 2015
MENUITEM "Agrega" ;
RESOURCE "bmp_AgrCli (20x20)" ; // EditBaseRecord( [cFieldList], [lNew], [bEdit], [oBrw], [lLock] )
ACTION ::oQryCli:EditBaseRecord( nil, TRUE, { |oRec| ::AgrEdiCliente( oRec, oBrw ) }, oBrw ) // <--- QUE HACE ESTE oBrw
MENUITEM "Edita" ;
RESOURCE "bmp_EdiCli (20x20)" ;
WHEN !::oQryCli:RecCount() == 0 ;
ACTION ::oQryCli:EditBaseRecord( nil, FALSE, { |oRec| ::AgrEdiCliente( oRec, oBrw ) }, oBrw, TRUE ) // <--- QUE HACE ESTE .T.
MENUITEM "Cierra Tabla" ;
RESOURCE "bmp_Salir (20x20)" ;
ACTION oDlg:End()
ENDMENU
return( oMenu )
// Fin
// Evento Guardar
REDEFINE RBBTN ID BTN_GUARDAR OF oDlg TRANSPARENT ;
PROMPT "Guardar" LEFT ;
BITMAP "bmp_Guardar (28x28)" ;
LINECOLORS CLR_BLUE, CLR_HBLUE ;
ACTION ( oCliente:idConcep := hServicios["idConcepto"], ;
oCliente:idService:= hServicios["idService"], ;
if( oSelf:GuardaCliente( oCliente, lAgrega ), ;
( oSelf:cDocumento:= ;
oSelf:cApellido := ;
oSelf:cNombre := "", ;
oSelf:SetFilterRegistro( oBrw ), ; // Re Filtra el Browse - mostrando toda la Tabla
if( lAgrega, ;
( oSelf:oQryCli:SetOrder( "Apellidos" ), ; // Posiciona la barra en el registro Agregado
oSelf:oQryCli:GoTop(), ;
oSelf:oQryCli:Seek( RTrim(oCliente:Apellidos) ) ), ), ;
oDlg:End(), ;
oBrw:SetFocus() ), ;
msgBeep() ) ) )
...
// Fin Dialog Agrega/Edita
// Consultas Filtradas
METHOD SetFilterRegistro( oBrw, lCaptura ) CLASS TBDatos
local oCol, ;
uVal, ;
uValFil:={}
DEFAULT lCaptura:= FALSE
FOR EACH oCol IN oBrw:aCols
uVal := oCol:uBarGetVal
if ValType(uVal)=="C"
aAdd( uValFil, AllTrim( uVal ) )
elseIf ValType(uVal)=="N"
aAdd( uValFil, Str( uVal ) )
elseIf ValType(uVal)=="D"
// PENDIENTE
end
NEXT
if Len(uValFil) > 0
::cDocumento:= if( ::nOpcFil == _QCOMIENCE, '', '%') +uValFil[1]+'%' //, ;
::cApellido := if( ::nOpcFil == _QCOMIENCE, '', '%') +uValFil[2]+'%' //, ;
if !lCaptura
::cNombre := if( ::nOpcFil == _QCOMIENCE, '', '%') +uValFil[3]+'%'
end
if !Empty( ::oQryCli )
if lCaptura
::oQryCli:Requery( { ::cDocumento, ::cApellido } )
else
::oQryCli:Requery( { ::cDocumento, ::cApellido, ::cNombre } )
end
::oQryCli:Refresh()
end
oBrw:Refresh()
end
oBrw:SetFocus()
return( TRUE )
// Fin//hace falta el paréntesis
oQryBD:= ::oConn:RowSet( "SELECT * FROM (clientes " + ;
"LEFT JOIN conceptos AS CONC ON CONC.idConcep = clientes.idConcep) " + ;
"LEFT JOIN servicios AS SERV ON SERV.idService = clientes.idService " + ;
"WHERE NumeroDocumento LIKE ? and Apellidos LIKE ? and Nombres LIKE ? " + ;
"ORDER BY Apellidos", ;
{ ::cDocumento, ::cApellido, ::cNombre } ) oQryBD:= ::oConn:RowSet( "SELECT * FROM clientes " + ;
"WHERE NumeroDocumento LIKE ? and Apellidos LIKE ? and Nombres LIKE ? " + ;
"ORDER BY Apellidos", ;
{ ::cDocumento, ::cApellido, ::cNombre } )#include "fivewin.ch"
function Main()
local oCn, oRs
oCn := maria_Connect( ... )
oRs := oCn:RowSet( "SELECT * FROM clientes " + ;
"WHERE NumeroDocumento LIKE <1> and Apellidos LIKE <2> " + ;
"and Nombres LIKE <3> ORDER BY Apellidos" )
// for the purpose of the test, substitute <1>, <2>, <3> with constant values
XBROWSER oRs FASTEDIT SHOW RECID
oRs:Close()
oCn:Close()
return nilHola,
este codigo si funciona, pero falla al hacer o aplicar requery.
Saludos.
XBROWSER oRs FASTEDIT SHOW RECID SETUP ( oBrw:bRClicked := { |r,c,f,o| oRs:Requery(), o:Refresh() } )Mr Rao,
El ejemplo que esta poniendo no es aplicable al problema que le planteo en el principio del post, el xbrowse que usamos esta definido en un DIALOG como verá en el ejemplo que le suministré.
En el xbrowser funciona pero cuando mira mi ejemplo enviado no funciona correctamente el :REQUERY().
Saludos.
/*
DEMO : mariarq.prg (ReQuery)
Por : Ariel Cagiao
Fecha: 17/06/20
*/
#include "fivewin.ch"
#define TRUE .t.
#define FALSE .f.
static oWMain
static oConn
static oQryCli
static cDocumento
static cApellidos
static cNombres
#define CLR_BACKAMAR nRGB( 255, 255, 230 )
// -------------------------------------------------------------------------- \\
PROCEDURE Main()
local oErr
// Vars
cDocumento:= cApellidos:= cNombres:= ""
// Coneccion
// FWCONNECT oConn HOST "localhost" USER "root" PASSWORD "qw" DATABASE "mgface"
FWCONNECT oConn HOST "localhost" USER "root" PASSWORD "India@1947" DATABASE "fwh"
if oConn == nil
MsgStop( "FWMaria Error:" +oConn:cError, cValToChar(oConn:nError) )
endif
fBrwClientes()
? "Zas!"
oConn:Close()
// Fin
#define _BtAgr 1
#define _BtEdi 2
#define _oBrw 3
// -------------------------------------------------------------------------- \\
FUNCTION fBrwClientes()
local oDlg, ;
aO[_oBrw]
// Select Tabla
oQryCli:= oConn:RowSet( "SELECT * FROM clientes " + ;
"WHERE NumeroDocumento LIKE ? and Apellidos LIKE ? and Nombres LIKE ? " + ;
"ORDER BY NumeroDocumento", ;
{ cDocumento, cApellidos, cNombres } )
//XBROWSER oQryCli FASTEDIT SHOW RECID
DEFINE DIALOG oDlg RESOURCE "brw_BDatos" TITLE "Tabla de Clientes"
REDEFINE XBROWSE aO[_oBrw] ID 300 OF oDlg AUTOSORT ;
COLUMNS "NumeroDocumento", "Apellidos", "Nombres" ;
HEADERS "NumeroDocumento", "Apellidos", "Nombres" ;
OBJECT oQryCli UPDATE
WITH OBJECT aO[_oBrw]
:nStretchCol := STRETCHCOL_LAST
// Get de Cabecera
:lGetBar := .T.
:bClrEdits := { || { CLR_BLACK, CLR_BACKAMAR } }
END
WITH OBJECT aO[_oBrw]:NumeroDocumento
:cHeader:= "Dcto N°"
:nWidth := 110
:Cargo:= "NumeroDocumento"
:bBarGetAction:= {|| SetFilterRegistro( aO[_oBrw] ) }
END
WITH OBJECT aO[_oBrw]:Apellidos
:nWidth := 300
:Cargo:= "Apellidos"
:bBarGetAction:= {|| SetFilterRegistro( aO[_oBrw] ) }
:cBarGetPic:= "@!"
END
WITH OBJECT aO[_oBrw]:Nombres
:cHeader:= "Nombres"
:nWidth := 1
:Cargo:= "Nombres"
:bBarGetAction:= {|| SetFilterRegistro( aO[_oBrw] ) }
:cBarGetPic:= "@!"
END
aEval( aO[_oBrw]:aCols, { |o,n| IF(o:cargo <> Nil, ( o:uBarGetVal := Space( 50 ), ;
o:cBarGetBmp := HB_UTF8CHR(0xE16E), ;
o:bBarGetValid:= {|| SetFilterRegistro( aO[_oBrw] ) } ), ) } )
REDEFINE BUTTONBMP aO[_BtAgr] ID 501 OF oDlg ;
RESOURCE 0xE1E2 TEXTRIGHT ;
TOOLTIP "Agrega" ;
ACTION ( oQryCli:EditBaseRecord( nil, TRUE, {|oRec| AgrEdiCliente( oRec, aO[_oBrw] ) }, aO[_oBrw] ), ;
SetFilterRegistro( aO[_oBrw] ) )
aO[_BtAgr]:bColorMap:= {|| { , CLR_HGREEN } }
REDEFINE BUTTONBMP aO[_BtEdi] ID 502 OF oDlg ;
RESOURCE 0xE104 TEXTRIGHT ;
TOOLTIP "Edita" ;
ACTION ( oQryCli:EditBaseRecord( nil, FALSE, {|oRec| AgrEdiCliente( oRec, aO[_oBrw] ) }, aO[_oBrw] ), ;
SetFilterRegistro( aO[_oBrw] ) )
aO[_BtEdi]:bColorMap:= {|| { , CLR_GREEN } }
ACTIVATE DIALOG oDlg CENTER
oQryCli:End()
return( nil )
// Fin
#define _BtSve 1
#define _BtFin 2
#define _GApellido 3
#define _GNombre 4
#define _GDNI 5
// ----------------------------------------------------------------------------- \\
//
FUNCTION AgrEdiCliente( oCliente, oBrw )
local oDlg, ;
oErr, ;
bSave, ;
aO[ _GDNI ], ;
lOk:= FALSE
// Dialogo
DEFINE DIALOG oDlg RESOURCE "get_DatosClientes"
// Datos Cliente
REDEFINE GET aO[_GApellido] VAR oCliente:Apellidos ID 101 OF oDlg UPDATE ;
PICTURE "@!;S40" COLOR CLR_BLUE, CLR_BACKAMAR ;
CUEBANNER "* Obligatorio *"
REDEFINE GET aO[_GNombre] VAR oCliente:Nombres ID 102 OF oDlg UPDATE ;
PICTURE "@!;S40" COLOR CLR_BLUE, CLR_BACKAMAR ;
CUEBANNER "* Obligatorio *"
REDEFINE GET aO[_GDNI] VAR oCliente:NumeroDocumento ID 103 OF oDlg UPDATE ;
COLOR CLR_BLUE, CLR_BACKAMAR ;
CUEBANNER "* Obligatorio *"
REDEFINE BUTTONBMP aO[_BtSve] ID 501 OF oDlg ;
RESOURCE 0xE105 TEXTRIGHT ;
TOOLTIP "Guarda" ;
ACTION ;
( oBrw:oCol( 1 ):oBarGet:cText := Space( 50 ), ;
oBrw:Apellidos:oBarGet:cText := oCliente:Apellidos, ;
oBrw:oCol( 3 ):oBarGet:cText := Space( 50 ), ;
oCliente:Save(), oDlg:End() )
aO[_BtSve]:bColorMap:= {|| { , CLR_HBLUE } }
REDEFINE BUTTONBMP aO[_BtFin] ID 502 OF oDlg ;
RESOURCE 0xE106 TEXTRIGHT ;
TOOLTIP "Edita" ;
ACTION oDlg:End()
aO[_BtFin]:bColorMap:= {|| { , CLR_RED } }
ACTIVATE DIALOG oDlg CENTER
return( TRUE )
// Fin
// ----------------------------------------------------------------------------- \\
// Consultas Filtradas
function SetFilterRegistro( oBrw )
local oCol, ;
uVal, ;
uValFil:={}
FOR EACH oCol IN oBrw:aCols
uVal := oCol:uBarGetVal
if ValType(uVal)=="C"
aAdd( uValFil, AllTrim( uVal ) )
elseIf ValType(uVal)=="N"
aAdd( uValFil, Str( uVal ) )
end
NEXT
if Len(uValFil) > 0
cDocumento:= uValFil[1]+'%'
cApellidos:= uValFil[2]+'%'
cNombres := uValFil[3]+'%'
if !Empty( oQryCli )
oQryCli:Requery( { cDocumento, cApellidos, cNombres } )
oBrw:Refresh()
oBrw:SetFocus()
end
end
return( TRUE )
// FinMr. Rao,
Perfecto! ahora si funciona correctamente, en base a lo que comenta :
" You chose to use the method EditBaseRecord() for editing the record (though it is not necessary or recommended in this case, but that is a separate discussion)."
en que caso es recomendable usar EditBaseRecord() y en cual no ? porque los ejemplos que vi en samples lo utilizan, de ahi que me base en los ejemplos para construir esta consulta.
Gracias.