`
xys_777
  • 浏览: 203874 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

datawindow的update过程中显示进度与中断

 
阅读更多

最近csdn上频频出现类似中断commit的问题:

http://topic.csdn.net/u/20090805/10/c9270a8b-2ac1-4beb-b59a-7d89dc6c4e07.html?58492

http://topic.csdn.net/u/20090806/03/5227d73b-4300-4c20-b353-5bbba45a50a6.html?8869

所以决定开始对这问题研究一下。

起初考虑的是用多线程的方法,可是无论怎么写都难以达到理想的效果,所以便开始从datawindow和datastore的事件上开始下手,果然在datawindow的sqlpreview事件上可以做。

commit是最后的提交,程序并不能中断这一操作。然而基本上我们都是先写一个update然后再commit,所以给人感觉提交数据库慢,其实慢在执行update函数上,所以可以中断update来阻止commit。

查看pb帮助,很清楚的写着:

Description

Occurs immediately before a SQL statement is submitted to the DBMS. Methods that trigger DBMS activity are Retrieve, Update, and ReselectRow.

Return value

Set the return code to affect the outcome of the event:

0 Continue processing
1 Stop processing
2 Skip this request and execute the next request

For information on setting the return code in a particular environment, see "About return values for DataWindow events".

于是可以得知datawindow的逐行提交过程可以在这个事件上做中断yield,即可将cpu时间分给执行其他代码。

下面是研究的一点成果:

实例一:这个是如何实现终止update操作

1、sqlpreview事件:

yield()
if ib_stopcommit then return 1 //ib_stopcommit实例变量

2、加一个按钮写上
ib_stopcommit=ture

3、加上dberror事件
return 1


实例二:这个是提交数据库操作中进行进度提示,以及gif动画的运行

1、sqlpreview事件:

w_wait.wf_setcurrentposition(row)//设置等待窗口的滚动条进度
yield()
if ib_stopcommit then return 1//停止

2、提交按钮:

wf_openwait() 打开进度提示窗口
wf_update()datawindow提交
wf_closewait() 关闭进度提示窗口

wf_openwait() 函数:

open(w_wait)
w_wait.wf_setmaxposition(dw_1.rowcount())

wf_update()函数:

if dw_1.update( ) =1 then
if ib_stopcommit then
return 1
end if
commit;
messagebox('系统提示','保存成功')
else
if ib_stopcommit then
return 1
end if
rollback;
messagebox('系统提示','保存失败')
end if

wf_closewait() 函数:

close(w_wait)

代码附件:

http://download.csdn.net/source/1566944

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics