Adsense Ad

Wednesday, 14 February 2018

Oracle Forms: Progress Bar Solution - 5

Scenario to generate progress bar:
either it can be applied for processing time of a transaction/job/query or no. of records,procedures.
to simplify it i have taken no. of records.


Steps: here are the steps and below is the code of all the steps.
1>emp,dept table should be in scott/tiger schema and create emp_dept table to run this example successfully.


2>create a progress_bar package with 3 procedures Initialize_progress_bar,Show_progress_bar,Hide_progress_bar


3>create a form with 2 display item PERCENT and BAR with color you want to see it with and one START button (you can apply on any of the other trigger as well) to see the status bar on click of it.


4>write a when-button-pressed trigger to show and hide progress bar.


Source Codes:
1>CREATE TABLE EMP_DEPT
(  EMPNO     NUMBER(4),
  ENAME     VARCHAR2(10 BYTE),
  DEPTNO    NUMBER(2),
  DNAME VARCHAR2(14 BYTE)  
)
2>for Progress_bar package
PACKAGE progress_bar IS
  ----------------------------------------------- Public Variable
return_item VARCHAR2(32);
bar_id ITEM; -- id of the bar
view_id VIEWPORT ; -- id of the canvas
full_width NUMBER; -- full width before modifying
return_item VARCHAR2(32); -- return item
Initialized BOOLEAN;
--------------------------------------------- Public Procedures
PROCEDURE Initialize_progress_bar ;
PROCEDURE Show_progress_bar (percent IN NUMBER := 0);
PROCEDURE Hide_progress_bar ;
END progress_bar;
----------Package body----------------------- 
PACKAGE BODY progress_bar IS
    PROCEDURE Show_bar (percent IN NUMBER := 0) IS
     bar_width NUMBER;     IT_ID1 ITEM;
    BEGIN
        bar_width := ROUND((progress_bar.full_width)/ 100 * percent,2);
        SET_ITEM_PROPERTY(progress_bar.bar_id,WIDTH, bar_width);
        COPY(RTRIM(TO_CHAR(ROUND(percent,0)) || '%'),'progress_bar.percent');
        SYNCHRONIZE;
       -- IF percent >= 100 THEN -- job completed
         --   progress_bar.Hide_progress_bar;
       -- END IF;
    END Show_bar;

    PROCEDURE Initialize_progress_bar IS
        it_id varchar2(200);IT_ID1 ITEM;
    BEGIN
        IF progress_bar.Initialized THEN
            MESSAGE('A progress bar is already initialized');
            RAISE FORM_TRIGGER_FAILURE;
            ELSIF progress_bar.full_width IS NULL THEN
            progress_bar.bar_id :=FIND_ITEM('progress_bar.bar');
            progress_bar.full_width := TO_NUMBER(GET_ITEM_PROPERTY(progress_bar.bar_id, WIDTH));
            IT_ID1 := Find_Item('progress_bar.bar');
            SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_TRUE);
            IT_ID1 := Find_Item('progress_bar.PERCENT');
            SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_TRUE);
        END IF;
        IF progress_bar.Return_item IS NULL THEN
            it_id := :SYSTEM.TRIGGER_ITEM;
            progress_bar.Return_item :=NAME_IN('SYSTEM.TRIGGER_ITEM');
        END IF;
        progress_bar.Initialized := TRUE;
        Show_bar(0);
    END;

    PROCEDURE Show_progress_bar (percent IN NUMBER := 0) IS
        BEGIN
            IF NOT progress_bar.Initialized THEN
                MESSAGE('No progress bar has been initialized');
                RAISE FORM_TRIGGER_FAILURE;
            END IF;
            Show_bar(percent);
        END ;

    PROCEDURE Hide_progress_bar IS
        IT_ID1 ITEM;
        BEGIN
            IT_ID1 := Find_Item('progress_bar.bar');
            SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_FALSE);
            IT_ID1 := Find_Item('progress_bar.PERCENT');
            SET_ITEM_PROPERTY(it_id1,VISIBLE,PROPERTY_FALSE);            -- SET_ITEM_PROPERTY(progress_bar.bar_id,WIDTH, 0);
            progress_bar.full_width := NULL;
            GO_ITEM(progress_bar.return_item);-- GO_ITEM(:SYSTEM.TRIGGER_ITEM);
            progress_bar.Return_item := NULL;
            progress_bar.Initialized := FALSE;--SET_WINDOW_PROPERTY('PROCESSING_bar',VISIBLE,PROPERTY_FALSE);
        END Hide_progress_bar;
    END;
----------End of Package body----------------------- 
3> Progress_bar datablock on form builder with 2 display item:PERCENT,BAR
                                                                              1 button :START
4>when-button-pressed trigger
DECLARE
CURSOR C1 IS select empno,ename,d.deptno,d.dname from emp e,dept d where d.deptno=e.deptno;
P_PERCENT NUMBER(3):=0;
C_DONE NUMBER:=1;
BEGIN
    select count(*) INTO :GLOBAL.C_TOT from emp e,dept d where d.deptno=e.deptno;
PROGRESS_BAR.INITIALIZE_PROGRESS_BAR;
FOR CL_REC IN C1 LOOP
-- :global.c_totis the total number of records to be processed.
--c_done total number of records processed.
insert into emp_dept(EMPNO,ENAME,DEPTNO,DNAME) values (CL_REC.EMPNO,CL_REC.ENAME,CL_REC.DEPTNO,CL_REC.DNAME);
C_DONE:=C_DONE+1;
P_PERCENT := TRUNC(C_DONE*100/:GLOBAL.C_TOT);
IF P_PERCENT >= 100 THEN
P_PERCENT := 100;
END IF;
--commit;
PROGRESS_BAR.SHOW_PROGRESS_BAR(P_PERCENT);
END LOOP;
message('Process has been completed successfully');
commit_form;
END;

3 comments:

Unknown said...

sir would you pls make any video about all tutorials that you have point out in your wbsite pls

Unknown said...

my level is initials level i could understand with video example

Hasan Jawaid said...

Please follow below mentioned link:
https://hasanjawaid.blogspot.com/2018/03/oracle-forms-how-to-create-progress-bar.html