unit uBizEmpleadosServer;

interface

uses
  schContactosServer_Intf, uDAInterfaces, uDADelta,
  uDADataTable, uDABusinessProcessor, uBizContactosServer;

const
  BIZ_SERVER_EMPLEADO = 'Server.Empleado';

type
  TBizEmpleadoServer = class(TBizContactosServer)
  protected
    function DarReferenciaContacto : String; override;
    function IncrementarReferenciaContacto : Boolean; override;
  
    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, 
  schContactosClient_Intf, uBusinessUtils;

const
  REF_EMPLEADOS = 'REF_EMPLEADOS';

{ TBizEmpleadoServer }

function TBizEmpleadoServer.DarReferenciaContacto: String;
begin
  Result := _DarReferenciaInterna(REF_EMPLEADOS)
end;

procedure TBizEmpleadoServer.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_EmpleadosDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_EMPLEADO').Value := aChange.OldValueByName[fld_EmpleadosID];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

function TBizEmpleadoServer.IncrementarReferenciaContacto: Boolean;
begin
  Result := _IncrementarReferenciaInterna(REF_EMPLEADOS)
end;

procedure TBizEmpleadoServer.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_EmpleadosDatos');
  try
    with ACommand do
    begin
      ParamByName('ID_EMPLEADO').Value := aChange.NewValueByName[fld_EmpleadosID];
      ParamByName('FECHA_NACIMIENTO').Value := aChange.NewValueByName[fld_EmpleadosFECHA_NACIMIENTO];
      ParamByName('CATEGORIA').Value := aChange.NewValueByName[fld_EmpleadosCATEGORIA];
      ParamByName('FECHA_ALTA_EMPRESA').Value := aChange.NewValueByName[fld_EmpleadosFECHA_ALTA_EMPRESA];
      ParamByName('FORMACION_BASE').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_BASE];
      ParamByName('FORMACION_COMPLE').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_COMPLE];
      ParamByName('FORMACION_RECIBIDA').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_RECIBIDA];
      ParamByName('EXPERIENCIA').Value := aChange.NewValueByName[fld_EmpleadosEXPERIENCIA];
      ParamByName('CONTRATO').Value := aChange.NewValueByName[fld_EmpleadosCONTRATO];
      ParamByName('DURACION').Value := aChange.NewValueByName[fld_EmpleadosDURACION];
      ParamByName('FECHA_BAJA').Value := aChange.NewValueByName[fld_EmpleadosFECHA_BAJA];
      ParamByName('CAUSA_BAJA').Value := aChange.NewValueByName[fld_EmpleadosCAUSA_BAJA];            
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

procedure TBizEmpleadoServer.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_EmpleadosDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_EMPLEADO').Value := aChange.OldValueByName[fld_EmpleadosID];
      ParamByName('FECHA_NACIMIENTO').Value := aChange.NewValueByName[fld_EmpleadosFECHA_NACIMIENTO];
      ParamByName('CATEGORIA').Value := aChange.NewValueByName[fld_EmpleadosCATEGORIA];
      ParamByName('FECHA_ALTA_EMPRESA').Value := aChange.NewValueByName[fld_EmpleadosFECHA_ALTA_EMPRESA];
      ParamByName('FORMACION_BASE').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_BASE];
      ParamByName('FORMACION_COMPLE').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_COMPLE];
      ParamByName('FORMACION_RECIBIDA').Value := aChange.NewValueByName[fld_EmpleadosFORMACION_RECIBIDA];
      ParamByName('EXPERIENCIA').Value := aChange.NewValueByName[fld_EmpleadosEXPERIENCIA];
      ParamByName('CONTRATO').Value := aChange.NewValueByName[fld_EmpleadosCONTRATO];
      ParamByName('DURACION').Value := aChange.NewValueByName[fld_EmpleadosDURACION];
      ParamByName('FECHA_BAJA').Value := aChange.NewValueByName[fld_EmpleadosFECHA_BAJA];
      ParamByName('CAUSA_BAJA').Value := aChange.NewValueByName[fld_EmpleadosCAUSA_BAJA];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

initialization
  RegisterBusinessProcessorRules(BIZ_SERVER_EMPLEADO, TBizEmpleadoServer);

end.
