Download dev_tut

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Clusterpoint wikipedia , lookup

SQL wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

PL/SQL wikipedia , lookup

Database model wikipedia , lookup

Transcript

Developer/ 2000:
The aim of this course is to introduce the concepts and techniques of forms, and to learn how
to build both single and multiple form applications, using database and graphical user interface
(GUI) features.

Form:
- Forms are a major component of developer/2000. Forms enable you to quickly develop
form-based applications for presenting and manipulating data in a variety of ways.
-
Forms applications let your users:
 Insert, update, and query data.
 Present data using text, images, and VBX controls.
 Control forms across several windows and database transactions.
 Access comprehensive facilities using integrated menus.
 Send data directly to reports.
-
Forms modules: Forms application may comprise many modules (files) of the
following three types:
 Form: A form presents the objects and data that users can see and interact with.
Data items in a form are arranged into records.
 Menu: A menu module may comprise a hierarchy of menus, each with selectable
items for the user to choose.
 Library: A collection of PL/SQL program units.
-
Product components: Forms include three components that you can access as the
designer of an application:
 Forms designer.
 Forms generate.
 Forms runform.

There are many types of objects that you can create in a form module:
Object
Block
Item
Description
Logical owner of items. Owned by the form module
Member of a block. Object to represent data values to
the user or let the user interact with the form.
Items are logically grouped into blocks and Items are
visibly arranged on canvas.
Canvas (page)
The surface where visual objects are arranged.
Form can have several canvases in the same window or
can assign separate windows
Procedures, functions, or package
A program unit that is executed due to an event or is (a
PL/SQL block executed due to an event)
Includes Alerts, Parameters, and Record Groups.
Program unit
Trigger
Other objects
Note:
1- When you create a form then you have two files:
 .fmb (binary)
in design time.
 .fmx (executable) in runtime.
2- Minimum requirements:
1 item
1 block
1canvas
1 window
3- Block = canvas & Item = canvas
Window
Canvas
Block
Item
1. Create a form:
a) You can create the form using one of the following:
 Build your form manually, object navigator =>file =>new or
 Using the form wizard, including number of records, which type of the form you
want, etc.
b) Set the form module properties.
2.
Creating block:
a) Database block:
a. Click the object navigator entry block.
(Hint: you can also use the wizard for creating the data block).
b. Click the create icon in the object navigator.
c. Create a new single-block form module.
d. Base it on emp table and include all columns.
e. Show just one record at a time (see the block properties).
f. Use a form layout and vertical orientation (hint: you can also do this from your
block properties).
g. Run your form.
b) Running your form:
a. On the object navigator, File => Compile.
b. Run your form from the toolbar click on run.
c. Retrieving data (unrestricted query)=> press execute query.
d. Retrieving data (restricted query)=> can use matching values, matching patterns
(wildcards).
a. Select query=>enter.
b. Enter the following:
:item =11 or :item between 100 and 200
c. Press execute query.

Database block:
- Create a form based on EMP table.
- Retrieve all fields.
- Let it be Form layout.
- Display one record, and display scrollbar.

Running your form:
a) Run your form from the toolbar, click on Run.
b) Retrieving data (unrestricted query)=> press Execute Query.
c) Insert new, update, and delete employees.
d) Retrieving data (restricted query)=> you can use matching values, matching patterns
(wildcards)
e) Select from Menu => Query =>Enter.
f) Enter 7369 in the employee’s text box, press F8 to execute the query.
g) The employee’s data is displayed.

Layout editor: Graphical design facility for creating and arranging interface items in a form.

Property Palette:
- Used to modify the properties of any object.
- To display the property palette:
b) Select the object, Menu => Tools => Property palette.
c) Double-click the object icon. (Except the canvases).
d) Double-click the item in the layout editor.
e) Select the object node and click the right mouse button.

