tutorials3

9
Tutorial for Oracle10g Forms/Reports Lesson 3 In this lesson, you will learn how to: Create Alerts (a modal window) on a push button that will function as a warning or a message to the users when they click the button. Create Procedures which are stored blocks of code which can be called from multiple objects saving the time taken for retyping codes Creating an Alert 1. Go to Alerts in the Object Navigator and double click on it. 2. Double click on the newly created alert and name it DELETE_ALERT.

Upload: raja-umair

Post on 27-Dec-2014

279 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Tutorials3

Tutorial for Oracle10g Forms/Reports

Lesson 3

In this lesson, you will learn how to:

Create Alerts (a modal window) on a push button that will function as a warning or a message to the users when they click the button.

Create Procedures which are stored blocks of code which can be called from multiple objects saving the time taken for retyping codes

Creating an Alert

1. Go to Alerts in the Object Navigator and double click on it. 2. Double click on the newly created alert and name it DELETE_ALERT.

Page 2: Tutorials3

3. Now double click on the alert and you will immediately go to its Property Palette. In the properties:

Change the title of the alert to Delete Alert, and Name to Delele_Alert.

Type in the message as "Are you sure you want to Delete?"

Select Stop as the Alert style

You can add a third button to the alert or just keep the OK and Cancel

Page 3: Tutorials3

Make sure that Button1 is selected as the default button

4. To activate the alert, we will create a procedure which we will call from the delete button. To add a procedure, go to the Object Navigator and double click on Program Units. Immediately the window for the new Program unit will appear.

Page 4: Tutorials3

5. In the window for the new Program Unit, type in the name as Display_Delete-Alert. Make sure that procedure is selected as the type of Program Unit and click OK.

6. Once you click OK, you will be automatically taken to the PL/SQL Editor window.

Page 5: Tutorials3

7. In the PL/SQL Editor, type in the following code for activating the alert. You may have to delete a couple of lines from the Editor to avoid duplication. In this code, we will declare a number variable called return_alert. We will then set it to show the alert that we created earlier in this lesson called Delete_Alert. We will then write a simple if/then statement, such that if the user clicks on OK, which is alert button 1, then 10g Forms/Reports will perform the deletion and commit the changes. Otherwise, it will exit the alert window and help the users decide on their action. (See the following to get a view of the code as it should look in the PL/SQL editor. Do not forget to compile.)

Page 6: Tutorials3

8. We will now add a push button to the form and then add the above procedure to it, so that whenever the user clicks on delete, the alert will be shown. To do this, go the Layout Editor by double-clicking Canvas icon and add a push button to the form, go its properties, and change the label to Delete (use the steps used to create a push button in Lesson 2). Now go to its PL/SQL Editor by right clicking on the push button.

Page 7: Tutorials3

9. At the When-Button-Pressed trigger in the PL/SQL Editor, write the following code:

delete from student where studid = :student.studid;delete_record;Display_Delete_Alert;

10. The last line of the code will call the previously created procedure Display_Delete_Alert and activate the alert whenever the user clicks on the delete button. The first two lines of code delete the record for any particular student ID.

11. Then click Run Form.

Page 8: Tutorials3

Lesson Summary

In this lesson you have learned how to:

Create alerts on push buttons (delete) so that when the user clicks on the button the alert is shown as a warning

Create procedures or stored blocks of code that can be called from any object

Page 9: Tutorials3

Next you will learn how to create reports. To do this, proceed to Lesson 4