| By Bruce Armstrong | Article Rating: |
|
| August 5, 2005 10:45 AM EDT | Reads: |
28,659 |
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.
dw_product_RowFocusChanged
If e.RowNumber > 0 And Not IsRetrieving Then
dw_productlist.SetRow(e.RowNumber)
If e.RowNumber > dw_productlist.LastRowOnPage Then
dw_productlist.ScrollToRow(e.RowNumber)
ElseIf e.RowNumber < dw_productlist.FirstRowOnPage Then
dw_productlist.ScrollToRow(e.RowNumber)
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
dw_product.AcceptText()
' Validate form values.
If Not IsValidForm() Then
Exit Sub
End If
Try
Dim conn As New System.Data.OleDb.OleDbConnection
conn.ConnectionString() = ConnectionString
conn.Open()
Dim SQLCA As New Sybase.DataWindow.AdoTransaction
SQLCA.Connection = conn
SQLCA.BindConnection()
dw_productlist.SetTransaction(SQLCA)
SQLCA.Transaction = SQLCA.Connection.BeginTransaction
dw_productlist.UpdateData()
SQLCA.Transaction.Commit()
SQLCA.Connection.Close()
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
Else
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.
Published August 5, 2005 Reads 28,659
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
![]() |
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. Thanks |
||||
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Names The World's 30 Most Influential Virtualization Bloggers
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects
































