以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  检查表中数据是否合理  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=158153)

--  作者:hopestarxia
--  发布时间:2020/11/10 0:42:00
--  检查表中数据是否合理
老师:
设计了一单据窗口,窗口中有table1,
其中table1表中设置了起始编码,结束编码两列,
想实现在保存单据时,检查明细table1表中录入数据是否合理,
在保存中这段检查代码请问如何实现?

明细表中要求每行的数据(起始编号,结束编号)不能包含在别的行的这两例的区间段范围内。
例如
行号   起始编码  结束编码
  1      50001   55000
  2      51001   51200

这种情况就提示第二行数据不合理,号码段已经在表中存在,不能重复录入。

如下情况多行之间不互相包含,则检查通过:
行号   起始编码  结束编码
  1      50001   55000
  2      81001   81200








--  作者:有点蓝
--  发布时间:2020/11/10 9:03:00
--  
如果是后台表,保存后使用sql判断效率高一点

select count(*) as 不合理数量 from {表C} as a inner join {表C} as b on a.[_Identify] <> b.[_Identify] where (a.起始编码 < b.起始编码 and a.结束编码 > b.起始编码) or (a.结束编码 > b.结束编码 and a.起始编码 < b.结束编码 )

或者使用代码遍历处理。

for each  r as row in tables("表C").rows
dim dr as datarow = datatables("表C").find("((起始编码 < " & r("起始编码") & " and 结束编码 > " & r("起始编码") & ") or (结束编码 > " & r("结束编码") & " and 起始编码 < " & r("结束编码") & " )) and _Identify <>" & r("_Identify"))
if dr isnot nothing then
msgbox("不合理")

--  作者:hopestarxia
--  发布时间:2020/11/11 17:50:00
--  
谢谢,就是想还没有存入后台数据时先检查一下数据是否录入合理。