Commit 0119f01b authored by Thiago Anders's avatar Thiago Anders

EmprestarLivro criada e funcionando.

parent 7b8cb443
-- CLASS ngSituacaoExemplar
CREATE TABLE SITUACAOEXEMPLAR (
ID_SITUACAOEXEMPLAR INT PRIMARY KEY,
CODIGO VARCHAR(32) NOT NULL,
DESCRICAO VARCHAR(128) NOT NULL
);
-- CLASS ngLivro
CREATE TABLE LIVRO (
ID_LIVRO INT PRIMARY KEY,
TITULO VARCHAR(200) NOT NULL,
AUTOR VARCHAR(128) NOT NULL,
EDICAO VARCHAR(64) NOT NULL
);
-- CLASS ngCliente
CREATE TABLE CLIENTE (
ID_CLIENTE INT PRIMARY KEY,
NOME VARCHAR(256) NOT NULL,
CPF VARCHAR(11) NOT NULL
);
-- CLASS ngExemplar
CREATE TABLE EXEMPLAR (
ID_EXEMPLAR INT PRIMARY KEY,
CODIGO VARCHAR(32) NOT NULL,
ID_SITUACAOEXEMPLAR INT NOT NULL,
ID_LIVRO INT NOT NULL
);
-- CLASS ngExemplar
-- RELATION ngSituacaoExemplar(0..*) <----> (1..1)ngExemplar
ALTER TABLE EXEMPLAR ADD CONSTRAINT F2999ID_SITUACAOEXEMPLAR FOREIGN KEY (ID_SITUACAOEXEMPLAR) REFERENCES SITUACAOEXEMPLAR(ID_SITUACAOEXEMPLAR);
CREATE INDEX I2999ID_SITUACAOEXEMPLAR ON EXEMPLAR (ID_SITUACAOEXEMPLAR);
-- RELATION ngLivro(0..*) <----> (1..1)ngExemplar
ALTER TABLE EXEMPLAR ADD CONSTRAINT F2999ID_LIVRO FOREIGN KEY (ID_LIVRO) REFERENCES LIVRO(ID_LIVRO);
CREATE INDEX I2999ID_LIVRO ON EXEMPLAR (ID_LIVRO);
-- CLASS ngEmprestimo -- CLASS ngEmprestimo
CREATE TABLE EMPRESTIMO ( CREATE TABLE EMPRESTIMO (
ID_EMPRESTIMO INT PRIMARY KEY, ID_EMPRESTIMO INT PRIMARY KEY,
...@@ -17,5 +58,4 @@ CREATE INDEX I3000ID_EXEMPLAR ON EMPRESTIMO (ID_EXEMPLAR); ...@@ -17,5 +58,4 @@ CREATE INDEX I3000ID_EXEMPLAR ON EMPRESTIMO (ID_EXEMPLAR);
-- RELATION ngCliente(0..*) <----> (1..1)ngEmprestimo -- RELATION ngCliente(0..*) <----> (1..1)ngEmprestimo
ALTER TABLE EMPRESTIMO ADD CONSTRAINT F3000ID_CLIENTE FOREIGN KEY (ID_CLIENTE) REFERENCES CLIENTE(ID_CLIENTE); ALTER TABLE EMPRESTIMO ADD CONSTRAINT F3000ID_CLIENTE FOREIGN KEY (ID_CLIENTE) REFERENCES CLIENTE(ID_CLIENTE);
CREATE INDEX I3000ID_CLIENTE ON EMPRESTIMO (ID_CLIENTE); CREATE INDEX I3000ID_CLIENTE ON EMPRESTIMO (ID_CLIENTE);
\ No newline at end of file
INSERT INTO SITUACAOEXEMPLAR VALUES (1,'1','Disponível')
INSERT INTO SITUACAOEXEMPLAR VALUES (2,'2','Emprestado')
INSERT INTO SITUACAOEXEMPLAR VALUES (3,'3','Reservado')
INSERT INTO SITUACAOEXEMPLAR VALUES (4,'4','Outro')
INSERT INTO EXEMPLAR VALUES (1,'34523452345',1,1)
INSERT INTO EXEMPLAR VALUES (2,'34523452346',1,1)
INSERT INTO EXEMPLAR VALUES (3,'34523452347',1,2)
INSERT INTO EXEMPLAR VALUES (4,'34523452348',1,2)
-- CLASS ngCliente
CREATE TABLE CLIENTE (
ID_CLIENTE INT PRIMARY KEY,
NOME VARCHAR(256) NOT NULL,
CPF VARCHAR(11) NOT NULL
);
-- CLASS ngExemplar
CREATE TABLE EXEMPLAR (
ID_EXEMPLAR INT PRIMARY KEY,
CODIGO VARCHAR(32) NOT NULL,
ID_SITUACAOEXEMPLAR INT NOT NULL,
ID_LIVRO INT NOT NULL
);
-- CLASS ngExemplar
-- RELATION ngSituacaoExemplar(0..*) <----> (1..1)ngExemplar
ALTER TABLE EXEMPLAR ADD CONSTRAINT F2999ID_SITUACAOEXEMPLAR FOREIGN KEY (ID_SITUACAOEXEMPLAR) REFERENCES SITUACAOEXEMPLAR(ID_SITUACAOEXEMPLAR);
CREATE INDEX I2999ID_SITUACAOEXEMPLAR ON EXEMPLAR (ID_SITUACAOEXEMPLAR);
-- RELATION ngLivro(0..*) <----> (1..1)ngExemplar
ALTER TABLE EXEMPLAR ADD CONSTRAINT F2999ID_LIVRO FOREIGN KEY (ID_LIVRO) REFERENCES LIVRO(ID_LIVRO);
CREATE INDEX I2999ID_LIVRO ON EXEMPLAR (ID_LIVRO);
-- CLASS ngLivro
CREATE TABLE LIVRO (
ID_LIVRO INT PRIMARY KEY,
TITULO VARCHAR(200) NOT NULL,
AUTOR VARCHAR(128) NOT NULL,
EDICAO VARCHAR(64) NOT NULL
);
-- CLASS ngSituacaoExemplar
CREATE TABLE SITUACAOEXEMPLAR (
ID_SITUACAOEXEMPLAR INT PRIMARY KEY,
CODIGO VARCHAR(32) NOT NULL,
DESCRICAO VARCHAR(128) NOT NULL
);
...@@ -89,10 +89,17 @@ uses ...@@ -89,10 +89,17 @@ uses
ucuCadastroUsuarioSistema, ucuCadastroUsuarioSistema,
utuSysUtils, utuSysUtils,
acuRegisterModelMappings in 'lib\acuRegisterModelMappings.pas', acuRegisterModelMappings in 'lib\acuRegisterModelMappings.pas',
nguVersaoBanco in 'ngu\nguVersaoBanco.pas',
ucuHelloWorldMain in 'ucu\ucuHelloWorldMain.pas', ucuHelloWorldMain in 'ucu\ucuHelloWorldMain.pas',
svuHelloWorld in 'svuHelloWorld.pas' {svHelloWorld: TService}, svuHelloWorld in 'svuHelloWorld.pas' {svHelloWorld: TService},
ucuHelloWorld in 'ucu\ucuHelloWorld.pas'; ucuHelloWorld in 'ucu\ucuHelloWorld.pas',
ucuEmprestarLivro in 'ucu\ucuEmprestarLivro.pas',
utuEmprestimoOQL in 'utu\utuEmprestimoOQL.pas',
nguCliente in 'ngu\nguCliente.pas',
nguEmprestimo in 'ngu\nguEmprestimo.pas',
nguExemplar in 'ngu\nguExemplar.pas',
nguLivro in 'ngu\nguLivro.pas',
nguSituacaoExemplar in 'ngu\nguSituacaoExemplar.pas',
nguVersaoBanco in 'ngu\nguVersaoBanco.pas';
var var
lErros : TStringList; lErros : TStringList;
......
...@@ -4,7 +4,7 @@ unit nguCliente; ...@@ -4,7 +4,7 @@ unit nguCliente;
interface interface
uses uses
acuframework; acuframework, utuMessage;
type type
ngCliente = class(acPersistentObject) ngCliente = class(acPersistentObject)
...@@ -12,6 +12,8 @@ type ...@@ -12,6 +12,8 @@ type
FNome: acString; FNome: acString;
FCPF: acString; FCPF: acString;
fEmprestimos: acRelationPartnerList; fEmprestimos: acRelationPartnerList;
public
procedure toXML(piField: utField);
published published
property Nome: acString read FNome write FNome; property Nome: acString read FNome write FNome;
property CPF: acString read FCPF write FCPF; property CPF: acString read FCPF write FCPF;
...@@ -20,6 +22,14 @@ type ...@@ -20,6 +22,14 @@ type
implementation implementation
{ ngCliente }
procedure ngCliente.toXML(piField: utField);
begin
piField.AddAttribute('OID').AsString := Self.IDO.AsString;
piField.AddAttribute('Nome').AsString := Self.Nome.AsString;
piField.AddAttribute('CPF').AsString := Self.CPF.AsString;
end;
initialization initialization
......
...@@ -25,7 +25,13 @@ type ...@@ -25,7 +25,13 @@ type
implementation implementation
uses uses
ucuManager; ucuManager,
utuMessage {define utField},
acuFramework,
utuEmprestimoOQL,
acuObject {define acEnumerator},
nguCliente;
procedure ucEmprestarLivro.Initialize; procedure ucEmprestarLivro.Initialize;
begin begin
...@@ -39,9 +45,50 @@ begin ...@@ -39,9 +45,50 @@ begin
end; end;
procedure ucEmprestarLivro.Effect_PesquisarUsuario(piRequest: utRequest; piTransition: utTransition); procedure ucEmprestarLivro.Effect_PesquisarUsuario(piRequest: utRequest; piTransition: utTransition);
var
lFieldUsuario,
lFieldUsuarios: utField;
lOQL: IObterClientes;
lListUsuarios: acPersistentObjectList;
lEnumUsuario: acEnumerator;
lUsuario: ngCliente;
begin begin
lFieldUsuario := piRequest.Message.RootField.FieldByName('Cliente');
lOQL := utEmprestimoOQL.ObterClientes(Self.Session);
lFieldUsuarios := piRequest.Response.RootField.AddField('Cliente');
lListUsuarios := acPersistentObjectList.Create(ngCliente);
try
if lFieldUsuario.HasAttribute('Nome')
then lOQL.Param_nome.Value := lFieldUsuario.AttributeByName('Nome').AsString
else lOQL.Param_nome.SetNull;
if lFieldUsuario.HasAttribute('CPF')
then lOQL.Param_cpf.Value := lFieldUsuario.AttributeByName('CPF').AsString
else lOQL.Param_cpf.SetNull;
lOQL.LoadList(lListUsuarios);
lEnumUsuario := acEnumerator.Create(lListUsuarios);
try
while not lEnumUsuario.EOL do
begin
lUsuario := lEnumUsuario.Current as ngCliente;
lUsuario.toXML(lFieldUsuarios.AddField('Cliente'));
lEnumUsuario.MoveNext;
end;
finally
lEnumUsuario.Free;
end;
finally
lListUsuarios.Free;
end;
piRequest.Processed := True; piRequest.Processed := True;
end; end;
......
unit utuEmprestimoOQL;
interface
uses acuOQL, acuFramework;
type
IObterClientes = interface(IOQLQuery)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
end;
utEmprestimoOQL = class
class function ObterClientes(piSessao: acPersistenceSession): IObterClientes;
end;
implementation
type
TObterClientes = class(acOQLQuery, IObterClientes)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
end;
{ TObterClientes }
function TObterClientes.Param_nome: acOQLParamString;
begin
result := acOQLParamString(Self.ParamByName('nome'));
end;
function TObterClientes.Param_cpf: acOQLParamString;
begin
result := acOQLParamString(Self.ParamByName('cpf'));
end;
{ utOQLs }
class function utEmprestimoOQL.ObterClientes(piSessao: acPersistenceSession): IObterClientes;
begin
result := TObterClientes.Create(pisessao,
'SELECT ngCliente' + #13#10 +
'FROM ngCliente' + #13#10 +
'WHERE (ngCliente.Nome LIKE ''%''+?nome:acString+''%'' OR ?nome:acString IS NULL)' + #13#10 +
' AND (ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)');
end;
end.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment