Guião para criar aplicações simples em APEX (parte I...

23
Guião para criar aplicações simples em APEX (parte I) Guide to create simple Apex applications (part I) O guião que se segue usará uma base de dados que decorre do seguinte DER: The following script will use a database from the following DER: Ao qual correpondem as seguintes tabelas: Corresponding to the following tables:

Transcript of Guião para criar aplicações simples em APEX (parte I...

Guião para criar aplicações simples em APEX (parte I)

Guide to create simple Apex applications (part I)

O guião que se segue usará uma base de dados que decorre do seguinte DER:

The following script will use a database from the following DER:

Ao qual correpondem as seguintes tabelas:

Corresponding to the following tables:

Socio=(num_socio, nome_socio, bi_socio,data_nsc_socio, morada_socio, tlf_socio, sexo_socio) Genero=(cod_genero, nome_genero) Editora=(cod_editora, nome_editora) Actor=(cod_actor, nome_actor) Realizador=(cod_realizador, nome_realizador) Filme=(cod_filme, nome_filme, ano_filme, preço_dia_filme, dias_sem_multa_filme, multa_dia_filme, cod_genero, cod_editora) Filme_actor=(cod_filme,cod_actor) Filme_realizador=(cod_filme,cod_realizador) Copia=(cod_filme,num_copia) Aluguer=(cod_filme,num_copia,data_aluguer, num_socio, data_prev_dev_aluguer) Devolucao=(cod_filme, num_copia, data_aluguer, num_socio, data_devolucao, estado_devolucao)

Estão também disponíveis sequências que foram criadas com os seguintes comandos SQL:

Also available are sequences that were created with the following SQL

commands:

create sequence seq_socio increment by 1 start with 1; create sequence seq_genero increment by 1 start with 1; create sequence seq_editora increment by 1 start with 1; create sequence seq_filme increment by 1 start with 1; create sequence seq_actor increment by 1 start with 1; create sequence seq_realizador increment by 1 start with 1;

So, enter you workspace, user and password in the oracle apex site and ater creating the tabels

bove, in Sqlworkshop environment, click on App Builder and you will see:

Uma aplicação Apex assenta numa coleção de páginas ligadas usando tabs, buttons e links hypertext.

An Apex application lies on a collection of linked pages using tabs, buttons and hypertext links.

Clique em Create / Click on Create.

Escolha / choose New Application

Give a name to your application (here is VideoClube). A blank (Home) page will be created to be a menu. Click Add Page.

Selecione Report / select Report

Basicamente, uma página do tipo Report serve para mostrar conteúdos de tabelas, views ou resultados de queries; nesta página não é permitido alterar dados da base de dados.

Basically, a Report page is used to display table contents, views, or query results; on this page it is not allowed to change data from the database.

Now give a name to the report (Editora), chhose interactive Report, choose table editora and click add page.

Then click Create Application.

Now click run application

Enter user and password

Clike on the blue square

and you will see the table content. You may now click on actions and filter to obtain answers to specific queries, for ex:

Which will give the following result

Criação de um report sobre junção de tabelas

Building a report on a join of tables.

Clique em Application nnn e Create page/ Click on Application nnn and Create page

Now choose Report

and then choose Inteactive Report

Now give a name (Filme) to the page. Choose table Filme and choose breadcrumb to indicate that you want to connect to other pages from this one. Then connect to page Home and Click Next.

Then include all attributes of the table to be viewed in the report, like the next picture

After cliking Next, you will see

Then run the page by ckicking the blue arrow.

You can hide the cod Filme attribute you you want.For that, click on Action, move that attribute to the left, and click Apply like this;

Assim, este é o resultado do SQL interno que é guiado pelo conjunto de atributos na tabela Filme. Para além dos outros atributos, são mostrados os códigos de editora e de género, que são valores núméricos que não permitem uma leitura digamos “natural e imediata” como a que se conseguiria se em vez deles, estivessem os nomes da editora e do género, respetivamente. Em face desta

contingência, vamos contornar o problema. Clique em Edit Page n (o número desta última página).

Thus, this is the result of the internal SQL that is guided by the set of attributes in table

Filme, which shows in addition to the other attributes, the editora and género codes, which

are numeric values that do not allow a reading to say "natural and immediate" as that would

be obtained if the names of the editora and the género were present, instead of the codes.

In face of this contingency, we will work around the problem. Click Edit Page n (the number

of this last page)

Agora, na zona Content Body, clique em Filme e verá à direita o código SQL (na zona source, Sql query) que gerou a leitura do conteúdo da tabela Filme. Para aceder a uma janela de edição, clique no quadrado indicado pela seta vermelha.

Now, in the zone Content Body, click on Filme and you will see the SQL code (next to the

source zone, Sql query) that showed the table Filme content. To acess to an edition

window, click on the square pointed by the red arrow.

And then

Agora substitua aquele código SQL pelo seguinte, cuja alteração usa no report do Filme os nomes da editora e do género em vez dos respetivos códigos que são de leitura, à partida, não entendível.

Now replace that SQL code with the following, which uses in the Filme report, the names

of the editora and the género instead of their codes that are not easily readable.

select nome_filme as nome,ano_filme as ano,preco_dia_filme as "preco

dia",dias_sem_multa_filme as "dias sem multa",multa_dia_filme as "multa

dia",nome_genero as genero,nome_editora as editorafrom filme natural inner join editora

natural inner join genero

Quando não hover erros, corra a página para ver este resultado onde os códigos e os nomes dos

atritutos foram visualmente “substituídos” por forma a permitir uma compreensão plena.

When there are no errors, run the page to see this result where the codes and names of the

attributes have been visually “replaced” in order to allow a full understanding.

Criar uma página Form para inserir e modificar dados Create

a Form page to insert and modify data

Clicar em Application nnn e Create Page / Click Application nnn and Create Page

Click on Form

Escolha Report with Form on Table / choose Report with Form on Table

Dê nomes ao Report e ao Form, e dê indicação de que quer que haja uma entrada no menú em Home para estas páginas, como indicado acima

Name the Report and the Form, and indicate that you want an entry in the Home menu for

these pages, as indicated above.

And

Na janela seguinte escolha a tabela sobre a qual vai incidir este Report; neste caso é socio. Depois clique em Next.

In the next window choose the table on which this report will focus; in this case it is socio.

Then click Next.

Agora, tal como se mostra no quadro seguinte, escolha “select Primary Key Columns”, carregue

em >> para incluir no forms todas os atributos da tabela, aceite NUM_SOCIO como chave e

escolha “Existing sequence” como forma de gerar um novo número para cada futuro novo tuplo

na tabela socio. Depois faça Create.

Now, as it is shown next, choose "select Primary Key Columns", click on >> to include all

attributes of the table in the form, accept NUM_SOCIO as the key. Then click Create.

De seguida, é preciso tornar o attributo num_socio visível ja´que, por ser primary key neste form,

fiva invisível. Para tal, na última página criada (a página do form) clique em Create depois no item

num_socio e depois substitua a característica hidden por number field para este attributo

(num_socio), como mostram as setas vermelhas na figura seguinte:

Next, you have to make the num_socio attribute a visible one because since it is primary key in this in-visible form it was hidden by the APEX. To do this, on the last created page (the form page), click Cre-ate on the item num_socio, and then replace the hidden feature with number field for this attribute (num_socio), as shown by the red arrows in the following figure:

Na característica Label podemos escrever num_socio.

Depois é preciso preencher o attributo num_socio com um valor automaticamente gerado pela

sequência seq_socio. Para tal, na zona Processing, clique em Process form ... e, na zona Settings à

direita, troque a indicação Region Source para PL/SQL code como mostram aas setas na figura.

Then you need to populate the attribute num_socio with a value automatically generated by the seq_socio sequence. To do this, in the Processing zone, click Process form ... and, in the Settings area on the right, change the Region Source indication to PL / SQL code as shown by the arrows in the fig-ure.

Depois abrir-se-á uma janela onde se deve escrever o seguinte programa em PL/SQL:

Then a window will open where the following PL / SQL program should be written:

BEGIN

IF :P20_NUM_SOCIO is NULL then

select seq_socio.nextval into :P20_NUM_SOCIO

from sys.dual;

end if;

end;

%NOTA: devido ao facto deste guião ter sido feito ao longo do tempo, o número da página do

forms surge por vezes com o nº 18 (:P18) ou com o número 20 (:P20) com é no caso presente.

% NOTE: Due to the fact that this script has been made over time, the page number of the forms some-times appears with the number 18 (: P18) or with the number 20 (: P20) with is in the present case.

Quando não houver mais erros sintáticos, corra a página.

When there are no more syntactic errors, run the page.

Preencha valores e clique em create e verá o resultado:

Fill in values and click on create and you will see the result:

Joaquim Francisco Ferreira da Silva

Maio de 2019