Sunteți pe pagina 1din 24

Oracle Forms Builder

Page 1 of 24
Oracle Schema Builder

Generate the following two tables :

Employee

EmployeeNo - Primary Key, Number, required, constraint
<100, > 500 (Between 100 .. 500)
EmployeeTitle - Var Character of length 5, constraint Mr,
Mrs, etc, default value 'Mrs' (In Miss, Ms)
EmployeeName - Var Character of length 30
EmployeeAddress - Var Character of length 30
EmployeeTelephoneNo - Number, optional
Salary - Number, constraint >2000, <5000 (Between )
Birthdate - Date, required

Department

DepartmentNo - Primary Key, Number
DepartmentTitle - Var character length 30
EmployeeNumber - Number


Create relationship between employee number in both
tables

Save table
Oracle Forms Builder
Page 2 of 24

100 Miss Mary
Kelly
Galway 55555 2500 5/1/91
101 Mr John
Smith
Galway 66666 300 15/10/90
103 Mrs Mary
Dow
Tuam 11111 2000 5/5/86




10 Research 100
10 Finance 101
20 Accounts 103


Insert Into Employee Values (100,Miss, Mary Kelly,
Galway, 5555, 2500, 5-Jan-1991);
Oracle Forms Builder
Page 3 of 24
Forms Builder

Record Insert, Action Save

Query Enter, Query Execute

Query Count Hit

Name field: =Mary Kelly - returns all records where Mary
Kelly is the name

Name field: =% S% - returns all records where employee
surname begins with S

Salary field: >=2000 - returns all records where salary is
greater than or equal to 2000

Generate query to return records for all employees living in
Galway or Tuam, :aid=Tuam or :aid=Galway

Query/Where used to enter more complex queries,
:variable, e.g. :tid = Miss and :aid = Galway

Deleting record from table Record Remove

:bind variable, binding to attribute in table

File : Emp1.fmb or EmpForm1.fmb


Oracle Forms Builder
Page 4 of 24
Form designed by creating / editing objects using various
Tools

Layout Editor (F2), Canvas View

Object Navigator (F3) uses icons to indicate object that has
properties

Property Palette (F4)

Canvas visual surface on which items placed

Form can be run within Oracle Forms Designer using Run
Form icon

Forms stored on local machine as .FMB files
(ForM Binary)

Compiled forms stored on local machine as .FMX files
(ForM eXecutable)

Tables stored on remote machine, Galvia
Oracle Forms Builder
Page 5 of 24
Triggers

Block of PL/SQL code to customise application

Trigger attached to specific object and executes in response
to certain event

Triggers associated with form, item, block, etc

80 different triggers in Oracle

Trigger code may include calls to custom PL/SQL code
called Built-Ins, e.g. message, open_form, commit,etc

5 classifications of triggers: Key, On, Post, Pre, When

Possible to utilise Built-In procedures, i.e. code already
written and tested

250 various built-ins:
Forms Builtins
Query Builtins
Record Builtins
Application Builtins
Misc Builtins



Oracle Forms Builder
Page 6 of 24
Record Built-ins

CHECK_RECORD_UNIQUENESS
CLEAR_RECORD
CREATE_QUERIED_RECORD
CREATE_RECORD
DELETE_RECORD
DOWN
DUPLICATE_RECORD
FIRST_RECORD
GENERATE_SEQUENCE_NUMBER
GET_RECORD_PROPERTY
GO_RECORD
INSERT_RECORD
LAST_RECORD
LOCK_RECORD
NEXT_RECORD
NEXT_SET
PREVIOUS_RECORD
SCROLL_DOWN
SCROLL_UP
SELECT_RECORDS
SET_RECORD_PROPERTY

UP
UPDATE_RECORD
Oracle Forms Builder
Page 7 of 24
Add nine buttons to navigate through the records:
First, Last, Prev, Next, Insert, Delete and Close

