unit uBizContactosPersonal;

interface

uses
  uDAInterfaces, uDADataTable,
  schContactosClient_Intf;

const
  BIZ_CLIENT_CONTACTO_PERSONAL = 'Client.ContactosPersonal';

type
  IBizContactoPersonal = interface (IPersonalContacto)
    ['{9FFEFD2E-1EED-4FA2-80D7-81B1541B122C}']
  end;

  TBizContactoPersonal = class(TPersonalContactoDataTableRules, IBizContactoPersonal)
  private
    ContIdAux: Integer;
  protected
    procedure OnNewRecord(Sender: TDADataTable); override;
    procedure BeforeInsert(Sender: TDADataTable); override;    
  public
    constructor Create(aDataTable: TDADataTable); override;
  end;

implementation

{ TBizContactoPersonal }

uses
  DB;

procedure TBizContactoPersonal.BeforeInsert(Sender: TDADataTable);
var
  AMasterTable : TDADataTable;
begin
  inherited;
  AMasterTable := DataTable.GetMasterDataTable;
  if Assigned(AMasterTable) and (AMasterTable.State in dsEditModes) then
    AMasterTable.Post;
end;

constructor TBizContactoPersonal.Create(aDataTable: TDADataTable);
begin
  inherited;
  ContIdAux := -1;
end;

procedure TBizContactoPersonal.OnNewRecord(Sender: TDADataTable);
begin
  inherited;
  ID := ContIdAux; // -1, -2, -3...
  Dec(ContIdAux);
end;

initialization
  RegisterDataTableRules(BIZ_CLIENT_CONTACTO_PERSONAL, TBizContactoPersonal);

end.

