unit uViewEmpleado;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewContacto, dxLayoutLookAndFeels, DB, uDADataTable,
  dxLayoutControl, cxMemo, cxDBEdit, cxContainer, cxEdit, cxTextEdit, cxControls,
  cxMaskEdit, cxSpinEdit, ImgList, PngImageList, ActnList, cxHyperLinkEdit,
  Buttons, PngSpeedButton, cxDropDownEdit, cxCalendar, cxGraphics, uGruposEmpleadoController,
  uDAInterfaces;    

type
  IViewEmpleado = interface(IViewContacto)
  ['{245F4A36-39A4-4081-9826-F05FBBC729AE}']
  end;

  TfrViewEmpleado = class(TfrViewContacto, IViewEmpleado)
    eFechaNacimiento: TcxDBDateEdit;
    dxLayoutControlContactoItem16: TdxLayoutItem;
    dxLayoutControlContactoItem19: TdxLayoutItem;
    eFechaAltaEmpresa: TcxDBDateEdit;
    dxLayoutControlContactoItem20: TdxLayoutItem;
    cbCategoria: TcxDBComboBox;
    dxLayoutControlContactoItem21: TdxLayoutItem;
    cbContrato: TcxDBComboBox;
    dxLayoutControlContactoItem22: TdxLayoutItem;
    eDuracionContrato: TcxDBTextEdit;
    dxLayoutControlContactoGroup14: TdxLayoutGroup;
    dxLayoutControlContactoItem23: TdxLayoutItem;
    eFechaBaja: TcxDBDateEdit;
    dxLayoutControlContactoItem24: TdxLayoutItem;
    eCausaBaja: TcxDBTextEdit;
    procedure CustomViewCreate(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);
    procedure cbCategoriaPropertiesInitPopup(Sender: TObject);
    procedure cbCategoriaPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
    procedure cbContratoPropertiesInitPopup(Sender: TObject);
  protected
    FGrupoController: IGruposEmpleadoController;
  public
    { Public declarations }
  end;

implementation
{$R *.dfm}

uses
  uBizGruposEmpleado, uBizContactos, uEmpleadosController;

procedure TfrViewEmpleado.cbCategoriaPropertiesInitPopup(Sender: TObject);
begin
  inherited;
  with cbCategoria.Properties.Items do
  begin
    ShowHourglassCursor;
    BeginUpdate;
    try
      Clear;
      AddStrings(FGrupoController.DarListaGruposEmpleado);
    finally
      EndUpdate;
      HideHourglassCursor;
    end;
  end;
end;

procedure TfrViewEmpleado.cbCategoriaPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
var
  AGrupo : IBizGrupoEmpleado;
begin
  inherited;
  with (Sender as TcxDBComboBox) do
  begin
    if (Length(DisplayValue) > 0) and (DisplayValue <> (Contacto as IBizEmpleado).CATEGORIA) then
      if Properties.LookupItems.IndexOf(DisplayValue) < 0 then
      begin
        ShowHourglassCursor;
        Properties.LookupItems.BeginUpdate;
        AGrupo := FGrupoController.BuscarTodos;
        AGrupo.DataTable.Active := True;
        try
          FGrupoController.Anadir(AGrupo);
          AGrupo.DESCRIPCION := DisplayValue;
          FGrupoController.Guardar(AGrupo);
          Properties.LookupItems.Add(DisplayValue);
        finally
          Properties.LookupItems.EndUpdate;
          AGrupo := NIL;
          HideHourglassCursor;
        end;
      end;
  end;
end;

procedure TfrViewEmpleado.cbContratoPropertiesInitPopup(Sender: TObject);
begin
  inherited;
  with cbContrato.Properties.Items do
  begin
    ShowHourglassCursor;
    BeginUpdate;
    try
      Clear;
      AddStrings((FController as IEmpleadosController).DarListaContratosEmpleado);
    finally
      EndUpdate;
      HideHourglassCursor;
    end;
  end;
end;

procedure TfrViewEmpleado.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FGrupoController := TGruposEmpleadoController.Create;
end;

procedure TfrViewEmpleado.CustomViewDestroy(Sender: TObject);
begin
  FGrupoController := NIL;
  inherited;  
end;

end.