Change Name and Label in properties window for each
button

Trigger is When-Button-Pressed

Use following built-ins:

Last_Record; Next_Record, Previous_Record,
First_Record, Commit, Close_Form( nameofform),
Enter_Query, Execute_Query


Insert Record code:

declare
commit_alert Number;

begin
commit_alert:= show_alert('Commit');
if commit_alert = alert_button1 then
commit;
end if;
if commit_alert = alert_button2 then
rollback;
end if;
end;
Oracle Forms Builder
Page 8 of 24
Delete Record code:

Declare
Delete_Alert Number;

Begin
Delete_Alert:= Show_Alert('Delete');
If Delete_Alert = Alert_Button1 Then
Delete_Record;
Commit;
End if;
If Delete_Alert = Alert_Button2 Then
Rollback;
End if;
End;

Next Record Code:

Begin
Next_Record;
If :Employeeno = Null Then
message('null data encountered');
message(' ');
Previous_Record;
Else
message('not null');
message(' ');
End If;
End;

Close Form code:
Oracle Forms Builder
Page 9 of 24
Close_Form('**Employee');


Oracle Forms Builder
Page 10 of 24


Oracle Forms Builder
Page 11 of 24
Need to modify the 'Requirement' value for employee number, we set this requirement in
the Schema Builder

Can do this manually by changing the defer_requirement_enforcement property for the
Form OR we can change this requirement property by writing a program that calls the
Set_Form_Property builtin to change the value of some property of a form

Create a When-New-Form-Instance trigger at the Form level

Declare
Form_Id formModule;

Begin

Form_Id := Find_Form(:System.Current_form);
Set_Form_Property(Form_Id, Defer_Required_Enforcement, Property_True);
message(' Welcome to Developer / 2000');
message(' ');

End;
Oracle Forms Builder
Page 12 of 24
Modify the employee form to add a bonus field. If the
employee salary is greater than 3000, the employee gets a
commission of 10% otherwise the employee gets a bonus
of 5%

Post_Change trigger associated with Salary Text Item

Modify
Name property for each new item, (i.e. Bonus, Total)
Database item property = No
Datatype = Number

Display the Salary, Bonus and Total for each record.

Begin
Message('Salary value after changing');

If :Salary > 3000 then
:Bonus := :Salary * 0.10;
Else
:Bonus := :Salary * 0.05;
End If;

:Total := :Salary +:Bonus;

End;


Oracle Forms Builder
Page 13 of 24
Add When-Validate-Item trigger to employee address field
so that only values accepted are Galway, Sligo, Mayo,
Roscommon and Leitrim.

If a wrong value is entered, the employee address field
should turn red

When correct value entered, field will return to white.

Use Set_Item_Property Builtin to modify the
Visual_Attribute property of the Employee Address field

Create an alert called Wrong_Address, set the title,
message, number of buttons, button labels and default
button properties of this alert.

Create 2 new Visual_Attribute objects, one called
White_Back and the other called Red_Back

The White_Back will have the background colour set to
white. The Red_Back will have the background colour set
to red.

Add exception code so that record will not be committed to
database until the correct value in entered into the
employee address field

Oracle Forms Builder
Page 15 of 24
Declare
Item_Id Item;
Alert_Button Number;

Begin
Item_Id:=Find_Item('Employeeaddress');
If Id_Null(Item_Id) Then
message('Item not found');
End If;

If lower(:Employeeaddress) not in ('galway','mayo','sligo', 'roscommon', 'leitrim') Then
Alert_Button := Show_Alert('Wrong_Address');
Set_Item_Property(Item_Id, Visual_Attribute,'Red_Back');
Raise Form_Trigger_Failure;
Else
Set_Item_Property(Item_Id, Visual_Attribute,'White_Back');
End If;
End;

Oracle Forms Builder
Page 16 of 24
Add a command button to the canvas:
Name = Hide_Btn,
Label = Hide

