如何选中复选框并自动选择其他相关复选框。

时间:2015-01-12 11:15:54

标签: plsql oracleforms

我有以下代码。我的目标是选择一个复选框,然后选中所有相关的复选框。当我选择第一个复选框和下一个组复选框时,我能够自动选择其他复选框,但是当我选择第二个复选框并且第一个复选框与第二个复选框相关时,它不起作用,第一个复选框未自动选中,

看起来循环不会回到原点。我的代码出了什么问题?

DECLARE
    v_selected_contract       VARCHAR2 (50);
    v_selected_contract_ver   NUMBER;
    v_selected_contract_n     VARCHAR2 (50);
    v_selected_contract_ver_n NUMBER;
BEGIN
    Go_block('PCMS_CONTRACT_LINES');

    --  first_record;
    IF :PCMS_CONTRACT_LINES.selected = 'Y' THEN
      v_selected_contract := :PCMS_CONTRACT_LINES.contract_num;
      v_selected_contract_ver := :PCMS_CONTRACT_LINES.contract_version_num;

      WHILE :PCMS_CONTRACT_LINES.contract_num = v_selected_contract
            AND :PCMS_CONTRACT_LINES.contract_version_num =
                v_selected_contract_ver
      LOOP
          :PCMS_CONTRACT_LINES.selected := 'Y';
          EXIT WHEN :System.last_record = 'TRUE';
          next_record;
      END LOOP;
      Go_block('PCMS_CONTRACT_LINES');
      first_record;
    ELSE
      v_selected_contract_n := :PCMS_CONTRACT_LINES.contract_num;
      v_selected_contract_ver_n := :PCMS_CONTRACT_LINES.contract_version_num;

      WHILE :PCMS_CONTRACT_LINES.contract_num = v_selected_contract_n
            AND :PCMS_CONTRACT_LINES.contract_version_num =
                v_selected_contract_ver_n LOOP
          :PCMS_CONTRACT_LINES.selected := 'N';
          EXIT WHEN :System.last_record = 'TRUE';
          next_record;
      END LOOP;

      Go_block('PCMS_CONTRACT_LINES');

      first_record;
    END IF;
END; 

1 个答案:

答案 0 :(得分:0)

  Go_block('PCMS_CONTRACT_LINES');
  first_record;
在开始循环之前

应该在那里,否则如果你点击第二个记录,第二个记录之后的记录将被选中,循环退出,控件转到第一个记录,但你不选择它

应该是这样的:

DECLARE
    v_selected_contract       VARCHAR2 (50);
    v_selected_contract_ver   NUMBER;
    v_selected_contract_n     VARCHAR2 (50);
    v_selected_contract_ver_n NUMBER;
BEGIN

    IF :PCMS_CONTRACT_LINES.selected = 'Y' THEN -- first current record is checked
       Go_block('PCMS_CONTRACT_LINES');   -- go to the block 
       first_record;  -- first record, then loop and select all.
      v_selected_contract := :PCMS_CONTRACT_LINES.contract_num;
      v_selected_contract_ver := :PCMS_CONTRACT_LINES.contract_version_num;

      WHILE :PCMS_CONTRACT_LINES.contract_num = v_selected_contract
            AND :PCMS_CONTRACT_LINES.contract_version_num =
                v_selected_contract_ver
      LOOP
          :PCMS_CONTRACT_LINES.selected := 'Y';
          EXIT WHEN :System.last_record = 'TRUE';
          next_record;
      END LOOP;
      Go_block('PCMS_CONTRACT_LINES');
      first_record;
    ELSE
      Go_block('PCMS_CONTRACT_LINES');   -- go to the block 
      first_record;  -- first record, then loop and unselect all.
      v_selected_contract_n := :PCMS_CONTRACT_LINES.contract_num;
      v_selected_contract_ver_n := :PCMS_CONTRACT_LINES.contract_version_num;

      WHILE :PCMS_CONTRACT_LINES.contract_num = v_selected_contract_n
            AND :PCMS_CONTRACT_LINES.contract_version_num =
                v_selected_contract_ver_n LOOP
          :PCMS_CONTRACT_LINES.selected := 'N';
          EXIT WHEN :System.last_record = 'TRUE';
          next_record;
      END LOOP;

      Go_block('PCMS_CONTRACT_LINES');

      first_record;
    END IF;
END;