Domanda

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.

  1. should i use the columns to insert records through the columns or i create single line texts on the window object
  2. is the 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
È stato utile?

Soluzione

I see that you seem confused about the datawindow usage.

Let's try to summarize:

  1. you create a new datawindow d_newrecord (say it is a grid) based on a sql select in your database, say select id_number, name from employee.
  2. in the detail zone of the datawindow (that will be repeated for each record at runtime but that is only once in design), you need to put one column object for each column (here you will have id_number and name) these objects are both to display existing data and receive user input for editing data and inserting new records.
  3. don't forget to set the Rows / Update properties if you need to make the dw updatable.
  4. in the header zone of the datawindow you can have a static text associated to each column that is just here to display the column name, it does not concern table data.
  5. in some window object, you place a datawindow control dw_newemployee where the content of the datawindow will be painted, you set d_newrecord as its dataobject.
  6. you need to set at some point the transaction object of the dw, for example in the 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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top