07ch

download 07ch

of 49

Transcript of 07ch

  • 8/2/2019 07ch

    1/49

    Enhanced Guide to Oracle8i

    Chapter 7:Creating Custom Forms

  • 8/2/2019 07ch

    2/49

    Data Block and Custom Forms Data block form

    Based on data blocks that are associated

    with specific database tables Reflect the structure of the database

    Custom form

    Based on control blocks that process datafrom multiple tables

    Reflect business processes rather than thedatabase structure

  • 8/2/2019 07ch

    3/49

    Creating a Custom Form1. Create the form

    2. Create the form window and canvas

    manually3. Create a control block

    Data block that is not associated with a specifictable

    Contains form items that you manually draw onthe canvas

    4. Create form triggers to process data

  • 8/2/2019 07ch

    4/49

    Form Triggers Code that is associated with a form

    object and an event

    Can contain SQL INSERT, UPDATE,DELETE, and SELECT commands

    Referencing form text item values in

    triggers:

    :block_name.item_name

  • 8/2/2019 07ch

    5/49

    Program Units Self-contained programs

    Can be called from PL/SQL triggers

    Used to make triggers more modular,and reuse code within triggers

  • 8/2/2019 07ch

    6/49

    Referencing System Date and

    Time Values in FormsSystem Variable Return Value

    $$DATE$$ Current operating system date

    $$TIME$$ Current operating system time

    $$DATETIME$$ Current operating system date& time

    $$DBDATE$$ Current DB server date

    $$DBTIME$$ Current DB server time

    $$DBDATETIME$$ Current DB server date & time

  • 8/2/2019 07ch

    7/49

    Using the Forms Debugger

    to Find Runtime Errors1. Run the form using the Run

    Form Debug button2. Set a breakpoint on the program

    line where you want to startexamining variable values duringexecution

    Breakpoint

  • 8/2/2019 07ch

    8/49

    Using the Forms Debugger

    to Find Runtime Errors3. Run the program and execute the trigger

    containing the breakpoint

    4. Single-step through the code and monitor thevariable values

    Execution arrow

    Variablevalues

  • 8/2/2019 07ch

    9/49

    Forms Debugger Variable

    Types Module (block)

    Current values of form items

    Stack

    Values of local variables declared inPL/SQL triggers or program units

    Global Values of global variables used in

    form triggers or program units

  • 8/2/2019 07ch

    10/49

    Strategy for Using the

    Forms Debugger Single-step through the trigger and

    identify the program line causing the

    error Run the form again and single-step

    through the trigger, and note the valuesof variables just before the line

    containing the error executes

    Determine the cause of the error

  • 8/2/2019 07ch

    11/49

    Form Triggers Categories

    Block processing

    Interface event Master-detail processing

    Message handling

    Navigational

    Query time

    Transactional

    Validation

  • 8/2/2019 07ch

    12/49

    Trigger Timing PRE-

    Fires just before associated event occurs

    POST-

    Fires just after associated event occurs

    ON-, WHEN-, KEY-

    Fires immediately, in response to specificuser actions, such as key presses

  • 8/2/2019 07ch

    13/49

    Trigger Scope Defines where an event must occur to make

    the trigger fire

    Trigger scope includes the object to whichthe trigger is attached, as well as all objectswithin that object Form-level: fires when event occurs within any

    block or item in the form

    Block-level: fires when event occurs within anyitem in the form

    Item-level: fires only when event occurs withinthat item

  • 8/2/2019 07ch

    14/49

    Trigger Execution Hierarchy If 2 related objects have the same

    trigger, the higher-level objects trigger

    fires first Form & block, forms trigger fires first

    Block & item, blocks trigger fires first

    You can specify a custom executionorder on the trigger Property Palette

  • 8/2/2019 07ch

    15/49

    Navigational Triggers External navigation: occurs when user

    causes form focus to change

    Internal navigation: occurs as a resultof internal form triggers that fire inresponse to external navigation events

  • 8/2/2019 07ch

    16/49

    User Action Triggers FiredResult on UserScreen Display

    User starts formPRE-FORMPRE-BLOCK

    Form appears,but with no

    data visible

    WHEN-NEW-FORM-INSTANCEWHEN-NEW-BLOCK-INSTANCEWHEN-NEW-RECORD-INSTANCE

    WHEN-NEW-ITEM-INSTANCE

    Form is

    available for use

    Triggers That Fire at

    Form Startup

    12 3

    4 5

  • 8/2/2019 07ch

    17/49

    User Action Triggers Fired Result on UserScreen Display

    User places theinsertion point

    in a text item

    WHEN-NEW-ITEM-INSTANCEInsertion pointappears in item

    WHEN-NEW-RECORD-INSTANCEWHEN-NEW-ITEM-INSTANCE

    Next recordappears

    User clicksthe Next Recordbutton

    Triggers That Fire as a ResultOf External Navigation

  • 8/2/2019 07ch

    18/49

    User Action Triggers FiredResult on UserScreen Display

    User closesthe FormsRuntime window

    Forms Runtimewindow closes

    POST-BLOCKPOST-FORM

    Triggers That Fire When a

    Form Closes

  • 8/2/2019 07ch

    19/49

    Directing External

    Navigation Form tab order

    is based on

    item order inObjectNavigator block

    list Formtaborder

  • 8/2/2019 07ch

    20/49

    Moving to a Specific Form

    ItemGO_ITEM(:block_name_item_name);

  • 8/2/2019 07ch

    21/49

    Oracle Error Message Severity

    Levels 5: informative message

    10: informative message advising user

    of procedural error 20: condition that keeps trigger from

    working correctly

    25 condition that keeps form fromworking correctly

    >25: extreme severity

  • 8/2/2019 07ch

    22/49

    Suppressing Lower Level

    System Messages Set :SYSTEM.MESSAGE_LEVEL variable

    to a higher level in PRE-FORM trigger

    :SYSTEM.MESSAGE_LEVEL := 25;

  • 8/2/2019 07ch

    23/49

    Providing User Feedback

    in Forms Message

    Text in message line at bottom of form

    Informational only; user doesn't have torespond

    Alert

    Dialog box Allows user to choose different ways to proceed

  • 8/2/2019 07ch

    24/49

    Messages

    Message

    Syntax:MESSAGE(message text);

  • 8/2/2019 07ch

    25/49

    Alerts Form-level object

    Object properties define alert

    appearance

    Title

    Styleicon

    Message

    Buttons

  • 8/2/2019 07ch

    26/49

    Code for Displaying an AlertDECLARE

    alert_button NUMBER;

    BEGIN

    alert_button := SHOW_ALERT('alert_name');

    IF alert_button = ALERT_BUTTON1 THEN

    program statements for first button;

    ELSE

    program statements for second button;END IF;

    END;

  • 8/2/2019 07ch

    27/49

    Avoiding User Errors Make primary and foreign key text

    items non-navigable

    When user moves form focus toprimary or foreign key text item,trigger moves focus to alternate

    form item

  • 8/2/2019 07ch

    28/49

    Trapping Runtime Errors Create an ON-ERROR event trigger

    Form-level trigger

    Executes whenever an FRM- or ORA- erroroccurs

    -FRM errors: generated by Forms

    Runtime -ORA errors: generated by database

  • 8/2/2019 07ch

    29/49

    Form Procedures That Return

    System Error Information DBMS_ERROR_CODE: -ORA error code

    DBMS_ERROR_TEXT: -ORA error message

    ERROR_CODE: -FRM error code ERROR_TEXT: -FRM error message

    MESSAGE_CODE: most recent error code

    (eitherORA orFRM) MESSAGE_TEXT: most recent error message

    (eitherORA orFRM)

  • 8/2/2019 07ch

    30/49

    Structure of ON-ERROR

    TriggerBEGIN--trap FRM errors

    IF ERROR_CODE = FRM_error_code1 THEN

    error handler;

    ELSIF ERROR_CODE = FRM_error_code2 THEN

    error handler;

    ELSE

    --trap ORA errors

    IF DBMS_ERROR_CODE = -ORA_error_code1 THEN

    error handler

    ELSIF DBMS_ERROR_CODE = -ORA_error_code2 THEN

    error handler

    END IF

    END IF;

    END;

    Code to

    trapFRMerrors

    Code totrap

    ORAerrors

  • 8/2/2019 07ch

    31/49

    Form Validation Ensures that form data meets preset

    requirements so erroneous data is not sent todatabase

    Validation unit: specifies the largest datachunk that the user can enter enter beforevalidation occurs Can be performed at the form, block, record, or

    item level

    Specified in the Validation Unit property on theform Property Palette

  • 8/2/2019 07ch

    32/49

    Types of Form Validation Data

    Specifies data types, lengths, and maximum and

    minimum values Database

    Specifies which operations a user can perform ona text item

    List of Values Specifies whether a data value must be validated

    against the text items LOV

  • 8/2/2019 07ch

    33/49

    Data Blocks vs. Control Blocks Data block

    Easy to create and use

    Is associated with a single table, and reflects thetables structure

    Control block

    Requires a lot of custom programming

    Can contain items from many different tables

    You can link data and control blocks to takeadvantages of the strengths of each

  • 8/2/2019 07ch

    34/49

    Linking Data Blocks and

    Control Blocks1. Create the control block as the master block

    2. Create the data block as the detail block, but

    do not create a master-detail relationship3. Create a master-detail relationship manually in

    the WHERE Clause property of the detailblock:

    data_block_field := control_block.text_item

  • 8/2/2019 07ch

    35/49

    Displaying and Refreshing the

    Data Block Values Create a trigger to:

    Place the insertion point in the data block

    GO_BLOCK(block_name);

    Flush the data block to make its dataconsistent with the master block and the

    database:EXECUTE_QUERY;

  • 8/2/2019 07ch

    36/49

    Converting a Data Block to a

    Control Block Create a data block and layout that

    contains most of the required text items

    Convert the data block to a controlblock by changing the following blockproperties:

    Database Data Block = No Required = No

  • 8/2/2019 07ch

    37/49

    Creating a Form with Multiple

    Canvases Users should be able to see all canvas

    text items without scrolling

    For complex applications with many textitems, divide application into multiplecanvases

  • 8/2/2019 07ch

    38/49

    Block Navigation Order First block in Object Navigator Data

    Blocks list determines block items that

    first appear when form opens Users can use the Tab key to navigate

    among different block items

    Canvas that contains block itemsautomatically appears

  • 8/2/2019 07ch

    39/49

    Block Navigation Order

    Block order

    Canvas order doesnt matter

  • 8/2/2019 07ch

    40/49

    Controlling Block Navigation Block Navigation Style property

    Same Record: navigation cycles through

    items on same block Change Data Block: navigation moves to

    next data block in list

  • 8/2/2019 07ch

    41/49

    Tab Canvases Multiple-page canvases that allow users

    to move among different canvas

    surfaces by clicking tabs

  • 8/2/2019 07ch

    42/49

    Tab Canvas Components Tab canvas

    Collection of related tab pages

    Tab pages Surfaces that display form items

    Tab labels

    Identifier at top of tab pageA tab canvas lies on top of a content

    canvas

  • 8/2/2019 07ch

    43/49

    Creating a Tab Canvas Use the Tab Canvas tool on the

    Layout Editor tool palette to draw a tab

    canvas on an existing content canvas By default, a new tab canvas has 2 tab

    pages

    Create new tab pages as neededAdjust tab page properties

  • 8/2/2019 07ch

    44/49

    Important Tab Page PropertiesName: how the pageIs referenced in the form

    Label: Caption thatappearson the associated tab

  • 8/2/2019 07ch

    45/49

    Adjusting the Tab Page Order Tab page that appears first is tab page

    whose block items appear first in the

    Object Navigator

    Block order

    Tab page order

    doesnt matter

  • 8/2/2019 07ch

    46/49

    Stacked Canvases Canvas that appears on an existing

    content canvas, and can be

    displayed or hidden as neededAllows user to configure canvas

    items

  • 8/2/2019 07ch

    47/49

    Stacked Canvas Example

    Stackedcanvas

    Content

    canvas

  • 8/2/2019 07ch

    48/49

    Creating a Stacked Canvas Use the Stacked Canvas tool on the

    Layout Editor tool palette to draw a

    stacked canvas on an existing contentcanvas

    Create block items on the stackedcanvas

    Create buttons and triggers to displayand hide the stacked canvas

  • 8/2/2019 07ch

    49/49

    Displaying and Hiding a

    Stacked Canvas Displaying a stacked canvas:GO_BLOCK(stacked_canvas_block);

    SHOW_VIEW(stacked_canvas);

    Hiding a stacked canvas:GO_BLOCK(stacked_canvas_block);

    HIDE_VIEW(stacked_canvas);