由于when-validate-item 不能使用go_item(),first_record等,而when-new-item-instance却答应,所以,可以这样处理: 以基本表(id主键,name ,remark,20行每页界面) 在id(主键)的下一导航项,设置为check_uniqueness_button.
check_uniqueness_button为这个块内的一个按钮,它的when-new-item-instance担任检查该行的重复情况的功能,代码见本贴附录。 另外,手工按check_uniqueness_button,也会执行这段代码,产生手工检查重复情况的功能。 附录代码: declare temprecord number; tempval varchar2(20); temp_count number :=0; BEGIN go_item('base_table.id'); temprecord := :system.cursor_record; tempval := :base_table.id; first_record; if :system.current_value is not null then ---假如有记录,开始运算 loop if :base_table.id = tempval and :system.cursor_record <> temprecord then temp_count := temp_count + 1; message('代码有重复,请检查第:' :system.cursor_record '行,代码:' :base_table.id ',名称:' :base_table.name); message('代码有重复,请检查第:' :system.cursor_record '行,代码:' :base_table.id ',名称:' :base_table.name); end if; next_record; if :system.current_value is null then exit; end if; end loop; if temp_count = 0 then message('该行代码没有重复'); end if; go_record(temprecord); go_item('base_table.name'); else message('光标所有行没有代码为空,请先将光标放在有数值的地方'); message('光标所有行没有代码为空,请先将光标放在有数值的地方'); end if; END; 附录 check_record_uniqueness 可以检查一个数据块(Data Block)内,主键有无重复的记录。 使用方法举例: 1.Block 上,先设定一个item是主键。 2。在主键字段的 when-validate-item trigger 上,加入如下代码: check_record_uniqueness; if not form_sUCess then clear message; message(数据有重复!"); end if; 以上代码,可以使用户每输入一条记录时,系统自动检查主键有无重复。 优点:速度快,代码简单。 缺点:只能应用于主键。 最致命的缺点:经测试后我发现,它只能检查新输入的数据,与已存盘的数据有无重复。假如新输入的记录与未存盘的记录重复,它不会报警! 使用建议: 1。只可用于比较简单的场合,及用户每次输入的资料数目比较少的情况。假如用户大批量输入:如每次输入几十条,甚至上百条,使用check_record_uniqueness便会心惊胆跳了,因为谁也不能保证 ,新输入的数据内会否有重复。 2。假如不是应用于主键,假如每次用户输入量可能比较大,建议自行编写查重复的代码。
|