unit uBizClientesServer;

interface

uses
  schContactosServer_Intf, uDAInterfaces,
  uDADataTable, uDABusinessProcessor, uBizContactosServer;

const
  BIZ_SERVER_CLIENTE = 'Server.Cliente';

type
  TBizClienteServer = class(TBizContactosServer)
  protected
    procedure Insert_Datos_Contacto(aChange: TDADeltaChange); override;
    procedure Update_Datos_Contacto(aChange: TDADeltaChange); override;
    procedure Delete_Datos_Contacto(aChange: TDADeltaChange); override;
  end;

implementation

uses
  uDataModuleServer, uDAClasses, DARemoteService_Impl,
  schContactosClient_Intf, uBusinessUtils;

{ TBizClienteServer }

procedure TBizClienteServer.Delete_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;
  
  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Delete_ClientesDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_CLIENTE').Value := aChange.OldValueByName[fld_ClientesID];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

procedure TBizClienteServer.Insert_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;
  
  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Insert_ClientesDatos');
  try
    with ACommand do
    begin
      ParamByName('ID_CLIENTE').Value := aChange.NewValueByName[fld_ClientesID];
      ParamByName('ID_VENDEDOR').Value := aChange.NewValueByName[fld_ClientesID_VENDEDOR];
      ParamByName('PROCEDENCIA').Value := aChange.NewValueByName[fld_ClientesPROCEDENCIA];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;


procedure TBizClienteServer.Update_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;
  
  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Update_ClientesDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_CLIENTE').Value := aChange.OldValueByName[fld_ClientesID];
      ParamByName('ID_CLIENTE').Value := aChange.NewValueByName[fld_ClientesID];
      ParamByName('ID_VENDEDOR').Value := aChange.NewValueByName[fld_ClientesID_VENDEDOR];
      ParamByName('PROCEDENCIA').Value := aChange.NewValueByName[fld_ClientesPROCEDENCIA];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

initialization
  RegisterBusinessProcessorRules(BIZ_SERVER_CLIENTE, TBizClienteServer);

end.
