VFP9:两个以上用户共同编辑一个表时出现的锁定和解锁问题,请指正......
msso_h 父表msso_d:子表
cNosaveText=不能保存,其他人正在使用
例:A用户正在编辑记录1,B用户正在编辑记录2,
这时A用户编辑完按“保存”会发现“不能保存,其他人正在使用”
B用户编辑完按“保存”也会“不能保存,其他人正在使用”
结果死循环,只能撤销。
******************************下面是“保存”的代码*********************************
If This.goto_txtemploy()
Else
Return .F.
Endif
curarea=sele()
Begin TRANSACTION
If THIS.modifyflag
=this.revdata()
Sele msso_h
Replace grand_amt WITH THISFORM.pageframe1.page1.txtgrand_amt.VALUE
Select msso_d
Delete IN msso_d FOR empty(stock_code)
Else
lastno = AUTONO("msso_h","msso_id")
If typeesc
Rollback
Return
Endif
Select msso_h
If Rlock()
Repl msso_h.msso_id WITH lastno,;
grand_amt WITH THISFORM.pageframe1.page1.txtgrand_amt.VALUE
Sele msso_d
GO RECNO()
SCAN For alltrim(msso_id)="NEW"
REPL msso_id WITH lastno FOR UPPER(ALLTRIM(msso_id))="NEW"
Delete IN msso_d FOR empty(stock_code)
DELETE IN msso_d for msso_d.qty_l+msso_d.qty_s=0
ENDSCAN
UNLOCK ALL
Else
Rollback
= MESSAGEBOX(cMessageText,64,'警告!')
Sele (curarea)
Return
endif
endif
saveOK = tableupdate(1,.T.,'msso_h')
if saveOK
saveOK = tableupdate(1,.T.,'msso_d')
endif
IF saveOK
End Transaction
This.lallowedits=.T.
This.lallowdelete=.T.
This.lallownew=.T.
This.CLOSABLE=.T.
IF .NOT.THIS.modifyflag
WAIT WIND "存盘成功,单号是:"+lastno NOWAIT
ELSE
WAIT WIND "存盘成功... " NOWAIT
ENDIF
SELE msso_h
UNLOCK ALL
THIS.REFRESH()
this.pageframe1.page1.cmdfocuscontrol.SETFOCUS()
else
ROLLBACK
Sele (curarea)
=MESSAGEBOX(CHR(13)+cNosaveText,0+0+0,"提示")
Return
Endif
*****************************下面是“编辑”的代码************************
Sele msso_h
If filed.or.finished
=messagebox("这张单已经完成,不能修改!",0+0+0,"提示")
Return
Endif
a=recno()
GO a
IF Rlock()
Sele * from msso_d into cursor tmpmsso where msso_id=msso_h.msso_id
This.lAllowEdits=.f.
This.lAllowdelete=.f.
This.lAllownew=.f.
This.closable=.f.
This.modifyflag=.t.
Thisform.pageframe1.ACTIVEPAGE = 1
Thisform.pageframe1.page2.ENABLED = .F.
Thisform.pageframe1.page1.grdlineitems.setfocus()
Else
= MESSAGEBOX('其他用户正在使用,请稍候尝试!',64,'警告!')
Sele msso_h
Return
Endif