当前位置: 代码迷 >> PB >> 一段程序第一次运行第二行生成一条记录,第二次两条,第三次三条解决办法
  详细解决方案

一段程序第一次运行第二行生成一条记录,第二次两条,第三次三条解决办法

热度:96   发布时间:2016-04-29 08:53:01.0
一段程序第一次运行第二行生成一条记录,第二次两条,第三次三条
一段程序用于发货单审核生成出库单,程序代码应该也不复杂,但是这两天测试就是发现如此奇怪的事。第一次审核正常,两条发货单记录生成了两条出库单记录;第二次第一行记录正常,第二条记录变成两个,第三次第一条记录还是正常,第二条记录变成三个:

程序代码如下:

有点长,简要说明如下:

//变量声明
//表头取数;

//插入表头数据;

//表体循环取数;

//表体循环插入值;

//插入成功,反写订单进度和当前单据审核状态;

用过调试和数据库的事件探查器跟踪,都没有发现什么错误,数据库检查过,已删除相关的触发器,但是结果还一样。但是就是如上出现奇怪现象,请高手指教。
if dw_1.accepttext() < 1 then return
if dw_detail.accepttext() < 1 then return

ll_mrow = dw_detail.getrow()
ll_mpid = dw_detail.getitemnumber(ll_mrow,"DLID")

d_outdate = date(dw_detail.getitemdatetime(1,"outdate"))

ls_checkopinion = dw_detail.getitemstring(1,"checkopinion")

dd_today = date(uf_getserverdatetime())

d_cveridate = uf_getserverdatetime()

ls_cveriperson = uf_returnusername(g_app.id)

if isnull(d_outdate) then
messagebox('提示','实发送货日期不允许为空,请核对后输入')
return 
end if

ll_istate = DaysAfter(d_outdate,dd_today)

if abs(ll_istate) > 10 then
 if messagebox('提示','实发日期与当前日期相差过大,是否继续?',Question!,yesno!) = 2 then return 
end if

st_1.visible = true

ls_modify_new = 'Y'

dw_generate.reset()

dd_today = date(uf_getserverdatetime())

ls_head_yyyymm = string(date(dd_today),'yyyymm')

//这里是取单号
select top 1 cNumber into :ll_foot
  from VoucherHistory where CardNumber = 'XS'
  using sqlca;
 
if sqlca.sqlcode = 100 then
insert VoucherHistory(CardNumber,cContentRule,cseed,cNumber,bEmpty) values  
('XS','年月',1,1,0) using sqlca;
end if
 
if isnull(ll_foot) then ll_foot = 1

//ls_ccode = ls_head_yyyymm + string(10000 + ll_foot)

nn:
ls_ccode = string(long(ls_head_yyyymm) * 10000 + ll_foot)

ls_ccode = 'XS'+ls_ccode
//上面这里还不能完全肯定避免单据号重复,注意必须符合单据号不允许重复的原则。

select top 1 ccode into :ls_tcccode from rdrecord where ccode = :ls_ccode
using sqlca;

if sqlca.sqlcode = 0 then
// messagebox('提示','单据号已存在,请核对后重新输入')
// return
ll_foot = ll_foot +1
goto nn
end if

ls_rdstyle = dw_detail.getitemstring(ll_mrow,"crdcode")

ls_department = dw_detail.getitemstring(ll_mrow,"cdepcode")
//if isnull(ls_department) then ls_department = ''

ls_person = dw_detail.getitemstring(ll_mrow,"cpersoncode")
//if isnull(ls_person) then ls_person = ''

ls_cmemo = dw_detail.getitemstring(ll_mrow,"cmemo")
//if isnull(ls_cmemo) then ls_cmemo = ''

ls_rdtype = dw_detail.getitemstring(ll_mrow,"cvouchtype")
if isnull(ls_rdtype) then ls_rdtype = '32'

//ls_businesstype = dw_detail.getitemstring(ll_mrow,"cbustype")
if isnull(ls_businesstype) then ls_businesstype = '普通销售'

//ls_cprobatch = dw_detail.getitemstring(ll_mrow,"cprobatch")
//if isnull(ls_cprobatch) then ls_cprobatch = ''

ls_cdefine1 = dw_detail.getitemstring(ll_mrow,"cdefine1")
//if isnull(ls_cdefine1) then ls_cdefine1 = ''

ls_cdefine2 = dw_detail.getitemstring(ll_mrow,"cdefine2")
//if isnull(ls_cdefine2) then ls_cdefine2 = ''

ls_cdefine3 = dw_detail.getitemstring(ll_mrow,"cdefine3")
//if isnull(ls_cdefine3) then ls_cdefine3 = ''

d_cdefine4 = dw_detail.getitemdatetime(ll_mrow,"cdefine4")
//if isnull(d_cdefine4) then d_cdefine4 = ''

ll_cdefine5 = dw_detail.getitemnumber(ll_mrow,"cdefine5")
//if isnull(ll_cdefine5) then ll_cdefine5 = ''

d_cdefine6 = dw_detail.getitemdatetime(ll_mrow,"cdefine6")
//if isnull(d_cdefine6) then d_cdefine6 = ''

d_cdefine7 = dw_detail.getitemdecimal(ll_mrow,"cdefine7")
//if isnull(ls_cdefine3) then ls_cdefine3 = ''
  相关解决方案