程序代码如下:
有点长,简要说明如下:
//变量声明
//表头取数;
//插入表头数据;
//表体循环取数;
//表体循环插入值;
//插入成功,反写订单进度和当前单据审核状态;
用过调试和数据库的事件探查器跟踪,都没有发现什么错误,数据库检查过,已删除相关的触发器,但是结果还一样。但是就是如上出现奇怪现象,请高手指教。
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 = ''
ls_cdefine8 = dw_detail.getitemstring(ll_mrow,"cdefine8")
//if isnull(ls_cdefine8) then ls_cdefine8 = ''
ls_cdefine9 = dw_detail.getitemstring(ll_mrow,"cdefine9")
//if isnull(ls_cdefine9) then ls_cdefine9 = ''
ls_cdefine10 = dw_detail.getitemstring(ll_mrow,"cdefine10")
//if isnull(ls_cdefine10) then ls_cdefine10 = ''
ls_ccuscode = dw_detail.getitemstring(ll_mrow,"ccuscode")
//if isnull(ls_ccuscode) then ls_ccuscode = ''
//ls_vencode = dw_detail.getitemstring(ll_mrow,"cvencode")
//if isnull(ls_vencode) then ls_vencode = ''
ls_cmaker = uf_returnusername(g_app.id)
ls_cwhcode[1] = dw_1.getitemstring(1,"cwhcode")
//ls_cwhcode[1] = '003'
update rdrecord set id = id where 1=0;
select max(id) into :ll_id from rdrecord WITH (HOLDLOCK)
using sqlca;
if isnull(ll_id) then
ll_id = 1
else
ll_id = ll_id + 1
end if
insert into rdrecord
(ID,bRdFlag,cVouchtype,cBustype,cSource,cWhcode,dDate,cCode,cMaker,VT_ID,cPsPcode,cMPoCode,bTransFlag,bIsSTQc,crdcode,cdepcode,cpersoncode,cmemo,ccuscode,cdefine1,cdefine2,cdefine3,cdefine4,cdefine5,cdefine6,cdefine7,cdefine8,cdefine9,cdefine10)
values (:ll_id,0,"32","普通销售","发货单",:ls_cwhcode[1],:d_outdate,:ls_ccode,:ls_cmaker,65,:ls_cpspcode,:ls_mpcode,0,0,:ls_rdstyle,:ls_department,:ls_person,:ls_cmemo,:ls_ccuscode,:ls_cdefine1,:ls_cdefine2,:ls_cdefine3,:d_cdefine4,:ll_cdefine5,:d_cdefine6,:d_cdefine7,:ls_cdefine8,:ls_cdefine9,:ls_cdefine10) using sqlca;
if sqlca.sqlcode = 0 then
commit using sqlca;
else
messagebox('提示','单据保存失败,错误原因请参考:'+sqlca.sqlerrtext)
rollback using sqlca;
return
end if
update rdrecords set autoid = autoid where 1=0;
select max(autoid) into :ll_autoid from rdrecords WITH (HOLDLOCK)
using sqlca;
if isnull(ll_autoid) then
ll_autoid = 1
else
ll_autoid = ll_autoid + 1
end if
for ll_row = 1 to dw_1.rowcount()
ls_cinvcode = dw_1.getitemstring(ll_row,"cinvcode")
// ls_rpcinvcode = dw_1.getitemstring(ll_row,"rpcinvcode")
// if len(trim(ls_rpcinvcode)) <> 0 then ls_cinvcode = ls_rpcinvcode
ls_cbatch = dw_1.getitemstring(ll_row,"cbatch")
ls_cfree1 = dw_1.getitemstring(ll_row,"cfree1")
ls_cfree2 = dw_1.getitemstring(ll_row,"cfree2")
ls_cfree3 = dw_1.getitemstring(ll_row,"cfree3")
ls_cfree4 = dw_1.getitemstring(ll_row,"cfree4")
ls_cfree5 = dw_1.getitemstring(ll_row,"cfree5")
ls_cfree6 = dw_1.getitemstring(ll_row,"cfree6")
ls_cfree7 = dw_1.getitemstring(ll_row,"cfree7")
ls_cfree8 = dw_1.getitemstring(ll_row,"cfree8")
ls_cfree9 = dw_1.getitemstring(ll_row,"cfree9")
ls_cfree10 = dw_1.getitemstring(ll_row,"cfree10")
d_iquantity = dw_1.getitemdecimal(ll_row,"iquantity")
d_fquantity = dw_1.getitemdecimal(ll_row,"fquantity")
d_iunitcost = dw_1.getitemdecimal(ll_row,"itaxunitprice")
//d_iprice = dw_1.getitemdecimal(ll_row,"isum")
d_iprice = d_fquantity * d_iunitcost
//ll_iMPoIds = dw_1.getitemnumber(ll_row,"iMPoIds")
ll_mpmainid = dw_1.getitemnumber(ll_row,"isosid")
ll_dlsid = dw_1.getitemnumber(ll_row,"autoid")
ls_cdefine25 = dw_1.getitemstring(ll_row,"cdefine25")
insert into rdrecords (AutoID,ID,cInvCode,iQuantity,iFlag,iPOsID,cbatch,cfree1,cfree2,cfree3,cfree4,cfree5,cfree6,cfree7,cfree8,cfree9,cfree10,isoutquantity,iPunitcost,
iPprice,cdefine25,iDLsID)
values (:ll_autoid,:ll_id,:ls_cinvcode,:d_fquantity,0,:ll_mpmainid,:ls_cbatch,:ls_cfree1,:ls_cfree2,:ls_cfree3,:ls_cfree4,:ls_cfree5,:ls_cfree6,:ls_cfree7,:ls_cfree8,:ls_cfree9,:ls_cfree10,&
:d_iquantity,:d_iunitcost,:d_iprice,:ls_cdefine25,:ll_dlsid)
using sqlca;
if sqlca.sqlcode <> 0 then
messagebox('提示','单据保存失败,错误原因请参考:'+sqlca.sqlerrtext)
rollback using sqlca;
return
end if
//修改现存量
if isnull(ls_cbatch) then ls_cbatch = ''
if isnull(ls_cfree1) then ls_cfree1 = ''
if isnull(ls_cfree2) then ls_cfree2 = ''
if isnull(ls_cfree3) then ls_cfree3 = ''
if isnull(ls_cfree4) then ls_cfree4 = ''
if isnull(ls_cfree5) then ls_cfree5 = ''
if isnull(ls_cfree6) then ls_cfree6 = ''
if isnull(ls_cfree7) then ls_cfree7 = ''
if isnull(ls_cfree8) then ls_cfree8 = ''
if isnull(ls_cfree9) then ls_cfree9 = ''
if isnull(ls_cfree10) then ls_cfree10 = ''
update currentstock set iquantity = iquantity - :d_fquantity,foutquantity = :d_fquantity
where cwhcode = :ls_cwhcode[1] and cinvcode = :ls_cinvcode and cbatch = :ls_cbatch
and cfree1 = :ls_cfree1 and cfree2 = :ls_cfree2 and cfree3 = :ls_cfree3
using sqlca;
if sqlca.sqlcode <> 0 then
messagebox('提示','生成过程意外中断,错误原因请参考'+sqlca.sqlerrtext)
rollback using sqlca;
return
end if
////////////////////
//反写销售订单,已出库数量
update pp_pomain set iFHQuantity = :d_iquantity + isnull(iFHQuantity,0)
where mainid = :ll_mpmainid using sqlca;
if sqlca.sqlcode <> 0 and sqlca.sqlcode <> 100 then
messagebox('提示','生成过程意外中断,修改订单已发货数量出错,~r~n错误原因请参考'+sqlca.sqlerrtext)
rollback using sqlca;
return
end if
ll_autoid = ll_autoid + 1
next
if sqlca.sqlcode = 0 then
commit using sqlca;
else
messagebox('提示','生成过程意外中断,错误原因请参考'+sqlca.sqlerrtext)
rollback using sqlca;
return
end if
update dispatchlist set isflag = '3',outdate = :d_outdate,checkopinion = :ls_checkopinion,
cverifier = :ls_cveriperson,cveridate = :d_cveridate where dlid = :ll_mpid
using sqlca;
if sqlca.sqlcode = 0 then
commit using sqlca;
dw_1.setredraw(true)
st_1.visible = false
dw_detail.setitem(1,"isflag","3")
dw_detail.setitem(1,"cverifier",ls_cveriperson)
dw_detail.setitem(1,"cveridate",d_cveridate)
ls_dlcode_old = dw_detail.getitemstring(1,"cdlcode")
messagebox('提示','当前单据生成出库单成功!')
cb_3.TriggerEvent(clicked!)
else
st_1.visible = false
ls_err = '错误代号:+' + string(sqlca.sqlcode) + sqlca.sqlerrtext
rollback using sqlca;
messagebox('提示','生成失败,错误原因请参考'+ ls_err)
return
end if
6 个解决方案
#1
所谓第一次审核,第二次审核是指审核后弃审,弃审过后的数据也已经反复核对过数据库,确实已经删除掉对应记录。
#2
什么数据库?
#3
SQL Server 的话,用事件探查器看看这段程序和DB 都交互了些什么。
另外,程序有点长,大至看到了这里:
其中,sqlca.sqlcode 是用于检测SQL 语句是否执行成功的,并不表示检索的行已经存在。
sqlca 对象的sqlnrows 属性返回受当前SQL 语句影响的行数。
另外,程序有点长,大至看到了这里:
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
其中,sqlca.sqlcode 是用于检测SQL 语句是否执行成功的,并不表示检索的行已经存在。
sqlca 对象的sqlnrows 属性返回受当前SQL 语句影响的行数。
#4
sql数据库,这段代码是获得单号的与子表记录插入无关
#5
sql有点长,把非关键的地方全部注释掉,然后再测试
#6
感谢各位,发现错误了,是我无意中把数据库外键去掉了,导致了一个隐蔽性的错误。
#1
所谓第一次审核,第二次审核是指审核后弃审,弃审过后的数据也已经反复核对过数据库,确实已经删除掉对应记录。
#2
什么数据库?
#3
SQL Server 的话,用事件探查器看看这段程序和DB 都交互了些什么。
另外,程序有点长,大至看到了这里:
其中,sqlca.sqlcode 是用于检测SQL 语句是否执行成功的,并不表示检索的行已经存在。
sqlca 对象的sqlnrows 属性返回受当前SQL 语句影响的行数。
另外,程序有点长,大至看到了这里:
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
其中,sqlca.sqlcode 是用于检测SQL 语句是否执行成功的,并不表示检索的行已经存在。
sqlca 对象的sqlnrows 属性返回受当前SQL 语句影响的行数。
#4
sql数据库,这段代码是获得单号的与子表记录插入无关
#5
sql有点长,把非关键的地方全部注释掉,然后再测试
#6
感谢各位,发现错误了,是我无意中把数据库外键去掉了,导致了一个隐蔽性的错误。