I am using PowerBuilder classic 12.5 am having difficulties in inserting, editing, creating and printing reports.
i have a datawindow, dw_NewEmployee
with dataobject, d_newrecord
which is update-able.
itemchanged
event used on columns and rows on dataobject or
on single line texts... I am having trouble figuring out how to implement validation rules.
please give me an example to validate employee ID_Number
I see that you seem confused about the datawindow usage.
Let's try to summarize:
d_newrecord
(say it is a grid) based on a sql select in your database, say select id_number, name from employee
.id_number
and name
) these objects are both to display existing data and receive user input for editing data and inserting new records.dw_newemployee
where the content of the datawindow will be painted, you set d_newrecord
as its dataobject.open()
event of the window:dw_newemployee.SetTransObject(sqlca)
dw_newemployee.Retreive() //if you are using some retreival arguments, don't forget to include them here
When you want to insert new data in your table (for example with a window button "add"), in the clicked()
event of the button you call dw_newemployee.InsertRow(0)
to insert at the end.
The ItemChanged()
event will be triggered after one cell will be modified, you will be given the row, item (a dwobject) and new data. By choosing the returned value of the event, you can accept or reject the new data.
Here is an example for a field validation in itemchanged()
event:
long ll_return_code = 0
string ls_column
ls_column = lower(dwo.name)
choose case ls_column
case "id_number"
if long(data) = 42 THEN
messagebox("validation error", "You cannot use 42 for the ID")
ll_return_code = 1 //reject and stay in cell
end if
case "name"
if data = "foobar" then
messagebox("validation error", "Do not use dummy value...")
ll_return_code = 2 //reject but allow to go elsewhere
end if
end choose
return ll_return_code