Validación dw incorrecta

Tengo un datawindow con un campo dni y la expresión de validación es esta:
match(dni, "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]") and len(dni)=9
Si intento modificar el dni de un registro introduciendo una expresión incorrecta, me la detecta y provoca un error. A continuación vuelvo a modificar el registro dejando una expresión válida y me sigue dando ese error. ¿A qué se debe esto? ¿Por qué no se me actualiza el nuevo valor introducido?
En la pantalla utilizo dos datawindow:
Dw_maestro: tabular donde unicamente visualizo los registros
dw_detalle: freeform donde realizo las modificaciones
El código que utilizo para la actualización es:
IF datawin_detalle.update()<>-1 THEN
COMMIT;
Messagebox("ATENCIÓN","Los datos han sido actualizados con éxito")
ELSE
ROLLBACK;
Messagebox("ATENCIÓN","No han podido realizarse los cambios")
END IF
// Se vuelven a recuperar todas las tuplas
datawin_tabular.retrieve()
// Se pone el cursor en el datawindows tabular
datawin_tabular. Setfocus()

1 respuesta

Respuesta
1
te aconsejo que mejor valides en el evento itemchanged del datawindow
string ls_dni
if dwo.name = 'dni' then
ls_dni = data
if not match( ls_dni, "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]") then
messagebox("Error","Dato mal ingresado")
return 1
else
return 0
end if
end if
Muchas gracias, eso ya lo tengo más o menos claro.
Ahora lo que quiero es que cuando se produzca el evento de error de la validación (itemerror), en lugar de salirse de la modificación se quede el cursor en el lugar donde se produjo el fallo y poder solucionarlo.
Tenia pensado hacer lo siguiente: desde el evento itemerror del datawindow llamar al evento que invoca de nuevo a la modificación:
uo_botonera.cb_modificar.triggerevent(clicked!)
Pero no lo tengo muy claro. Además, este error me puede ocurrir ta, bien a partir de un alta y en ese caso debería forzar el evento
uo_botonera.cb_añadir.triggerevent(clicked!)
¿Cómo los distingo? ¿Estoy siguiendo una buena estrategia?
-----------------
Gracias por contestarme, estoy empezando con el PBuilder y voy un poco perdido. Me estás siendo de gran ayuda ;)
Evento Itemchanged
Description
Occurs when a field in a DataWindow control has been modified and loses focus (for example, the user presses enter, the tab key, or an arrow key or clicks the mouse on another field within the DataWindow). ItemChanged can also occur when the AcceptText or Update function is called for a DataWindow control or DataStore object.
Event ID
Event ID Objects
pbm_dwnitemchange DataWindow control or DataStore
Arguments
Argument Description
row Long by value (the number of the row containing the item whose value has been changed)
dwo DWObject by value (a reference to the column containing the item whose value has been changed. Dwo is a reference to the column object, not the name of the column)
data String by value (the new data the user has specified for the item)
Return value
Long. Return code choices (specify in a RETURN statement):
0 (Default) Accept the data value
1 Reject the data value and don't allow focus to change
2 Reject the data value but allow the focus to change
Usage
The ItemChanged event does not occur when the DataWindow control itself loses focus. If the user clicks on an Update or Close button, you will need to write a script that calls AcceptText to see if a changed value should be accepted before the button's action occurs.
Obsolete techniques Information formerly provided by the GetText function is available in the data argument.
Instead of calling SetActionCode, use a RETURN statement with a return code.
*********************************************************
despues de leer esto te podras dar cuenta que al poner
return 1 en el evento itemchanged , el cursor no pasa a otro campo..

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas