unit uEditorPersonal;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, ExtCtrls, Mask, DBCtrls, DB, uDADataTable, PngSpeedButton,
  cxControls, cxContainer, cxEdit, cxTextEdit, cxHyperLinkEdit, cxDBEdit,
  uPersonalContactoController, uBizContactosPersonal,
  uDAInterfaces, uIEditorPersonalContacto;

type
  TfEditorPersonal = class(TForm, IEditorPersonalContacto)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    dsPersonal: TDADataSource;
    Label5: TLabel;
    eNombre: TDBEdit;
    Label6: TLabel;
    ePuesto: TDBEdit;
    Label7: TLabel;
    eTelefono: TDBEdit;
    Label11: TLabel;
    eMovil: TDBEdit;
    Label12: TLabel;
    eFax: TDBEdit;
    eMail: TcxDBHyperLinkEdit;
    PngSpeedButton3: TPngSpeedButton;
    Label8: TLabel;
    procedure PngSpeedButton3Click(Sender: TObject);
    procedure eMailPropertiesEditValueChanged(Sender: TObject);
    procedure eMailPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
    procedure CancelBtnClick(Sender: TObject);
  protected
    FController : IPersonalContactoController;
    FPersonal: IBizContactoPersonal;
  
    function GetController : IPersonalContactoController;
    procedure SetController (const Value : IPersonalContactoController);
    function GetPersonal: IBizContactoPersonal;
    procedure SetPersonal(const Value: IBizContactoPersonal);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Controller : IPersonalContactoController read GetController
      write SetController;
    property Personal: IBizContactoPersonal read GetPersonal write SetPersonal;
  end;

implementation

uses
  Variants;

type
  THackcxDBHyperLinkEdit = class(TcxDBHyperLinkEdit);

{$R *.dfm}

{ TfEditorPersonal }

procedure TfEditorPersonal.CancelBtnClick(Sender: TObject);
begin
  if FPersonal.DataTable.Editing then 
    FPersonal.Cancel;
end;

constructor TfEditorPersonal.Create(AOwner: TComponent);
begin
  inherited;
  FController := NIL;
end;

destructor TfEditorPersonal.Destroy;
begin
  FController := NIL;
  inherited;
end;

procedure TfEditorPersonal.eMailPropertiesEditValueChanged(Sender: TObject);
begin
  if not VarIsNull((Sender as TcxDBHyperLinkEdit).EditValue) then
     (Sender as TcxDBHyperLinkEdit).EditValue := StringReplace((Sender as TcxDBHyperLinkEdit).EditValue, (Sender as TcxDBHyperLinkEdit).Properties.Prefix, '', []);
end;

procedure TfEditorPersonal.eMailPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
  if not VarIsNull(DisplayValue) then
     DisplayValue := StringReplace(DisplayValue, (Sender as TcxDBHyperLinkEdit).Properties.Prefix, '', []);
end;

function TfEditorPersonal.GetController: IPersonalContactoController;
begin
  Result := FController;
end;

function TfEditorPersonal.GetPersonal: IBizContactoPersonal;
begin
  Result := FPersonal;
end;

procedure TfEditorPersonal.PngSpeedButton3Click(Sender: TObject);
begin
  THackcxDBHyperLinkEdit(eMail).DoStart;
end;

procedure TfEditorPersonal.SetController(
  const Value: IPersonalContactoController);
begin
  FController := Value;
end;

procedure TfEditorPersonal.SetPersonal(const Value: IBizContactoPersonal);
begin
  FPersonal := Value;
  if Assigned(FPersonal) then
    dsPersonal.DataTable := FPersonal.DataTable
  else
    dsPersonal.DataTable := NIL;
end;

end.
