DataWindow.NET How To: Data Entry Form(检测表单字段是否不能为空)
2008-01-24 10:48
537 查看
DataWindow.NET How To: Data Entry Form
Simplifying database application development
By: Bruce Armstrong
Aug. 5, 2005 10:45 AM
Digg This!
Page 3 of 4 « previous page next page »
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.
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.
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.
Simplifying database application development
By: Bruce Armstrong
Aug. 5, 2005 10:45 AM
Digg This!
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
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.
相关文章推荐
- 解决jsp或serverlet 不能解析multipart/form-data 类型的表单域的问题 --http://ckasj.vicp.net/blog/index.php/archives/236
- How To Display Hierarchical Data by Using Nested Repeater Controls and Visual C# .NET(ZT)
- 使用jspsmartupload解决表单属性为multipart/form-data不能传其他参数的问题
- 提交表单检测数据是否为空getElementById() onSubmit form
- How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object
- 检测form表单是否有被修改
- How to fetch data from SAP system using sap .net connector?
- How To Create A Data Entry Screen
- How to change default form name "aspnetForm" in Beta 2
- 表单同时有中文字段和文件上传,加上enctype="multipart/form-data"后导致的中文乱码问题
- How to use Asp.Net Mvc ActionFilterAttribute for form authentication
- How to change default form name "aspnetForm" in Beta 2
- How to Turn Off Form Autocompletion FireFox下表单无法刷新重置的解决
- How To Automate Internet Explorer to POST Form Data
- ASP.NET中实现Form表单字段值自动填充到操作模型中
- How to submit data in InfoPath form services
- drupal7之学习在已存在的form表单中增加自定义验证(Learn how to add custom validation to an existing Drupal form)
- Csharp windowform datagridview TO EXCEL OR FROM EXCEL DATA 保存datagridview所有數據
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How to set window title name on Oracle EBS Form?