Add another command button to the canvas:
Name = Other_Btn,
Label = Other

Create a When-Button-Pressed trigger associated with the
Hide button.


Set_Item_Property('Other_Btn', Visible, Property_False);
Set_Item_Property(Last_Btn', Label, 'Final');
Oracle Forms Builder
Page 17 of 24
Open the Employee Form

Add a new text item (name = Relocation) and new prompt
(= Relocation)

Set the Calculation Mode for this text item = Formula, in
the Formula field enter

:Total*1.1

Go to the Data - > Data Type, make sure it is Number

Get help on Format Mask Field - F1

Go to the Data - > Format Mask and set it to "e"9,999.99

Notice format for output values

Go to Birthdate text item

Go to the Data - > Format Mask and set it to
DY DD-MONTH-YYYY BC


Oracle Forms Builder
Page 18 of 24
Master Detail Relationship

Using the datablock wizard, create data block for Employee
table

In the object Navigator, highlight the data block item and
select new will create another Data Block

Create a second datablock using the Department table,
display all fields

Notice extra tab on Data Block Wizard

On Master-detail window, select Create Relationship

Uncheck AUTO-JOIN check box

Foreign key relationship should automatically get
displayed.

Run form, place cursor in employee no field and run a
query

Include Go_Block built-in as part of When-New-Form-
Instance in order to place the cursor in the top block.
Oracle Forms Builder
Page 19 of 24
Notice Relations Item created under Datablocks

Look at Delete Record Behavior property

Non-Isolated: Default setting. Prevents deletion of a
master record when associated detail records exist in
database.
Isolated: Allows master record to be deleted and does
not affect associated detail records in database.
Cascading: Allows master record to be deleted and
automatically deletes any associated detail records in
detail block's base table at commit time.

Include scroll bar on employee layout that will display 5
records at a time.

Run form, place cursor in dept no field and run a query

Include GO_BLOCK built-in as part of When-New-Form-
Instance in order to place the cursor in the top block.

Oracle Forms Builder
Page 20 of 24
Create a WHEN NEW FORM INSTANCE trigger for the
form

Each form runs / executes using same Master Document
Interface (MDI)

Concept of individual forms and MDI (common) form

Possible to set title of MDI and individual forms by setting
properties directly or by writing a PL/SQL program!!

Set the CASE INSENSITIVE PROPERTY for each data
item that may be queried

Oracle Forms Builder
Page 21 of 24
Declare
Fm_Id FormModule;

Begin
Fm_Id :=Find_Form(:System.Current_Form);
Set_Form_Property(Fm_Id,Defer_Required_Enforcement,
Property_True);
Set_Window_Property(Forms_Mdi_Window,Window_State,Maximize);
Set_Window_Property(Forms_Mdi_Window,Title,'MDI Title' );
Set_Window_Property('Window1', Window_State, Maximize);
Set_Window_Property('Window1', Title, 'Form Title');

End;
Oracle Forms Builder
Page 22 of 24
Possible to generate primary key value automatically

Use Sequence database object created by user, possible
for multiple users to share access to sequence

Sequences stored and generated independently of tables

SQL> Create sequence name Increment by n
Start with n Minvalue n Maxvalue n ;

Notice no , between parameters

SQL> Select Sequence_Name, Min_Value, Last_Number
From User_Sequences;

SQL> Alter Sequence name increment by 10;

NextVal, CurrVal

SQL> Select name.NEXTVAL From Dual;

SQL> Select name.CURRVAL From Dual;

SQL> Insert into EMP values (name.Nextval, xxx..);

SQL> Drop Sequence name;

Initial Value for Employee No property set =>
:Sequence.my_seq.Nextval
Oracle Forms Builder
Page 23 of 24
Creating Menu

File -> New -> Menu

Set name property = Menu

Tools -> Menu Editor



Oracle Forms Builder
Page 24 of 24

S-ar putea să vă placă și