//定义变量保存单号
string ls_bill;
//定义变量保存总行数 不应该每次循环都读取总行数
long ll_rowcount;
ll_rowcount=dw_2.rowcount();
for i=1 to ll_rowcount
//这里一项内容读取了两次 我认为如果定义变量可能会快一点
ls_bill=dw_2.getitemstring(i,"bill");
if isnull(ls_bill) or ls_bill<>bill then //用not会增加运算
messagebox("提示","出入库单号不能为空或已经修单号!")
return
end if
if isnull(dw_2.getitemstring(i,"item_code")) then //其实你这里应该判断是否等于"" 自己权衡吧
messagebox("提示","产品编码不能为空!")
//这里应该返回吧
return;
end if
if isnull(dw_2.getitemnumber(i,"qty")) then//其实你这里应该判断是否等于 0 ……自己权衡吧
messagebox("提示","出入库数量不能为空!")
return
end if
next
//下面这段语句我认为你写得相当繁琐
rtncode = dw_1.Update(TRUE, FALSE)
IF rtncode = 1 THEN
rtncode = dw_2.Update(TRUE, FALSE)
IF rtncode = 1 THEN
dw_1.ResetUpdate() // Both updates are OK
dw_2.ResetUpdate()// Clear update flags
COMMIT USING SQLCA; // Commit them
messagebox("提示","保存成功!")
pb_1.enabled=true
ELSE
ROLLBACK USING SQLCA; // 2nd update failed
messagebox("提示","保存失败")
END IF
END IF
我建议改为以下的书写方式,这样看起来简洁明了 要知道多一个if 程序就执行慢一些:
if dw_1.Update(TRUE, FALSE)=1 and dw_2.Update(TRUE, FALSE)=1 then
dw_1.ResetUpdate() // Both updates are OK
dw_2.ResetUpdate()// Clear update flags
commit;
messagebox("提示","保存成功!")
pb_1.enabled=true
else
ROLLBACK;
messagebox("提示","保存失败")
end if
//select count(*) into :row from inv_trans_head_stock where bill=:bill;
//
//if row>1 then
// messagebox("提示","此单据已经在数据库中存在!")
//end if
if isnull(dw_1.getitemstring(ll,"dept_no")) then
messagebox("提示","经办部门不能为空!")
return
end if
if isnull(dw_1.getitemstring(ll,"duty_man")) then
messagebox("提示","经办人不能为空!")
return
end if
if dw_2.rowcount()=0 then
messagebox("提示","产品明细数据不能为空!")
return
end if
for i=1 to dw_2.rowcount()
if isnull(dw_2.getitemstring(i,"bill")) or (not dw_2.getitemstring(i,"bill")=bill) then
messagebox("提示","出入库单号不能为空或已经修单号!")
return
end if
if isnull(dw_2.getitemstring(i,"item_code")) then messagebox("提示","产品编码不能为空!")
if isnull(dw_2.getitemnumber(i,"qty")) then
messagebox("提示","出入库数量不能为空!")
return
end if
next
dw_1.SetTransObject(SQLCA)
dw_2.SetTransObject(SQLCA)
rtncode = dw_1.Update(TRUE, FALSE)
IF rtncode = 1 THEN
rtncode = dw_2.Update(TRUE, FALSE)
IF rtncode = 1 THEN
dw_1.ResetUpdate() // Both updates are OK
dw_2.ResetUpdate()// Clear update flags
COMMIT USING SQLCA; // Commit them
messagebox("提示","保存成功!")
pb_1.enabled=true
ELSE
ROLLBACK USING SQLCA; // 2nd update failed
messagebox("提示","保存失败")
END IF
END IF