# Oracle Forms DataBlock Interaction



## Mavyak (Jul 8, 2003)

I have a tri-level Master-Detail Form. Data block ORDERS is the master for data block ORDER_DETAILS. ORDER_DETAILS is the master block for data block ORDER_DETAILS_TOPPINGS. I'm creating a RDBMS for a mock pizza company. The only time the table ORDER_DETAILS_TOPPINGS is used is in the event a pizza gets ordered. I would like to create a POST-CHANGE trigger attached to the PROD_ID attribute of the ORDER_DETAILS datablock that will change all the visible properties in the ORDER_DETAILS_TOPPINGS data block to "no" in the event the the PROD_ID is not a 5 (a PROD_ID of 5 equates to a pizza). There's no sense in the user having access to the portion of the form containing toppings information if they are ordering a soda. A copy of my ERD can be found here . (Warning: that link is not 56k friendly).

Thanks,

Mav


----------



## HKOldGuy (Jul 13, 2003)

I suppose you have many blocks in your forms. Two of thems are
B_ORDER_DETAILS and B_ORDER_DETAILS_TOPPINGS. And that they and a master-detail relationship. In the POST-CHANGE tirgger of item PROD_ID in block B_ORDER_DETAILS should include the codes similar to the followings:
DECLARE
v_item_name varchar2 (100);
v_last_item varchar2 (100);
BEGIN	
v_last_item := GET_BLOCK_PROPERTY( 'B_ORDER_DETAIL_TOPPINGS', LAST_ITEM);
v_item_name := GET_BLOCK_PROPERTY ('B_ORDER_DETAIL_TOPPINGS', FIRST_ITEM);
IF :B_ORDER_DETAILS.PROD_ID = 5 THEN
LOOP
SET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, ENABLED, PROPERTY_TRUE);
IF v_item_name = v_last_item THEN
EXIT;
END IF;
v_item_name := GET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, NEXTITEM);
END LOOP;
ELSE
LOOP
SET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, ENABLED, PROPERTY_FALSE);
IF v_item_name = v_last_item THEN
EXIT;
END IF;
v_item_name := GET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, NEXTITEM);
END LOOP;
END IF;
END; 

Hope this can help!


----------



## Mavyak (Jul 8, 2003)

Thanks OldGuy. I'll be working on that application more tomorrow (today, it's after midnight) and throughout the next two weeks. I did, however, discover a syntax error on my part that was probably the cause of my problem. In the following line:

SET_RADIO_BUTTON_PROPERTY('BLOCK.RADIO_GROUP','RADIO_BUTTON', PROPERTY_NAME, PROPERTY_VALUE);

I was prefacing the BLOCK.RADIO_GROUP with a ":". I tried it without the colon and I was able to control the item properties from a different block. However, I will more than likely use your code (modified a bit) because it includes the looping so i won't have to copy and paste the code for every item in my block (approx. 35). So a great big thank-you to you and I'll try to remember to update this topic with my results.

Mav:up:

BTW: I once took the Star Ferry to the mainland (Kowloon) and got all liquored up at a place called Casablanca and argued with a submariner for two hours once. Good Times! LOL! I love Hong Kong!


----------



## HKOldGuy (Jul 13, 2003)

The codes I posted on 8-Jul-2003 did not cater for RADIO BUTTON and PUSH BUTTON. It needs modification before it can use in business project. The following 2 paragraph of codings which I am currently using are for your reference. 
Note that the program unit LP_ENABLE should better stored in a separate library because it is very useful and may be used by other programs.

POST-CHANGE trigger :
DECLARE
v_item_name varchar2 (100);
v_last_item varchar2 (100);
BEGIN 
v_last_item := GET_BLOCK_PROPERTY( 'B_ORDER_DETAIL_TOPPINGS', LAST_ITEM);
v_item_name := GET_BLOCK_PROPERTY ('B_ORDER_DETAIL_TOPPINGS', FIRST_ITEM);
IF :B_ORDER_DETAILS.PROD_ID = 5 THEN
LOOP
LP_ENABLE ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, TRUE);
IF v_item_name = v_last_item THEN
EXIT;
END IF;
v_item_name := GET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, NEXTITEM);
END LOOP;
ELSE
LOOP
LP_ENABLE ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, FALSE);
IF v_item_name = v_last_item THEN
EXIT;
END IF;
v_item_name := GET_ITEM_PROPERTY ('B_ORDER_DETAIL_TOPPINGS.' || v_item_name, NEXTITEM);
END LOOP;
END IF;
END; 
=======================
PROCEDURE LP_ENABLE (piv_item varchar2, piv_enable boolean) IS
BEGIN

if get_item_property (piv_item, ITEM_TYPE) in ('BUTTON', 'RADIO GROUP') then
if piv_enable = TRUE then	
set_item_property (piv_item, ENABLED, PROPERTY_TRUE);
if get_item_property (piv_item, ITEM_TYPE) = 'RADIO GROUP' then
set_item_property (piv_item, UPDATE_ALLOWED, PROPERTY_TRUE); 
end if;
else
set_item_property (piv_item, ENABLED, PROPERTY_FALSE); 
end if;
else
if piv_enable = TRUE then	
set_item_property (piv_item, ENABLED, PROPERTY_TRUE);
else
set_item_property (piv_item, ENABLED, PROPERTY_FALSE);

end if;
end if; 

END;


----------

