Commit 45f74053 authored by Thiago Anders's avatar Thiago Anders

Caso de uso para cadastrar cliente feito

parent b53b431a
......@@ -19,8 +19,8 @@ WHERE ngLivro.OID = ?oid:acInt]]></query>
<description></description>
<query><![CDATA[SELECT ngCliente
FROM ngCliente
WHERE (ngCliente.Nome LIKE '%'+?nome:acString+'%' OR ?nome:acString IS NULL)
AND (ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL)]]></query>
WHERE ((ngCliente.Nome LIKE '%'+?nome:acString+'%' OR ?nome:acString IS NULL) AND ngCliente.Ativo = "1")
AND ((ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL) AND ngCliente.Ativo = "1")]]></query>
</oql>
<oql name="ObterEmprestimos" oqltype="0">
<description>Obtem emprestimos por cliente.</description>
......
This diff is collapsed.
......@@ -101,7 +101,8 @@ uses
nguSituacaoExemplar in 'ngu\nguSituacaoExemplar.pas',
nguVersaoBanco in 'ngu\nguVersaoBanco.pas',
ucuBuscarEmprestimos in 'ucu\ucuBuscarEmprestimos.pas',
ucuCadastrarLivro in 'ucu\ucuCadastrarLivro.pas';
ucuCadastrarLivro in 'ucu\ucuCadastrarLivro.pas',
ucuCadastrarCliente in 'ucu\ucuCadastrarCliente.pas';
var
lErros : TStringList;
......
This diff is collapsed.
......@@ -11,19 +11,19 @@ type
private
FNome: acString;
FCPF: acString;
FAtivo: acString;
fEmprestimos: acRelationPartnerList;
public
procedure toXML(piField: utField);
published
property Nome: acString read FNome write FNome;
property CPF: acString read FCPF write FCPF;
property Ativo: acString read FAtivo write FAtivo;
property Emprestimos: acRelationPartnerList read fEmprestimos write fEmprestimos;
end;
implementation
{ ngCliente }
procedure ngCliente.toXML(piField: utField);
begin
piField.AddAttribute('OID').AsString := Self.IDO.AsString;
......@@ -36,4 +36,3 @@ initialization
PersistenceManager.RegisterClass(ngCliente);
end.
unit ucuCadastrarCliente;
interface
uses
utuStateMachine, utuRequest, ucuUseCase, acuFramework, nguCliente;
type
ucCadastrarCliente = class(ucUseCase)
public
procedure Initialize; Override;
procedure Finalize; Override;
private
fCliente: ngCliente;
fSavePoint: acPersistenceSessionSavePoint;
published
procedure Effect_BuscarCliente(piRequest: utRequest; piTransition: utTransition);
procedure Effect_ExcluirCliente(piRequest: utRequest; piTransition: utTransition);
procedure Effect_IncluirCliente(piRequest: utRequest; piTransition: utTransition);
procedure Effect_EditarCliente(piRequest: utRequest; piTransition: utTransition);
procedure Effect_ConcluirEdicao(piRequest: utRequest; piTransition: utTransition);
procedure Effect_Cancelar(piRequest: utRequest; piTransition: utTransition);
end;
implementation
uses
ucuManager,
utuMessage {define utField},
utuEmprestimoOQL,
acuObject {define acEnumerator},
nguExemplar,
nguSituacaoExemplar,
nguEmprestimo,
nguLivro,
dateUtils;
procedure ucCadastrarCliente.Initialize;
begin
inherited;
end;
procedure ucCadastrarCliente.Finalize;
begin
inherited;
end;
procedure ucCadastrarCliente.Effect_BuscarCliente(piRequest: utRequest; piTransition: utTransition);
var
lFieldClientes,
lFieldCliente: utField;
lOQL: IObterClientes;
lListClientes: acPersistentObjectList;
lEnumCliente: acEnumerator;
lCliente: ngCliente;
begin
lFieldCliente:= piRequest.Message.RootField.FieldByName('Cliente');
lOQL := utEmprestimoOQL.ObterClientes(Self.Session);
lFieldClientes := piRequest.Response.RootField.AddField('Clientes');
lListClientes := acPersistentObjectList.Create(ngCliente);
try
if lFieldCliente.HasAttribute('CPF')
then lOQL.Param_cpf.Value := lFieldCliente.AttributeByName('CPF').AsString
else lOQL.Param_cpf.SetNull;
if lFieldCliente.HasAttribute('Nome')
then lOQL.Param_nome.Value := lFieldCliente.AttributeByName('Nome').AsString
else lOQL.Param_nome.SetNull;
lOQL.LoadList(lListClientes);
lEnumCliente := acEnumerator.Create(lListClientes);
try
while not lEnumCliente.EOL do
begin
lCliente := lEnumCliente.Current as ngCliente;
lCliente.toXML(lFieldClientes.AddField('Cliente'));
lEnumCliente.MoveNext;
end;
finally
lEnumCliente.Free;
end;
finally
lListClientes.Free;
end;
piRequest.Processed := True;
end;
procedure ucCadastrarCliente.Effect_IncluirCliente(piRequest: utRequest; piTransition: utTransition);
var
lFieldCliente: utField;
begin
fSavePoint := Self.Session.AddSavePoint;
try
fCliente := ngCliente.CreateNew(Self.Session);
lFieldCliente := piRequest.Response.RootField.AddField('Cliente');
lFieldCliente.AddAttribute('OID').AsInteger := fCliente.IDO.AsVariant;
except
Self.Session.RollBackToSavePoint(fSavePoint);
raise;
end;
piRequest.Processed := True;
end;
procedure ucCadastrarCliente.Effect_ExcluirCliente(piRequest: utRequest; piTransition: utTransition);
var
lFieldCliente: utField;
lSavePoint: acPersistenceSessionSavePoint;
begin
lSavePoint := Self.Session.AddSavePoint;
lFieldCliente := piRequest.Message.RootField.FieldByName('Cliente');
try
fCliente := Self.Session.LoadObject(ngCliente,acOIDInt.Create(lFieldCliente.AttributeByName('OID').AsInteger)) as ngCliente;
fCliente.Ativo.Value := '0';
Self.Session.Save;
except
Self.Session.RollBackToSavePoint(lSavePoint);
raise;
end;
piRequest.Processed := True;
end;
procedure ucCadastrarCliente.Effect_EditarCliente(piRequest: utRequest; piTransition: utTransition);
var
lFieldCliente: utField;
begin
fSavePoint := Self.Session.AddSavePoint;
lFieldCliente := piRequest.Message.RootField.FieldByName('Cliente');
try
fCliente := Self.Session.LoadObject(ngCliente,acOIDInt.Create(lFieldCliente.AttributeByName('OID').AsInteger)) as ngCliente;
except
on e:acObjectNotFoundException do
raise EucException.Create('Cliente a ser editado no pode ser encontrado.');
else
raise EucException.Create('No foi possvel editar este cliente.');
end;
lFieldCliente := piRequest.Response.RootField.AddField('Cliente');
fCliente.toXML(lFieldCliente);
piRequest.Processed := True;
end;
procedure ucCadastrarCliente.Effect_ConcluirEdicao(piRequest: utRequest; piTransition: utTransition);
var
lFieldCliente: utField;
begin
lFieldCliente := piRequest.Message.RootField.FieldByName('Cliente');
fCliente.CPF.Value := lFieldCliente.AttributeByName('CPF').AsString;
fCliente.Nome.Value := lFieldCliente.AttributeByName('Nome').AsString;
fCliente.Ativo.Value := '1';
Self.Session.Save;
lFieldCliente := piRequest.Response.RootField.AddField('Cliente');
fCliente.toXML(lFieldCliente);
piRequest.Processed := True;
end;
procedure ucCadastrarCliente.Effect_Cancelar(piRequest: utRequest; piTransition: utTransition);
begin
if Assigned(fSavePoint)
then Session.RollBackToSavePoint(fSavePoint);
piRequest.Processed := True;
end;
initialization
gucManager.RegisterClass(3229,ucCadastrarCliente);
end.
......@@ -163,8 +163,8 @@ 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)');
'WHERE ((ngCliente.Nome LIKE ''%''+?nome:acString+''%'' OR ?nome:acString IS NULL) AND ngCliente.Ativo = "1")' + #13#10 +
' AND ((ngCliente.CPF = ?cpf:acString OR ?cpf:acString IS NULL) AND ngCliente.Ativo = "1")');
end;
class function utEmprestimoOQL.ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos;
......
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