git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@61 0c75b7a4-871f-7646-8a2f-f78d34cc349f
275 lines
7.1 KiB
ObjectPascal
275 lines
7.1 KiB
ObjectPascal
unit uFormasPagoController;
|
||
|
||
interface
|
||
|
||
|
||
uses
|
||
Classes, SysUtils, uDADataTable, uControllerBase,
|
||
uBizFormasPago, uFormasPagoPlazosController, uIDataModuleFormasPago;
|
||
type
|
||
IFormasPagoController = interface(IObservador)
|
||
['{94E5F2B6-64C8-4331-B9CB-3ED730478529}']
|
||
function BuscarTodos: IBizFormaPago;
|
||
function Buscar(ID: Integer): IBizFormaPago;
|
||
procedure VerTodos(AFormasPago: IBizFormaPago);
|
||
procedure Ver(AFormaPago: IBizFormaPago);
|
||
procedure Anadir(AFormaPago : IBizFormaPago);
|
||
function Eliminar(AFormaPago : IBizFormaPago): Boolean;
|
||
function Guardar(AFormaPago : IBizFormaPago): Boolean;
|
||
procedure DescartarCambios(AFormaPago : IBizFormaPago);
|
||
function Localizar(AFormasPago: IBizFormaPago; ADescripcion:String): Boolean;
|
||
function DarListaFormasPago: TStringList;
|
||
end;
|
||
|
||
TFormasPagoController = class(TObservador, IFormasPagoController)
|
||
protected
|
||
FDataModule : IDataModuleFormasPago;
|
||
FPlazosController : IFormasPagoPlazosController;
|
||
|
||
procedure RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable); override;
|
||
function CreateEditor(const AName : String; const IID: TGUID; out Intf): Boolean;
|
||
|
||
function ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean;
|
||
procedure AsignarDataModule;
|
||
|
||
public
|
||
constructor Create; virtual;
|
||
destructor Destroy; override;
|
||
|
||
function Eliminar(AFormaPago : IBizFormaPago): Boolean;
|
||
function Guardar(AFormaPago : IBizFormaPago): Boolean; virtual;
|
||
procedure DescartarCambios(AFormaPago : IBizFormaPago); virtual;
|
||
procedure Anadir(AFormaPago : IBizFormaPago);
|
||
function BuscarTodos: IBizFormaPago;
|
||
function Buscar(ID: Integer): IBizFormaPago;
|
||
procedure VerTodos(AFormasPago: IBizFormaPago);
|
||
procedure Ver(AFormaPago: IBizFormaPago);
|
||
function Localizar(AFormasPago: IBizFormaPago; ADescripcion:String): Boolean;
|
||
function DarListaFormasPago: TStringList;
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
cxControls, DB, uEditorRegistryUtils, schFormasPagoClient_Intf,
|
||
uIEditorFormasPago, uIEditorFormaPago, uDataModuleFormasPago,
|
||
uDAInterfaces, uDataTableUtils, uDialogUtils,
|
||
uDateUtils, uROTypes, DateUtils, Controls, Windows;
|
||
|
||
{ TFormasPagoController }
|
||
|
||
procedure TFormasPagoController.Anadir(AFormaPago: IBizFormaPago);
|
||
begin
|
||
AFormaPago.Insert;
|
||
end;
|
||
|
||
procedure TFormasPagoController.AsignarDataModule;
|
||
begin
|
||
FDataModule := TDataModuleFormasPago.Create(Nil);
|
||
end;
|
||
|
||
function TFormasPagoController.Buscar(ID: Integer): IBizFormaPago;
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
Result := BuscarTodos;
|
||
with Result.DataTable.DynamicWhere do
|
||
begin
|
||
// (ID = :ID)
|
||
Expression := NewBinaryExpression(NewField('', fld_FormasPagoID),
|
||
NewConstant(ID, datInteger), dboEqual);
|
||
end;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
function TFormasPagoController.BuscarTodos: IBizFormaPago;
|
||
begin
|
||
Result := FDataModule.GetItems;
|
||
end;
|
||
|
||
constructor TFormasPagoController.Create;
|
||
begin
|
||
AsignarDataModule;
|
||
FPlazosController := TFormasPagoPlazosController.Create;
|
||
end;
|
||
|
||
function TFormasPagoController.CreateEditor(const AName: String; const IID: TGUID; out Intf): Boolean;
|
||
begin
|
||
Result := Supports(EditorRegistry.CreateEditor(AName), IID, Intf);
|
||
end;
|
||
|
||
function TFormasPagoController.DarListaFormasPago: TStringList;
|
||
var
|
||
AFormasPago: IBizFormaPago;
|
||
begin
|
||
AFormasPago := BuscarTodos;
|
||
AFormasPago.DataTable.Active := True;
|
||
Result := TStringList.Create;
|
||
try
|
||
with Result do
|
||
begin
|
||
AFormasPago.DataTable.First;
|
||
while not AFormasPago.DataTable.EOF do
|
||
begin
|
||
Add(AFormasPago.DESCRIPCION);
|
||
AFormasPago.DataTable.Next;
|
||
end;
|
||
end;
|
||
finally
|
||
AFormasPago := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TFormasPagoController.DescartarCambios(AFormaPago: IBizFormaPago);
|
||
begin
|
||
if not Assigned(AFormaPago) then
|
||
raise Exception.Create ('Forma de pago no asignada');
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
if (AFormaPago.State in dsEditModes) then
|
||
AFormaPago.Cancel;
|
||
|
||
AFormaPago.DataTable.CancelUpdates;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
destructor TFormasPagoController.Destroy;
|
||
begin
|
||
FDataModule:= NIL;
|
||
FPlazosController := NIL;
|
||
inherited;
|
||
end;
|
||
|
||
function TFormasPagoController.ValidarFormaPago(AFormaPago: IBizFormaPago): Boolean;
|
||
begin
|
||
Result := False;
|
||
|
||
if not Assigned(AFormaPago) then
|
||
raise Exception.Create ('Forma de pago no asignada');
|
||
|
||
if (AFormaPago.DataTable.State in dsEditModes) then
|
||
AFormaPago.DataTable.Post;
|
||
|
||
if Length(AFormaPago.REFERENCIA) = 0 then
|
||
raise Exception.Create('Debe indicar una referencia para esta forma de pago.');
|
||
|
||
if Length(AFormaPago.DESCRIPCION) = 0 then
|
||
raise Exception.Create('Debe indicar una descripci<63>n para esta forma de pago.');
|
||
|
||
Result := True;
|
||
end;
|
||
|
||
procedure TFormasPagoController.Ver(AFormaPago: IBizFormaPago);
|
||
var
|
||
AEditor : IEditorFormaPago;
|
||
begin
|
||
AEditor := NIL;
|
||
ShowHourglassCursor;
|
||
try
|
||
CreateEditor('EditorFormaPago', IEditorFormaPago, AEditor);
|
||
with AEditor do
|
||
FormaPago := AFormaPago;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.ShowModal;
|
||
AEditor.Release;
|
||
finally
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
procedure TFormasPagoController.VerTodos(AFormasPago: IBizFormaPago);
|
||
var
|
||
AEditor : IEditorFormasPago;
|
||
begin
|
||
AEditor := NIL;
|
||
ShowHourglassCursor;
|
||
try
|
||
CreateEditor('EditorFormasPago', IEditorFormasPago, AEditor);
|
||
with AEditor do
|
||
FormasPago := AFormasPago;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
|
||
if Assigned(AEditor) then
|
||
try
|
||
AEditor.ShowModal;
|
||
AEditor.Release;
|
||
finally
|
||
AEditor := NIL;
|
||
end;
|
||
end;
|
||
|
||
function TFormasPagoController.Eliminar(AFormaPago: IBizFormaPago): Boolean;
|
||
begin
|
||
Result := False;
|
||
|
||
if not Assigned(AFormaPago) then
|
||
raise Exception.Create ('Forma de pago no asignada');
|
||
|
||
ShowHourglassCursor;
|
||
try
|
||
if (AFormaPago.State in dsEditModes) then
|
||
AFormaPago.Cancel;
|
||
|
||
AFormaPago.Delete;
|
||
AFormaPago.DataTable.ApplyUpdates;
|
||
HideHourglassCursor;
|
||
Result := True;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
procedure TFormasPagoController.RecibirAviso(ASujeto: ISujeto; ADataTable: IDAStronglyTypedDataTable);
|
||
begin
|
||
inherited;
|
||
//
|
||
end;
|
||
|
||
function TFormasPagoController.Guardar(AFormaPago: IBizFormaPago): Boolean;
|
||
begin
|
||
Result := False;
|
||
|
||
if ValidarFormaPago(AFormaPago) then
|
||
begin
|
||
ShowHourglassCursor;
|
||
try
|
||
AFormaPago.DataTable.ApplyUpdates;
|
||
Result := True;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
function TFormasPagoController.Localizar(AFormasPago: IBizFormaPago; ADescripcion: String): Boolean;
|
||
begin
|
||
Result := True;
|
||
ShowHourglassCursor;
|
||
try
|
||
with AFormasPago.DataTable do
|
||
begin
|
||
DisableControls;
|
||
First;
|
||
if not Locate(fld_FormasPagoDESCRIPCION, ADescripcion, []) then
|
||
Result := False;
|
||
EnableControls;
|
||
end;
|
||
finally
|
||
HideHourglassCursor;
|
||
end;
|
||
end;
|
||
|
||
end.
|