Triggers:
-
A trigger is a program unit that is executed due to an event.
Trigger characteristics:
- Trigger Type: PRE, POST, WHEN, ON, KEY
- Trigger Code: PL/SQL.
- Trigger Scope: item level, form level, and block level.
Item level:
- A Trigger fires when this item is the current item.
- In the layout editor, create a button, right click, and choose Smart Triggers =>
‘When_button_pressed’.
- From the property palette, specify the property mouse navigable to NO.
- Edit PL/SQL:
1- Begin
2- Begin
Next_record;
Previous_record;
End;
End;
3- Begin
First_record;
End;
5- Begin
Commit;
End;
-
4- Begin
Last_record;
End;
Compile and close.

Buttons:
- In the property palette of a button:
a) The text label that appears on the button at runtime.
b) Default button: determines whether this is the default button for the block.
c) Iconic: determines whether the button displays an icon instead of a label.
d) Icon filename: identifies the name of the file that contains the icon resource
(DON’T mention the icon file extension here).
- Tool tip: short help text that displays info about item when you navigate to it with the
mouse.

Item Types:
1. Check Box:
a) In the layout editor, select the comm. item, enter property palette.
b) Change item type into Check Box.
c) Enter a check box label (it appears to the right of the check box).
d) Set value when checked => 1 and value when unchecked => 0. This means that the
value of the commission is known in advance, but we need to know if this employee
had a commission or not.
e) Set check box mapping of other values to Not Allowed (this determines how data
values other than specified are processed, not allowed property makes the form ignore
the entire record during the query processing).
f) Set initial value => 0.
2. Combo Box:
a) In the layout editor, select the job item, enter property palette.
b) Change item type property into List item.
c) Set List style => combo box.
d) Select Elements in List => click more => Enter the elements you want to appear in the
list and enter their values in the list item value field.
e) Ex. Manager => M, Programmer => P, and Analyst => A.
f) Leave the mapping of other values property blank, this will ignore any other data
values.
g) Set initial value => M.
h) Note: Null values are displayed as a blank element in combo box style.
i) Note: This combo box with this method is a Static combo box; it doesn’t retrieve
values from the database.
3. Radio Group:
a) A radio group is a set of radio buttons, each represents a different value. These values
are mutually exclusive.
b) In the layout editor, select the gender item, enter property palette.
c) Change item type property into radio group.
d) Leaving the radio group’s mapping of other values property blank makes the form
ignore the entire row during query processing. You may associate it with one of the
existing radio buttons by writing F or M.
e) In the object navigator, expand the gender node => radio buttons node => click the
create icon, and create two radio buttons.
f) Enter the property palette of the radio button, change label into Female.
g) Set radio button value => F.
h) The same: label => Male, radio button value => M.
i) Enter the property palette of the radio group, that is, the gender item itself.
j) Set initial value => F.

List Of Values (LOV):
- A window that allows the user to pick an item value from a multi value dynamic list.
- Select the LOVs node in the object navigator, click create icon ‘+’.
- In the New LOV dialog, choose to build a new LOV using wizard.
- Choose ‘New record group based on a query’. A record group is an object used to store
the array of values that are represented by LOV.
- Click ‘Build SQL query’, Choose EMP table, press include then close.
- Select the fields you want to include in LOV (if all, double click title bar).
- The query is displayed. The order of columns in the select statement is the order in which
they will appear the LOV.
- Hint: You can define return items in the Select statement using INTO clause.
- Move all record group columns into LOV columns.(don’t mention)
- You can change the title of columns; return values by pressing ‘Look up return items’, it
displays columns of EMP table, choose EMP.deptno.
- Change the LOV title into Department Info.
- Set Numbers of rows to be retrieved to 5, click Finish.
- If you didn’t look up the return items in the wizard, enter the LOV property palette =>
column mapping properties => Select item => press Browse => Select the return item
EMP.deptno. (don’t mention)
-

