78 lines
2.5 KiB
ObjectPascal
78 lines
2.5 KiB
ObjectPascal
unit uBizPresupuestosClienteServer;
|
|
|
|
interface
|
|
|
|
uses
|
|
schPresupuestosClienteServer_Intf, uDAInterfaces, uDADelta,
|
|
uDADataTable, uDABusinessProcessor;
|
|
|
|
const
|
|
BIZ_SERVER_PRESUPUESTOS_CLIENTE = 'Server.PresupuestosCliente';
|
|
REF_PRESUPUESTOS_CLIENTE = 'REF_PRESUPUESTOS_CLIENTE';
|
|
|
|
type
|
|
TBizPresupuestosClienteServer = class(TPresupuestosClienteBusinessProcessorRules)
|
|
protected
|
|
procedure BeforeProcessDelta(Sender: TDABusinessProcessor; const aDelta: IDADelta); override;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Dialogs, SysUtils, Variants, uDataModuleServer, uDAClasses, DARemoteService_Impl,
|
|
schPresupuestosClienteClient_Intf, uBusinessUtils, uReferenciasUtils, uROClasses;
|
|
|
|
{ TBizPresupuestosClienteServer }
|
|
|
|
|
|
procedure TBizPresupuestosClienteServer.BeforeProcessDelta(
|
|
Sender: TDABusinessProcessor; const aDelta: IDADelta);
|
|
var
|
|
ASchema : TDASchema;
|
|
ACurrentConn : IDAConnection;
|
|
dsData: IDADataset;
|
|
Empresa : Variant;
|
|
|
|
begin
|
|
inherited;
|
|
|
|
case Sender.CurrentChange.ChangeType of
|
|
ctInsert, ctUpdate: begin
|
|
//Si la referencia no ha sido asignada le asignamos una nosotros
|
|
if (VarIsNull(Sender.CurrentChange.NewValueByName[fld_PresupuestosClienteREFERENCIA]))
|
|
or (VarToStr(Sender.CurrentChange.NewValueByName[fld_PresupuestosClienteREFERENCIA]) = '') then
|
|
begin
|
|
ASchema := BusinessProcessor.Schema;
|
|
ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);
|
|
|
|
try
|
|
//Siempre va a estar rellena
|
|
Empresa := Sender.CurrentChange.NewValueByName[fld_PresupuestosClienteID_EMPRESA];
|
|
dsData := ASchema.NewDataset(ACurrentConn, 'DarReferencia', ['CODIGO', 'EMPRESA'], [REF_PRESUPUESTOS_CLIENTE, Empresa]);
|
|
except
|
|
RaiseError('No existe la tabla REFERENCIAS');
|
|
end;
|
|
|
|
dsData.Active := True;
|
|
|
|
if dsData.IsEmpty then
|
|
RaiseError('NO HAY REFERENCIA ' + REF_PRESUPUESTOS_CLIENTE + ' DECLARADA EN TABLA REFERENCIAS');
|
|
|
|
REFERENCIA := dsData.FieldByName(fld_DarReferenciaVALOR).AsString;
|
|
|
|
try
|
|
ASchema.NewCommand(ACurrentConn, 'ModificarReferencia', ['CODIGO', 'VALOR', 'EMPRESA'], [REF_PRESUPUESTOS_CLIENTE, DarReferenciaSiguiente(REFERENCIA), Empresa]);
|
|
except
|
|
RaiseError('Error al asignar la nueva ' + REFERENCIA + ' referencia en tabla');
|
|
end;
|
|
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
RegisterBusinessProcessorRules(BIZ_SERVER_PRESUPUESTOS_CLIENTE, TBizPresupuestosClienteServer);
|
|
|
|
end.
|