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" ?>
<DATA>
<oql name="ContarEmprestimosDeUmLivro" oqltype="0">
<oql name="ContarEmprestimosExemplar" oqltype="1">
<description></description>
<query><![CDATA[SELECT count(*) as qnt
FROM ngExemplar
]]></query>
FROM ngExemplar,
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 name="ObterClientes" oqltype="0">
<description></description>
......@@ -29,7 +38,7 @@ WHERE (ngExemplar.Livro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString
ORDER BY ngExemplar.Livro.OID]]></query>
</oql>
<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
FROM ngLivro
WHERE (ngLivro.Titulo LIKE '%'+?titulo:acString+'%' OR ?titulo:acString IS NULL)
......
......@@ -2020,7 +2020,7 @@ 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="SYSMAG">' + #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 +
......@@ -2077,6 +2077,47 @@ begin
'';
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;
begin
Result := '<?xml version="1.0"?>' + #13#10 +
......@@ -3185,6 +3226,7 @@ begin
lTransition.AddTrigger('RM_CONCLUIR_EDICAO');
lTransition.AddEffect('Effect_ConcluirEdicao');
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.SourceState := lState;
lTransition.TargetState := lStateMachine.FindState('SelecionandoLivro');
......
......@@ -13,6 +13,7 @@ type
procedure Finalize; Override;
private
fLivro: ngLivro;
fSavePoint: acPersistenceSessionSavePoint;
published
procedure Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition);
procedure Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition);
......@@ -49,16 +50,65 @@ begin
end;
procedure ucCadastrarLivro.Effect_IncluirLivro(piRequest: utRequest; piTransition: utTransition);
var
lFieldLivro: utField;
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;
end;
procedure ucCadastrarLivro.Effect_EditarLivro(piRequest: utRequest; piTransition: utTransition);
var
lFieldLivro,
lFieldExemplares,
lFieldExemplar: utField;
lExemplar: ngExemplar;
lExemplares: acPersistentObjectList;
lEnumExemplar: acEnumerator;
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;
end;
......@@ -115,20 +165,39 @@ end;
{Se ele possuir exemplares, eles sero deletados juntos com o livro.}
procedure ucCadastrarLivro.Effect_ExcluirLivro(piRequest: utRequest; piTransition: utTransition);
var
lFieldLivro: utField;
lFieldLivro,
lFieldResult: utField;
lLivro: ngLivro;
lListExemplares: acPersistentObjectList;
lOQL: IContarEmprestimosLivro;
lSavePoint: acPersistenceSessionSavePoint;
begin
lFieldLivro := piRequest.Message.RootField.FieldByName('Livro');
lSavePoint := Session.AddSavePoint;
try
lLivro := Self.Session.LoadObject(ngLivro,acOIDInt.Create(lFieldLivro.AttributeByName('OID').AsInteger)) as ngLivro;
Self.Session.DeleteObject(lLivro,ngLivro);
{Preparamos a busca OQL}
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
on e:acObjectNotFoundException do
raise EucException.Create('Livro a ser deletado no encontrado.');
else
raise EucException.Create('No foi possvel buscar o Livro a ser deletado.');
Self.Session.RollBackToSavePoint(lSavePoint);
raise;
end;
piRequest.Processed := True;
......@@ -136,15 +205,14 @@ end;
procedure ucCadastrarLivro.Effect_ConcluirEdicao(piRequest: utRequest; piTransition: utTransition);
begin
piRequest.Processed := True;
end;
procedure ucCadastrarLivro.Effect_Cancelar(piRequest: utRequest; piTransition: utTransition);
begin
if Assigned(fSavePoint)
then Session.RollBackToSavePoint(fSavePoint);
piRequest.Processed := True;
end;
......
......@@ -6,6 +6,14 @@ uses acuOQL, acuFramework;
type
IContarEmprestimosExemplar = interface(IDataSetOQLQuery)
function Param_oid: acOQLParamInt;
end;
IContarEmprestimosLivro = interface(IDataSetOQLQuery)
function Param_oid: acOQLParamInt;
end;
IObterClientes = interface(IOQLQuery)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
......@@ -27,6 +35,8 @@ type
end;
utEmprestimoOQL = class
class function ContarEmprestimosExemplar(piSessao: acPersistenceSession): IContarEmprestimosExemplar;
class function ContarEmprestimosLivro(piSessao: acPersistenceSession): IContarEmprestimosLivro;
class function ObterClientes(piSessao: acPersistenceSession): IObterClientes;
class function ObterEmprestimos(piSessao: acPersistenceSession): IObterEmprestimos;
class function ObterExemplares(piSessao: acPersistenceSession): IObterExemplares;
......@@ -37,6 +47,14 @@ implementation
type
TContarEmprestimosExemplar = class(acDataSetOQLQuery, IContarEmprestimosExemplar)
function Param_oid: acOQLParamInt;
end;
TContarEmprestimosLivro = class(acDataSetOQLQuery, IContarEmprestimosLivro)
function Param_oid: acOQLParamInt;
end;
TObterClientes = class(acOQLQuery, IObterClientes)
function Param_nome: acOQLParamString;
function Param_cpf: acOQLParamString;
......@@ -57,6 +75,20 @@ type
function Param_autor: acOQLParamString;
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 }
function TObterClientes.Param_nome: acOQLParamString;
......@@ -107,6 +139,25 @@ end;
{ 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;
begin
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