Tuesday, 10 June 2014

Prevent Acceidental close at Powerbuilder and save the datawindow contents.

Hi

Today am going to share about how to prevent the window closing when the data are not saved in the datawindow.
Usually when you did any changes to your data window if you not saved that datawindow and if you clos that datawindow  no data will be saved.
So to avoid that and your application users must save the datawindow while before closing the window use the following code to protect the accidental close.

Code follows

Write this code on your windows Close Query Event. Or if you want you can write at base window.

Integer li_count,li_ret

window aw_window
aw_window=this

FOR li_count = 1 TO UpperBound(control[])
    IF TypeOf(aw_window.control[li_count])=Datawindow! Then
        Datawindow dw
        dw=control[li_count]
        IF dw.AcceptText() = 1 AND dw.ModifiedCount() > 0  THEN
            li_ret=Messagebox('Alert','Changes Not Saved, Do you Want to Save it?',Question!,YesNo!,1)
            If li_ret=1 Then Return 1
        End if
    End if        
NEXT

this code is common to all windows you can write this code at your base objects close query event.

Explanation :
 aw.control[] this code is used to get the all controls places on the window.
Using the control we are verifying the type using the TypeOf. If the type is datawindow then we are checking is there any modifications happened using the Acceptext() function.
After this we are checking for modified count. Whether the data is changed or not. If so then we are giving the messagebox to ask the user to close or not.

You can also code the datawindow to save automatically when the user click Yes button. Write the update code on the return value loop statement.
dw.update()

thats it.

Regards
Raj




Wednesday, 21 May 2014

How to Change the Child datawindow object dynamically at run time in Powerbuilder

Hi Every one

Hope all fine. Today am going to discuss with how to change the child datawindow name dynamically based on some value or some other thing.

Initially we will setup the child datawindow with the dataobject and will choose the display column and data column.
But what happen if we want to change that child datawindow itself based on the used input. Here is the code.
Here the name Datawindow represents your datawindow name and the column_name represents your column name . And the dd_child_new represents the data object you want to set. Code follows

//Change datawindow child object
Datawindow.Modify("column_name.DDDW.Name=dd_child_new")

// Setting display column
Datawindow.Modify("column_name.DDDW.DisplayColumn='Short_name'")

// Setting data column
Datawindow.Modify("column_name.DDDW.DataColumn='Number'")

DataWindowChild ldwc_child
Datawindow.Getchild("column_name",ldwc_child)
ldwc_child.Settransobject(SQLCA)
ldwc_child.Retrieve()
ldwc_child.Reset()


hope this will help you a bit

Regards
Raj~