If you want the LOV to be automatically displayed, enter the LOV property palette =>
Automatic display => Yes.
To display the LOV in runtime, select item associated with the LOV, Menu => Edit =>
Display list OR press F9.
Two objects are created: record group & LOV (with the same name).
More than one LOV can be based on the same record group.
To view the select statement, choose record group, open the property palette, and examine
the record group query property.
Create a button to show LOV:
- Create button, right click, and choose smart triggers => ‘When_ button_ pressed’ => Edit
PL/SQL:
Declare
Press Boolean;
Begin
Press: = Show_Lov (‘LOV name’);
End;
-

Run Form, press button, the LOV will be shown.
Data Blocks with relationships:
- A form module can contain one or more data blocks; each can be standalone or related to
another data block.
- Master-Detail relationship equates to the one-to-many relationship. The master data
block is based on the P.K table, while the detail data block is based on the F.K table.
-
To create a Master-Detail form:
b) You can repeat the same steps as described previously for your master block
department, based on DEPT table.
c) Create the detail block called employees, based on EMP table.
d) Don’t include the image field in the emp data block.
e) Select the ‘auto-join data blocks’ check box and click Create Relationship.
f) Select the same canvas as the master data block.
g) Display four records in the detail block.
h) Use a tabular layout and include a scrollbar.
i) Before running the form, in the object navigator, switch between the two data
blocks to let the dept data block is the first to let focus be on it for correct execute
query.
-
Note: The master data block must exist in the form module before creating a detail block.
A relation object is automatically created under the master data block; the relation is given
the default name MasterDataBlock_DetailDataBlock.
Running a Master-Detail Form Module:
b) Querying the master data block retrieves the corresponding detail records.
-
c) Deleting a master record is prevented if detail records exist.
d) Inserting a detail record automatically associates it with the displayed master record.

Item Types (continued):
 Calculated Fields:
- They are read only.
- Calculation modes:
a) Formula: the calculated field is result of a horizontal calculation involving one or
more variables (form items, global variables and parameters).
-
b) Summary: the calculated field is a result of a vertical calculation involving the
values of a single item over all the rows within a single block.
We can use an existing item and set its calculation properties in the property palette or
create a new item in the layout editor.
A. Creating an item based on a formula:
1. In the layout editor, create a new text item, in the property palette:
2. Set the calculation mode property to Formula.
3. Set the Database Item property to NO.
4. In the Formula property, click more and enter the PL/SQL expression.
Rules:
5. The formula must not execute any DML statements.
6. Do not terminate the PL/SQL expression with a semi-colon.
7. If the PL/SQL expression involves an assignment, do not enter it.
8. Set the formula property to:
9. NVL (:emp.sal, 0) * NVL (:emp.comm, 0), the form builder generates:
: Emp.gross := (NVL (:emp.sal, 0) * NVL(:emp.comm, 0));
10. Run the form.
B. Creating an item based on a summary:
1. Set the calculation mode to Summary.
2. Set Data item property to Number.
3. Select the required function ‘MAX’ from the summary function pop-up list.
4. From the Summarized block property pop-up list, select the block over which all
rows will be summarized ‘EMP’.
5. From the Summarized item property pop-up list, select the item to be summarized
‘SAL’.
6. Set Insert allowed property and Update allowed property to No.
7. Set initial value to 0.
8. Set the query all records property or the precompute summaries property of the
EMP block to yes.
Rules:
9. The summary item must reside in the same block as the summarized item.
10. Set data type to number, unless the summary function is max or min, in which case,
the data type must mirror that of associated summarized item.
11. The summarized item must reside in a block whose query all records property or
the precompute summaries property is set to yes.

Image:
a) First modify the employee table to include a field for the employees pictures, this could
be done by the following code:
alter table emp
add picture long raw;
b) Build a form based on the employee table.
c) Add a button into the form with the following code:
declare
v_dirname varchar2(255);
v_filename varchar2(255);
begin
v_dirname:='c:\';
v_filename := get_file_name( v_dirname, NULL, 'Bitmap files (*.bmp)|*.bmp|');
if v_filename is not null then
read_image_file(v_filename,'ANY', 'emp.picture');
end if;
end;

