unit uPersonalContactoController;

interface

uses
  Windows, Forms, Classes, Controls, Contnrs, SysUtils, uDADataTable,
  uBizContactos, uBizContactosPersonal, uIDataModuleContactos,
  uControllerBase;

type
  IPersonalContactoController = interface(IControllerBase)
  ['{2A848939-9558-40DA-9886-F34D72331DA9}']
    procedure Ver(APersonal : IBizContactoPersonal);
    function Localizar(APersonal: IBizContactoPersonal; const ID : Integer): Boolean;    
  end;

  TPersonalContactoController = class(TControllerBase, IPersonalContactoController)
  private
    FDataModule : IDataModuleContactos;
  public
    procedure Ver(APersonal : IBizContactoPersonal);
    function Localizar(APersonal: IBizContactoPersonal; const ID : Integer): Boolean;
    constructor Create; override;
    destructor Destroy; override;
  end;

implementation

{ TPersonalContactoController }

uses
  uDataModuleContactos, schContactosClient_Intf, uIEditorPersonalContacto,
  uEditorRegistryUtils, cxControls;

constructor TPersonalContactoController.Create;
begin
  inherited;
  FDataModule := TDataModuleContactos.Create(Nil);
end;

destructor TPersonalContactoController.Destroy;
begin
  FDataModule := Nil;
  inherited;
end;

function TPersonalContactoController.Localizar(
  APersonal: IBizContactoPersonal; const ID: Integer): Boolean;
begin
  Result := True;
  ShowHourglassCursor;
  try
    with APersonal.DataTable do
    begin
      DisableControls;
      First;
      if not Locate(fld_PersonalContactoID, ID, []) then
         Result := False;
      EnableControls;
    end;
  finally
    HideHourglassCursor;
  end;
end;

procedure TPersonalContactoController.Ver(
  APersonal: IBizContactoPersonal);
var
  AEditor : IEditorPersonalContacto;
begin
  AEditor := NIL;	

  CreateEditor('EditorPersonalContacto', IEditorPersonalContacto, AEditor);
  if Assigned(AEditor) then
    try
      AEditor.Personal := APersonal;
      AEditor.Controller := Self;
      AEditor.ShowModal;
    finally
      AEditor.Release;
    end;
end;

end.
