Search code examples
powerbuilderdatawindowsql

PowerBuilder Retrieve() via controls by the user


I am using SetTransObject() and Retrieve() on PowerBuilder 12.5 Classic. However it doesn't give the user much power in retrieving data; I have a single line edit(sle_employeeID), which the user needs to insert in the employee ID and the DataWindow displays the employee data (IDNO, name, age, designation) of a selected ID NO.

dw_1.settransobject(sqlca)
string employeeID
employeeID=sle_employee.text
dw_1.retrieve(employeeID)

The code retrieves the whole data as per my specifications from the DataWindow object, I used a tabular and quick select statement. Please help with a code that will give me a freer way to select data via controls.


Solution

  • You may want to use the DataWindow's Query Mode as Terry mentioned. You will have to provide your user with instructions, but the basic use is to simply enter the values you want to match directly in the DataWindow. For more information see the topic Providing query ability to users in the DataWindow Programmer's Guide. Here is code I have in one of my utility windows. It uses a menu with a toolbar button to put the DataWindow in Query Mode and to turn Query Mode off and retrieve. I'm using PFC message routing between the menu and the DataWindow event but you could simply call the event from a button clicked event, in which case you'd remove the lines that modify the menu.

    // this code is in an event in the DataWindow
    // toggles query mode on and off
    
    if "no" = object.dataWindow.queryMode then
        // you may want to check for unsaved changes here and let the user go back
        object.dataWindow.queryMode = "yes"
        m_myMenu.m_rows.m_query.checked = TRUE  // this has a button on the toolbar
    
    else
        m_myMenu.m_rows.m_query.checked = FALSE
        acceptText()
        object.dataWindow.queryMode = "no"
        retrieve()
    
    end if
    

    To get maximum flexibility set criteria.override_edit='yes' on some or all of the columns. The code below sets criteria.override_edit='yes' on all the columns. This may not be appropriate for your situation. Without override_edit the user is restricted to entering query values that pass the column validation.

    // this code is in an event in the DataWindow
    // it is called after the DataObject is set
    // it sets criteria.override_edit='yes' for all the columns
    
    string ls_describe, ls_modify, ls_col, ls_result
    integer li_colCount, li_col
    
    setTransObject(SQLCA)
    ls_describe = "datawindow.column.count"
    ls_result = dw_1.describe(ls_describe)
    if not isnumber(ls_result) then
            // logging code elided
            ls_result = '0'
    end if
    li_colCount = integer(ls_result)
    for li_col = li_colCount to 1 step -1
        ls_col = "#" + string(li_col)
        ls_modify = ls_col + ".criteria.override_edit='yes'"
        ls_result = dw_1.modify(ls_modify)
        if "" <> ls_result then 
       // every column may not have an edit, and some edits might not          // have the property. it's just as fast to try to modify it as it
       // is to check it
           // logging code elided
        end if
    next