This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES/Source/Modulos/Formas de pago/Controller/uFormasPagoPlazosController.pas
2007-06-11 15:29:06 +00:00

114 lines
3.0 KiB
ObjectPascal

unit uFormasPagoPlazosController;
interface
uses
Windows, Forms, Classes, Controls, Contnrs, SysUtils, uDADataTable,
uBizFormasPago, uBizFormasPagoPlazos, uIDataModuleFormasPago;
type
IFormasPagoPlazosController = interface
['{3FCE2A31-9783-45F9-96D6-1157165AB8DB}']
procedure AsignarID(ADetalles: IBizFormaPagoPlazos; IDCabecera: Integer; AEsNuevo:Boolean);
end;
TFormasPagoPlazosController = class(TInterfacedObject, IFormasPagoPlazosController)
private
FDataModule : IDataModuleFormasPago;
public
procedure AsignarID(ADetalles: IBizFormaPagoPlazos; IDCabecera: Integer; AEsNuevo:Boolean);
constructor Create; virtual;
destructor Destroy; override;
end;
implementation
{ TFormasPagoPlazosController }
uses
uDataModuleFormasPago, uEditorRegistryUtils,
cxControls, schFormasPagoClient_Intf;
procedure TFormasPagoPlazosController.AsignarID(
ADetalles: IBizFormaPagoPlazos; IDCabecera: Integer;
AEsNuevo: Boolean);
begin
with ADetalles do
begin
DataTable.DisableControls;
try
if not DataTable.Active then
DataTable.Active := True;
// AuxPosicion := POSICION;
{ ¡¡¡¡ OJO !!!!
Para asignar el ID en los detalles hay
que tener en cuenta una cosa:
Si se cambia el ID, ese detalle ya no
pertenece a esa cabecera porque ya no se
cumple la condición de la relacion:
Master.ID = Detail.ID_PRESUPUESTO.
Por esa razón no sirve hacer un recorrido
desde el principio hasta el final porque
las detalles van desapareciendo según asignamos
el valor al campo ID y nos mueve aleatoriamente
la posición del registro actual.
Es mejor hacer un bucle sencillo hasta que
"se gasten" todos los detalles. Cuando el
RecordCount llegue a 0 quiere decir que hemos
tratado todos los detalles.
El bucle cambia en el caso de ser llamada esta funcion desde modificar
un presupuesto ya que en ese caso si que hay que hacer un recorrido
total de las tuplas de detalle.
}
if AEsNuevo then
begin
while RecordCount > 0 do
begin
DataTable.First;
Edit;
ID := FDataModule.GetNextID(DataTable.LogicalName);
ID_FORMA_PAGO := IDCabecera;
Post
end
end
else
begin
DataTable.First;
while not DataTable.EOF do
begin
if ADetalles.EsNuevo then
begin
Edit;
ID := FDataModule.GetNextID(DataTable.LogicalName);
ID_FORMA_PAGO := IDCabecera;
Post
end;
DataTable.Next
end;
end;
finally
DataTable.EnableControls;
end;
end;
end;
constructor TFormasPagoPlazosController.Create;
begin
inherited;
FDataModule := TDataModuleFormasPago.Create(Nil);
end;
destructor TFormasPagoPlazosController.Destroy;
begin
FDataModule := Nil;
inherited;
end;
end.