PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

DataWindow.NET How To: Data Entry Form

Simplifying database application development

There's a similar method coded for the dw_product DataWindowControl. All the rows of data are available in that DataWindowControl, but only one row is shown. As a result, if the user tabs out on the last column of dw_product, or reverse tabs (shift-tab) on the first column, he or she will actually scroll that DataWindowControl into the next or prior row of data. The dw_product_RowFocusChanged method, as shown below, keeps the two views of the product data in synch by moving the row selection indicator on the dw_productlist DataWindowControl to match the newly selected product. Note that it also uses the LastRowOnPage and FirstRowOnPage properties to determine if the dw_productlist data has to be scrolled forwards or backward to ensure that the newly selected product is visible in that DataWindowControl.

If e.RowNumber > 0 And Not IsRetrieving Then
If e.RowNumber > dw_productlist.LastRowOnPage Then
ElseIf e.RowNumber < dw_productlist.FirstRowOnPage Then
End If
End If

Let's assume that the user has made some changes to the product data and now wants to issue an update. With the VB.NET form, the btnUpdate_Click method first determines if the user is updating a new or existing row by checking the Mode variable, and then calls the AddProduct or UpdateProduct form methods, respectively. Once again, because the DataWindow keeps track of whether a row is being inserted or updated for us, the DW.NET version of the form only has to call its version of the UpdateProduct form method.

The VB.NET AddProduct and UpdateProduct methods contain roughly 50 lines of code each to parse together the insert or update statement needed to update the product. And, as with the .NET Pet Shop sample, no provision has been made for collision detection on the update. That is, every column is updated, whether modified or not, and the update is based solely on the primary key for the product table. If two more users try to update the same product, the last user to update wins, and no warning is given to any of the users that there might be an issue.

The DW.NET UpdateProduct method, while significantly smaller, addresses these issues. The DataWindow Object offers several options for determining how update statements are automatically generated (see Figure 6). One of them (the one used here) automatically generates a WHERE clause that includes all updateable columns and their original values. In there is an update collision, the second and subsequent users attempting to update the same data will be informed of the collision and their changes won't be applied.

DW.NET UpdateProduct
' Validate form values.
If Not IsValidForm() Then
Exit Sub
End If
Dim conn As New System.Data.OleDb.OleDbConnection
conn.ConnectionString() = ConnectionString
Dim SQLCA As New Sybase.DataWindow.AdoTransaction
SQLCA.Connection = conn
SQLCA.Transaction = SQLCA.Connection.BeginTransaction
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try

Both the VB.NET and the DW.NET UpdateProduct methods (and the VB.NET AddProduct method) call an IsValidForm method to determine if the user has provided all the data necessary before attempting the update. The VB.NET version of this method checks each of the individual controls to make sure they have been populated. The DW.NET version, as shown below, is not only smaller, it's also much more flexible:

DW.NET IsValidForm
Dim row As Integer = dw_product.CurrentRow
Dim column As Int16 = 1
dw_product.FindNextRequiredColumn(row, column, DataBuffer.Primary, True)
If row > 0 Then
Dim columnname As String = dw_product.GetColumnObjectByNumber(column).Name()
MsgBox("Please enter a value for " + columnname, MsgBoxStyle.Exclamation, Me.Text)
Return False
Return True
End If

There's an attribute on a column edit style in the DataWindow Object to indicate whether the column is required. The DataWindowControl FindNextRequiredColumn method is then used to determine whether any of these required columns haven't been populated. Note that the method doesn't refer to any specific columns by name. The approach is quite generic, and can be applied to any DataWindow. Any customization of the behavior is handled by the attributes on the DataWindow Object.

More Stories By Bruce Armstrong

Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
alvin 07/23/08 08:36:24 PM EDT

how can i change the highlight color of selected row? the default is dark blue which is too heavy. thanks

Allan A. Cartagenas 08/18/05 04:38:53 AM EDT

Where can I download the file frmDWMain.vb? The link to download the file is not included on the article.