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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值