Commit 0a47ab0c authored by Thiago Anders's avatar Thiago Anders

Incluir e editar livro prontos

parent 8ec60964
<?xml version="1.0" encoding="ISO-8859-1" ?> <?xml version="1.0" encoding="ISO-8859-1" ?>
<DATA> <DATA>
<oql name="ContarEmprestimosDeUmLivro" oqltype="0"> <oql name="ContarEmprestimosExemplar" oqltype="1">
<description></description> <description></description>
<query><![CDATA[SELECT count(*) as qnt <query><![CDATA[SELECT count(*) as qnt
FROM ngExemplar FROM ngExemplar,
]]></query> ngExemplar.Emprestimos
WHERE ngExemplar.OID = ?oid:acInt]]></query>
</oql>
<oql name="ContarEmprestimosLivro" oqltype="1">
<description></description>
<query><![CDATA[SELECT count(*) as qnt
FROM ngLivro,
ngLivro.Exemplares,
ngLivro.Exemplares.Emprestimos
WHERE ngLivro.OID = ?oid:acInt]]></query>
</oql> </oql>
<oql name="ObterClientes" oqltype="0"> <oql name="ObterClientes" oqltype="0">
<description></description> <description></description>
...@@ -29,7 +38,7 @@ WHERE (ngExemplar.Livro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString ...@@ -29,7 +38,7 @@ WHERE (ngExemplar.Livro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString
ORDER BY ngExemplar.Livro.OID]]></query> ORDER BY ngExemplar.Livro.OID]]></query>
</oql> </oql>
<oql name="ObterLivros" oqltype="0"> <oql name="ObterLivros" oqltype="0">
<description>Obtm livros por ttulo ou autor.</description> <description>Obt�m livros por t�tulo ou autor.</description>
<query><![CDATA[SELECT ngLivro <query><![CDATA[SELECT ngLivro
FROM ngLivro FROM ngLivro
WHERE (ngLivro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString IS NULL) WHERE (ngLivro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString IS NULL)
......
...@@ -2020,7 +2020,7 @@ begin ...@@ -2020,7 +2020,7 @@ begin
Result := '<?xml version="1.0"?>' + #13#10 + Result := '<?xml version="1.0"?>' + #13#10 +
'<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->' + #13#10 + '<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->' + #13#10 +
'<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">' + #13#10 + '<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">' + #13#10 +
' <xs:element name="SYSMAG">' + #13#10 + ' <xs:element name="SYSMSG">' + #13#10 +
' <xs:complexType>' + #13#10 + ' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 + ' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element name="Livro">' + #13#10 + ' <xs:element name="Livro">' + #13#10 +
...@@ -2077,6 +2077,47 @@ begin ...@@ -2077,6 +2077,47 @@ begin
''; '';
end; end;
function GetXSDOut_3227_smucCadastrarLivro_EditandoCadastro_RM_CONCLUIR_EDICAO: String;
begin
Result := '<?xml version="1.0"?>' + #13#10 +
'<!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)-->' + #13#10 +
'<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">' + #13#10 +
' <xs:element name="SYSMSG">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element name="Livro">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="1" maxOccurs="1">' + #13#10 +
' <xs:element name="Exemplares">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:sequence minOccurs="0" maxOccurs="unbounded">' + #13#10 +
' <xs:element name="Exemplar">' + #13#10 +
' <xs:complexType>' + #13#10 +
' <xs:attribute name="Codigo" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:attribute name="Titulo" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="Autor" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="Edicao" type="xs:string" use="required"/>' + #13#10 +
' <xs:attribute name="OID" type="xs:int" use="required"/>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
' </xs:sequence>' + #13#10 +
' <xs:anyAttribute processContents="skip"/>' + #13#10 +
' </xs:complexType>' + #13#10 +
' </xs:element>' + #13#10 +
'</xs:schema>' + #13#10 +
'';
end;
function GetXSDIn_3227_smucCadastrarLivro_EditandoCadastro_RM_INCLUIR_EXEMPLAR: String; function GetXSDIn_3227_smucCadastrarLivro_EditandoCadastro_RM_INCLUIR_EXEMPLAR: String;
begin begin
Result := '<?xml version="1.0"?>' + #13#10 + Result := '<?xml version="1.0"?>' + #13#10 +
...@@ -3185,6 +3226,7 @@ begin ...@@ -3185,6 +3226,7 @@ begin
lTransition.AddTrigger('RM_CONCLUIR_EDICAO'); lTransition.AddTrigger('RM_CONCLUIR_EDICAO');
lTransition.AddEffect('Effect_ConcluirEdicao'); lTransition.AddEffect('Effect_ConcluirEdicao');
lTransition.XsdIn.XML := GetXSDIn_3227_smucCadastrarLivro_EditandoCadastro_RM_CONCLUIR_EDICAO; lTransition.XsdIn.XML := GetXSDIn_3227_smucCadastrarLivro_EditandoCadastro_RM_CONCLUIR_EDICAO;
lTransition.XsdOut.XML := GetXSDOut_3227_smucCadastrarLivro_EditandoCadastro_RM_CONCLUIR_EDICAO;
lTransition := lState.NewOutgoingTransition('RM_CANCELAR'); lTransition := lState.NewOutgoingTransition('RM_CANCELAR');
lTransition.SourceState := lState; lTransition.SourceState := lState;
lTransition.TargetState := lStateMachine.FindState('SelecionandoLivro'); lTransition.TargetState := lStateMachine.FindState('SelecionandoLivro');
......
...@@ -13,6 +13,7 @@ type ...@@ -13,6 +13,7 @@ type
procedure Finalize; Override; procedure Finalize; Override;
private private
fLivro: ngLivro; fLivro: ngLivro;
fSavePoint: acPersistenceSessionSavePoint;
published published
procedure Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition); procedure Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition);
procedure Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition); procedure Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition);
...@@ -49,16 +50,65 @@ begin ...@@ -49,16 +50,65 @@ begin
end; end;
procedure ucCadastrarLivro.Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition); procedure ucCadastrarLivro.Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition);
var
lFieldLivro: utField;
begin begin
fSavePoint := Self.Session.AddSavePoint;
try
fLivro := ngLivro.CreateNew(Self.Session);
lFieldLivro := piRequest.Response.RootField.AddField('Livro');
lFieldLivro.AddAttribute('OID').AsInteger := fLivro.IDO.AsVariant;
except
Self.Session.RollBackToSavePoint(fSavePoint);
raise;
end;
piRequest.Processed := True; piRequest.Processed := True;
end; end;
procedure ucCadastrarLivro.Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition); procedure ucCadastrarLivro.Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition);
var
lFieldLivro,
lFieldExemplares,
lFieldExemplar: utField;
lExemplar: ngExemplar;
lExemplares: acPersistentObjectList;
lEnumExemplar: acEnumerator;
begin begin
fSavePoint := Self.Session.AddSavePoint;
lFieldLivro := piRequest.Message.RootField.FieldByName('Livro');
{Tentamos carregar o livro}
try
fLivro := Self.Session.LoadObject(ngLivro,acOIDInt.Create(lFieldLivro.AttributeByName('OID').AsInteger)) as ngLivro;
except
on e:acObjectNotFoundException do
raise EucException.Create('Livro a ser editado no pode ser encontrado.');
else
raise EucException.Create('No foi possvel editar este livro.');
end;
{Retornamos o livro e todos os seus exemplares}
lExemplares := fLivro.Exemplares as acPersistentObjectList;
lFieldLivro := piRequest.Response.RootField.AddField('Livro');
fLivro.toXML(lFieldLivro);
lFieldExemplares := lFieldLivro.AddField('Exemplares');
lEnumExemplar := acEnumerator.Create(lExemplares);
while not lEnumExemplar.EOL do
begin
lFieldExemplar := lFieldExemplares.AddField('Exemplar');
lExemplar := lEnumExemplar.Current;
lExemplar.toXML(lFieldExemplar);
lEnumExemplar.MoveNext;
end;
piRequest.Processed := True; piRequest.Processed := True;
end; end;
...@@ -115,20 +165,39 @@ end; ...@@ -115,20 +165,39 @@ end;
{Se ele possuir exemplares, eles sero deletados juntos com o livro.} {Se ele possuir exemplares, eles sero deletados juntos com o livro.}
procedure ucCadastrarLivro.Effect_ExcluirLivro(piRequest: utRequest; piTransition: utTransition); procedure ucCadastrarLivro.Effect_ExcluirLivro(piRequest: utRequest; piTransition: utTransition);
var var
lFieldLivro: utField; lFieldLivro,
lFieldResult: utField;
lLivro: ngLivro; lLivro: ngLivro;
lListExemplares: acPersistentObjectList; lListExemplares: acPersistentObjectList;
lOQL: IContarEmprestimosLivro;
lSavePoint: acPersistenceSessionSavePoint;
begin begin
lFieldLivro := piRequest.Message.RootField.FieldByName('Livro'); lFieldLivro := piRequest.Message.RootField.FieldByName('Livro');
lSavePoint := Session.AddSavePoint;
try try
lLivro := Self.Session.LoadObject(ngLivro,acOIDInt.Create(lFieldLivro.AttributeByName('OID').AsInteger)) as ngLivro; {Preparamos a busca OQL}
Self.Session.DeleteObject(lLivro,ngLivro); lOQL := utEmprestimoOQL.ContarEmprestimosLivro(Self.Session);
lOQL.Param_oid.Value := lFieldLivro.AttributeByName('OID').AsInteger;
lFieldResult := utField.Create;
try
{Verificamos se ele tiver emprestimos}
lOQL.LoadDataSet(lFieldResult);
if lFieldResult.ValueByPath('DATAPACKET.ROWDATA.ROW.@C0').AsInteger > 0
then raise EucException.Create('Nao foi possvel excluir o livro, ele possui pelo menos um exemplar com emprstimo associado.');
{Deletamos o livro e seus exemplares, exemplares so deletado devido a efeito cascata da composio}
lLivro := Self.Session.LoadObject(ngLivro,acOIDInt.Create(lFieldLivro.AttributeByName('OID').AsInteger)) as ngLivro;
Self.Session.DeleteObject(lLivro);
Self.Session.Save;
finally
lFieldResult.Free;
end;
except except
on e:acObjectNotFoundException do Self.Session.RollBackToSavePoint(lSavePoint);
raise EucException.Create('Livro a ser deletado no encontrado.'); raise;
else
raise EucException.Create('No foi possvel buscar o Livro a ser deletado.');
end; end;
piRequest.Processed := True; piRequest.Processed := True;
...@@ -136,15 +205,14 @@ end; ...@@ -136,15 +205,14 @@ end;
procedure ucCadastrarLivro.Effect_ConcluirEdicao(piRequest: utRequest; piTransition: utTransition); procedure ucCadastrarLivro.Effect_ConcluirEdicao(piRequest: utRequest; piTransition: utTransition);
begin begin
piRequest.Processed := True;
end; end;
procedure ucCadastrarLivro.Effect_Cancelar(piRequest: utRequest; piTransition: utTransition); procedure ucCadastrarLivro.Effect_Cancelar(piRequest: utRequest; piTransition: utTransition);
begin begin
if Assigned(fSavePoint)
then Session.RollBackToSavePoint(fSavePoint);
piRequest.Processed := True; piRequest.Processed := True;
end; end;
......
...@@ -6,6 +6,14 @@ uses acuOQL, acuFramework; ...@@ -6,6 +6,14 @@ uses acuOQL, acuFramework;
type type
IContarEmprestimosExemplar = interface(IDataSetOQLQuery)
function Param_oid: acOQLParamInt;
end;
IContarEmprestimosLivro = interface(IDataSetOQLQuery)
function Param_oid: acOQLParamInt;
end;
IObterClientes = interface(IOQLQuery) IObterClientes = interface(IOQLQuery)
function Param_nome: acOQLParamString; function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString; function Param_cpf: acOQLParamString;
...@@ -27,6 +35,8 @@ type ...@@ -27,6 +35,8 @@ type
end; end;
utEmprestimoOQL = class utEmprestimoOQL = class
class function ContarEmprestimosExemplar(piSessao: acPersistenceSession): IContarEmprestimosExemplar;
class function ContarEmprestimosLivro(piSessao: acPersistenceSession): IContarEmprestimosLivro;
class function ObterClientes(piSessao: acPersistenceSession): IObterClientes; class function ObterClientes(piSessao: acPersistenceSession): IObterClientes;
class function ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos; class function ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos;
class function ObterExemplares(piSessao: acPersistenceSession): IObterExemplares; class function ObterExemplares(piSessao: acPersistenceSession): IObterExemplares;
...@@ -37,6 +47,14 @@ implementation ...@@ -37,6 +47,14 @@ implementation
type type
TContarEmprestimosExemplar = class(acDataSetOQLQuery, IContarEmprestimosExemplar)
function Param_oid: acOQLParamInt;
end;
TContarEmprestimosLivro = class(acDataSetOQLQuery, IContarEmprestimosLivro)
function Param_oid: acOQLParamInt;
end;
TObterClientes = class(acOQLQuery, IObterClientes) TObterClientes = class(acOQLQuery, IObterClientes)
function Param_nome: acOQLParamString; function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString; function Param_cpf: acOQLParamString;
...@@ -57,6 +75,20 @@ type ...@@ -57,6 +75,20 @@ type
function Param_autor: acOQLParamString; function Param_autor: acOQLParamString;
end; end;
{ TContarEmprestimosExemplar }
function TContarEmprestimosExemplar.Param_oid: acOQLParamInt;
begin
result := acOQLParamInt(Self.ParamByName('oid'));
end;
{ TContarEmprestimosLivro }
function TContarEmprestimosLivro.Param_oid: acOQLParamInt;
begin
result := acOQLParamInt(Self.ParamByName('oid'));
end;
{ TObterClientes } { TObterClientes }
function TObterClientes.Param_nome: acOQLParamString; function TObterClientes.Param_nome: acOQLParamString;
...@@ -107,6 +139,25 @@ end; ...@@ -107,6 +139,25 @@ end;
{ utOQLs } { utOQLs }
class function utEmprestimoOQL.ContarEmprestimosExemplar(piSessao: acPersistenceSession): IContarEmprestimosExemplar;
begin
result := TContarEmprestimosExemplar.Create(pisessao,
'SELECT count(*) as qnt' + #13#10 +
'FROM ngExemplar,' + #13#10 +
' ngExemplar.Emprestimos' + #13#10 +
'WHERE ngExemplar.OID = ?oid:acInt');
end;
class function utEmprestimoOQL.ContarEmprestimosLivro(piSessao: acPersistenceSession): IContarEmprestimosLivro;
begin
result := TContarEmprestimosLivro.Create(pisessao,
'SELECT count(*) as qnt' + #13#10 +
'FROM ngLivro,' + #13#10 +
' ngLivro.Exemplares,' + #13#10 +
' ngLivro.Exemplares.Emprestimos' + #13#10 +
'WHERE ngLivro.OID = ?oid:acInt');
end;
class function utEmprestimoOQL.ObterClientes(piSessao: acPersistenceSession): IObterClientes; class function utEmprestimoOQL.ObterClientes(piSessao: acPersistenceSession): IObterClientes;
begin begin
result := TObterClientes.Create(pisessao, result := TObterClientes.Create(pisessao,
......
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