版主请进,PFC高手请进,讨论pfc_save()保存事件的处理过程

Thinkinger 2003-04-23 09:57:23
pfc_save()事件的处理过程包括以下代码:

Integer li_rc
Integer li_save_rc
Integer li_endtran_rc
powerobject lpo_updatearray[]

// Check if the CloseQuery process is in progress
If Not ib_closestatus Then

// Determine the objects for which an update will be attempted.
// For the pfc_save, the order sequence is as follows:
// 1) Specified one time sequence (thru pfc_saveobjects event).
// 2) Specified permananent sequence (thru of_SetUpdateObjects(...)).
// 3) None was specified, so use default window control array.
If UpperBound(ipo_tempupdateobjects) > 0 Then
lpo_updatearray = ipo_tempupdateobjects
ElseIf UpperBound(ipo_updateobjects) > 0 Then
lpo_updatearray = ipo_updateobjects
Else
lpo_updatearray = This.Control
End If

// Perform the Update Checks to determine if there are any updates
// pending and if they pass the standard validation
li_rc = of_UpdateChecks(lpo_updatearray)
If li_rc <= 0 Then
// 0 = No pending changes found
// -1 = AcceptText error
// -2 = UpdatesPending error was encountered
// -3 = Validation error was encountered
Return li_rc
End If
End If

// Perform the Update Preparation process.
If This.Event pfc_UpdatePrep(ipo_pendingupdates) <> 1 Then Return -9

// Perform the preupdate process.
If This.Event pfc_PreUpdate() <> 1 Then Return -4

// Begin the transaction.
If This.Event pfc_BeginTran() <> 1 Then Return -5

// Prevent datawindow dberror messages from appearing while PFC_Save
// updates are in progress.
ib_savestatus = True

// Update the changed objects.
li_save_rc = This.Event pfc_Update (ipo_pendingupdates)

// PFC_Save Updates are no longer in progress.
ib_savestatus = False


// Perform the endtransaction process
li_endtran_rc = This.Event pfc_EndTran(li_save_rc)

// If appropriate, display dberror message.
If li_save_rc<=0 Then This.Event pfc_dberror()

// Check for a successful save before performing any post operation.
If li_save_rc <> 1 Then Return -6

// Check for a successful end transaction before performing any post operation.
If li_endtran_rc <> 1 Then Return -7

// Perform the postupdate process.
If This.Event pfc_PostUpdate(ipo_pendingupdates) <> 1 Then Return -8

Return 1

//////////////////////////////////////////////////////////////////////////


我的理解是,pfc会先考察窗口中所有的数据窗口控件是否发生了修改,在pfc_UpdatePrep()事件的处理中,祖先程序会标记这些发生修改的数据窗口保存到
ipo_pendingupdates数组中,当我在pfc_UpdatePrep()事件中写入数据计算代码,然后
把计算的结果setitem()到某个数据窗口中时,pfc_UpdatePrep()事件的祖先程序并不能
把这些改变的数据窗口标记到ipo_pendingupdates中,这样的结果时,这些改变不能提交到数据库,这个问题怎样解决呢????
...全文
373 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
tchatcha 2003-04-24
  • 打赏
  • 举报
回复
将祖先代码注释了试试
青藤1111 2003-04-24
  • 打赏
  • 举报
回复
"当我手工修改数据窗口时,保存工作是能正常的工作的,当我用代码修改时不行!"

之后代码中必须加入 accepttext()语句,否则保存时不会将你修改的内容提交保存,

这是pfc_save() 时的执行过程:
pfc_AcceptText-》pfc_UpdatesPending-》
pfc_Validation-》pfc_UpdatePrep-》pfc_PreUpdate-》 pfc_BeginTran-》
pfc_Update—》 pfc_EndTran-》 pfc_DBError-》 pfc_PostUpdate。
Thinkinger 2003-04-24
  • 打赏
  • 举报
回复
我的应用是,用户输入基本的信息后,我要最后汇总基本信息,然后把汇总setitem()到另外一个datawindow中,最后一起提交保存,这也是一般化的需求规则,PFC肯定能实现的!
Thinkinger 2003-04-24
  • 打赏
  • 举报
回复
to wangsj_zj(藤):
在具体的实施中,我应该怎么做呢?

我们在保存中不是这样简单的代码:windowobject.event pfc_save()???

能不能在给点明确的指点,我的保存前的业务逻辑代码应该放在哪里合适?
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
to JIANXIN_LU(大侠):
它如果没有判断数据窗口被修改是不会激发UPDATESTART事件的,似乎这个方案是不行的!
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
to huangxinru(键盘手) :
这个应该跟事务是没有关系的,现在情况似乎是它判断数据窗口没有被修改!
JIANXIN_LU 2003-04-23
  • 打赏
  • 举报
回复
可以次修改的事件在数据窗口控件的UpdateStart事件中用TriggerEvent来驱动。
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
可以在祖先窗口的pfc_endtran中写上
IF ai_update_results = 1 THEN
COMMIT USING SQLCA;
IF SQLCA.SQLCODE = 0 THEN
RETURN 1
END IF
END IF

ROLLBACK USING SQLCA;
MessageBox("警告","数据存盘失败!")

RETURN -1

Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
to huangxinru(键盘手) :
我跟踪了一下,程序确实修改了数据窗口,可在数据库后台的跟踪中,没有发现提交语句,真是郁闷啊!
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
我们的程序就是这么写的,在pfc_updateprep中有setitem(),没有问题呀?
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
to huangxinru(键盘手) :
当我在数据窗口中手工修改数据时,pfc_UpdatePrep()能侦测到改变,也能正常的保存数据,现在我只能自己定义一个ue_save()事件,最后调用pfc_save()来做保存工作,这样的结果使我始终觉得没有发挥PFC的功能,而且在关闭窗口时,PFC在CLOSEQUERY事件中也可能调用pf_save(),现在我只能屏蔽掉
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
应该不存在这个问题,你可以检查一下update property或多表更新中的可更新列。关注。
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
我不能上QQ。setitem不能放在itemchanged、pfc_preinsertrow中吗?
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
要我手工修改数据窗口这种方式吗???????

你能上QQ吗?
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
“必须更改了dw中的其他内容”就是of_UpdateChecks(lpo_updatearray)>0;如果未更改dw中的其他内容,将导致of_UpdateChecks(lpo_updatearray)=0,pfc_save中止执行
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
谢谢你的帮助!!!!!!!!!!!!

你说的:“必须更改了dw中的其他内容,才能执行到上述的最后一条语句”,这是什么意思??

我说过,当我手工修改数据窗口时,保存工作是能正常的工作的,当我用代码修改时不行!

我怎么做合适呢????
huangxinru 2003-04-23
  • 打赏
  • 举报
回复
我又仔细看了一遍代码,
li_rc = of_UpdateChecks(lpo_updatearray)
If li_rc <= 0 Then
// 0 = No pending changes found
// -1 = AcceptText error
// -2 = UpdatesPending error was encountered
// -3 = Validation error was encountered
Return li_rc
End If
End If
// Perform the Update Preparation process.
If This.Event pfc_UpdatePrep(ipo_pendingupdates) <> 1 Then Return -9
就是说必须更改了dw中的其他内容,才能执行到上述的最后一条语句。你随意更改一下dw试一下。
我蛮喜欢看pfc的,也非常希望能和各位交流。
Thinkinger 2003-04-23
  • 打赏
  • 举报
回复
to huangxinru(键盘手) :
是不是在窗口打开时的设置方面有什么特别的要求呢????
请举个例子好吗?
我的pfc_preopen()事件中,主要是注册多表更新的代码

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