您的位置:首页 > 其它

PB中如何判断数据窗口发生的改变

2012-09-24 16:19 661 查看
问题:

一个数据窗口的数据发生了改变,但是该如何确定是哪些行的哪些列发生了改变?

方法:

(注:本方法仅限于对数据 修改的判断,不包含新增或删除的数据)

Step 1,在数据窗口中加入一个计算列 if(IsRowModified(),'Y','N'),命名为 ismodified , 用来判断对应的数据行是否有改变。

Step 2, 编写检验代码

If dw_ticket.ModifiedCount() = 0 Then Return

String ls_objects, ls_obj, ls_label, ls_coltype, ls_colvalue1, ls_colvalue2
Long	ll_pos, ll_getrow, ll_rows
String	ls_modified_col

dw_ticket.AcceptText()
ll_rows = dw_ticket.RowCount()

For ll_getrow = 1 To ll_rows
If dw_ticket.GetItemString(ll_getrow,'ismodified') = 'N' Then Continue

ls_modified_col = ''
ls_objects = dw_ticket.Describe("DataWindow.Objects") + "~t"

Do
ll_pos = pos(ls_objects, "~t")
ls_obj = left(ls_objects,ll_pos - 1)

If (dw_ticket.describe(ls_obj+ ".type")) <> "column" Then
ls_objects = right(ls_objects,len(ls_objects) - ll_pos)
Continue
End If

ls_coltype = dw_ticket.Describe(ls_obj + ".coltype")
ls_label = dw_ticket.Describe(ls_obj + "_t.text")

If ll_getrow > 0 Then
If Pos(ls_coltype, 'char') > 0 Then
ls_colvalue1 = dw_ticket.GetItemString(ll_getrow, ls_obj, Primary!, True)
ls_colvalue2 = dw_ticket.GetItemString(ll_getrow, ls_obj, Primary!, False)
ElseIf Pos(ls_coltype, 'datetime') > 0 Then
ls_colvalue1 = String(dw_ticket.GetItemDateTime(ll_getrow, ls_obj, Primary!, True))
ls_colvalue2 = String(dw_ticket.GetItemDateTime(ll_getrow, ls_obj, Primary!, False))
ElseIf Pos(ls_coltype, 'timestamp') > 0 Then
ls_colvalue1 = dw_ticket.GetItemString(ll_getrow, ls_obj, Primary!, True)
ls_colvalue2 = dw_ticket.GetItemString(ll_getrow, ls_obj, Primary!, False)
ElseIf Pos(ls_coltype, 'long') > 0 Then
ls_colvalue1 = String(dw_ticket.GetItemNumber(ll_getrow, ls_obj, Primary!, True))
ls_colvalue2 = String(dw_ticket.GetItemNumber(ll_getrow, ls_obj, Primary!, False))
ElseIf (Pos(ls_coltype, 'number') > 0 Or Pos(ls_coltype, 'decimal') > 0) Then
ls_colvalue1 = String(dw_ticket.GetItemDecimal(ll_getrow, ls_obj, Primary!, True))
ls_colvalue2 = String(dw_ticket.GetItemDecimal(ll_getrow, ls_obj, Primary!, False))
ElseIf Pos(ls_coltype, 'real') > 0 Then
ls_colvalue1 = String(dw_ticket.GetItemDecimal(ll_getrow, ls_obj, Primary!, True))
ls_colvalue2 = String(dw_ticket.GetItemDecimal(ll_getrow, ls_obj, Primary!, False))
End If

If ls_colvalue1 <> ls_colvalue2 Then
ls_modified_col = ls_modified_col + ls_obj + "~t"
End If

End If

ls_objects = right(ls_objects,len(ls_objects) - ll_pos)
Loop While (Pos(ls_objects, "~t") > 0)

MessageBox("Info","The row: " + String(ll_getrow) + " is modified." + "~r~nModified Columns: " + ls_modified_col)

Next
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