Triggers:
- A trigger is a program unit that is executed due to an event.
- Trigger Scope: item level, form level, and block level as mentioned the last week.
1. Form level:
- A Trigger fires due to events across the entire form.
- Select Triggers node under the form node, right click, and choose ‘WHEN-NEWFORM-INSTANCE’.
- Edit PL/SQL: execute_query;
- Compile, close and run the form.
- Select Triggers node under form node, right click, and choose ‘WHEN-NEWFORM-INSTANCE’
- Add: set_window_property ('window_name',window_state,maximize);
- set_window_property ('WINDOW1',TITLE,'My form');
- set_window_property (FORMS_MDI_WINDOW,window_state,maximize);
- For MDI parent window (the one with the title bar).
- Compile, close and run the form.
2.

Block level:
A Trigger fires when this block is the current block.
Select triggers node under data block node, right click, and choose ‘PRE_BLOCK’.
Edit PL/SQL: message (‘hi’); (it’s displayed in the status bar).
Write Message (‘hi’) twice to make it appear in a dialog to the user.
Compile and close.
Alerts:
- Select the Alerts node in the object navigator, click create icon.
- In the property palette of alert, write the message ‘INVALID DATE’ in the message
property.
- Set alert style to Stop.
- In button1 label => Ok, button2 label => Cancel.

Set the default alert button to Button1.
Validations:
- Select the hiredate item, right click, select Smart Triggers => WHEN-VALIDATE-ITEM
=> Edit PL/SQL:
Declare
Button number;
Begin
If :hiredate < '01-jan-1950' then
Button: = show_alert ('alertname');
/*
If button = 88 then
Message (‘you pressed the first button’);
Elsif button = 89 then
Message (‘you pressed the second button ');
Elsif button= 90 then
Message (‘you pressed the third button’); */ (if there is a
third button.)
End if;
End if;
End;
-
Run the form, try to insert a new employee with hiredate 01-jan-1900.
The message appears, but I can still move across items and the record may be saved.
Add the following statement in the If statement after the first message if button = 88:
Raise form_trigger_failure;
Run the form and press the first button.
Difference: The message appears, but I cannot move out of the item unless I enter a
valid value or close the form.

Kinds of blocks:
- Database blocks: It is based on an existing table, as explained before.
- Control blocks: A block that is not associated with any database. It is created for items
that need a navigator cycle, or buttons.

Navigation Methods:
1. Control block:
1. Create a form for the employees’ data.
2. Run the form to generate the .fmx file of the form.
3. Save the form and identify its path.
4. In the object navigator, click Forms.
5. Create a new form using create icon ‘+’.
6. Choose Data blocks node, create using create icon.
7. In the New Data Block dialog, choose to build a new block manually.
8. Create a new canvas using create icon, double click on your canvas icon.
9. On the block used => property palette => specify that you are using the control block
by choosing Database data block: No
10. In the layout editor (design), choose a button from the tool palette, and place it on the
canvas.
11. From the property palette, specify the property mouse navigable to NO.
12. Right click on the button, and choose Smart Triggers => ‘When_button_pressed’.
13. Edit PL/SQL:
Open_form (‘form_path\form_name.fmx’);
14. Note: Open_form command opens the form with the default menu.
15. Note: call_form command keeps the attached menu, if not the standard menu. If there
is no attached menu, both commands will be similar.
16. Run the navigation form.
2. Menu:
1. In the object navigator, create a new Menu Module using create icon ‘+’ or by doubleclicking.
2. Inside the menu module, create a new menu using create icon ‘+’ or by doubleclicking.
3. Double-click on the menu object and create two down new items and one right new
item as follows:
4. Right click on each item in the menu. Inside the PL/SQL editor:
open_form (‘form_path\form_name.fmx’);
5. To compile the menu, click on the menu module in the object navigator, and choose
from the File menu  Administration  Compile File.
6. If compiled successfully, a message ‘Module built successfully’ appears.
7. Save the menu module.
8. To attach the menu to a form, open the property palette of the navigation form.
9. In the Menu Module property, add path\menu_name.mmx.
10. Run the navigation form.