unit uEditorElegirPacientes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorPacientes, DB, uDADataTable, Menus, JvAppStorage,
  JvAppRegistryStorage, JvComponentBase, JvFormPlacement, ImgList, PngImageList,
  StdActns, ActnList, uCustomView, uViewBase, uViewGridBase, uViewGrid,
  uViewContactos, uViewPacientes, ComCtrls, TB2ExtItems, TBXExtItems, TBX,
  TB2Item, TB2Dock, TB2Toolbar, pngimage, ExtCtrls, JvExControls, JvComponent,
  JvNavigationPane, uIEditorElegirPacientes, uViewBarraSeleccion,
  StdCtrls, uBizContactos, TBXStatusBars, JvExComCtrls, JvStatusBar, JSDialog,
  uDAInterfaces;

type
  TfEditorElegirPacientes = class(TfEditorPacientes, IEditorElegirPacientes)
    frViewBarraSeleccion1: TfrViewBarraSeleccion;
    lblTitle: TLabel;
    lblComments: TLabel;
    EditorSeleccionActionList: TActionList;
    actBuscar2: TAction;
    actQuitarFiltro2: TAction;
    actAnchoAuto2: TAction;
    pnlHeader: TPanel;
    procedure frViewBarraSeleccion1actSeleccionarUpdate(Sender: TObject);
    procedure frViewBarraSeleccion1actCancelarExecute(Sender: TObject);
    procedure frViewBarraSeleccion1actSeleccionarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actQuitarFiltro2Execute(Sender: TObject);
    procedure actAnchoAuto2Execute(Sender: TObject);
  protected
    procedure SetMultiSelect (AValue : Boolean);
    function GetMultiSelect : Boolean;
    function GetContactosSeleccionados: IBizContacto;
    procedure SetViewGrid(const Value: IViewGridBase); override;
    procedure SetMensaje (const AValue: String);
    function GetMensaje: String;
  public
    property Mensaje : String read GetMensaje write SetMensaje;
    property ContactosSeleccionados: IBizContacto read GetContactosSeleccionados;
    property MultiSelect : Boolean read GetMultiSelect write SetMultiSelect;
  end;

implementation

uses
  uEditorGridBase, cxGridCustomTableView, uIntegerListUtils, uEditorContactos,
  uGridStatusUtils, uEditorBase, cxControls, uDBSelectionListUtils;

{$R *.dfm}

{ TfEditorElegirPacientes }

procedure TfEditorElegirPacientes.actAnchoAuto2Execute(Sender: TObject);
begin
  inherited;
  actAnchoAuto.Execute;
end;

procedure TfEditorElegirPacientes.actQuitarFiltro2Execute(Sender: TObject);
begin
  inherited;
  actQuitarFiltro.Execute;
end;

procedure TfEditorElegirPacientes.FormShow(Sender: TObject);
begin
  inherited;
  EditorActionList.State := asSuspended;
  frViewPacientes1.cxViewGridPopupMenu.PopupMenus.Items[0].HitTypes := [];
end;

procedure TfEditorElegirPacientes.frViewBarraSeleccion1actCancelarExecute(
  Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfEditorElegirPacientes.frViewBarraSeleccion1actSeleccionarExecute(
  Sender: TObject);
begin
  inherited;
  ModalResult := mrOk;
end;

procedure TfEditorElegirPacientes.frViewBarraSeleccion1actSeleccionarUpdate(
  Sender: TObject);
begin
  inherited;
  (Sender as TAction).Enabled := (ViewGrid._FocusedView.Controller.SelectedRowCount > 0)
end;

function TfEditorElegirPacientes.GetContactosSeleccionados: IBizContacto;
begin
  ShowHourglassCursor;
  try
    SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords);
    // En Contactos.SelectedRecords tengo los ID de las filas seleccionadas del grid
    Result := Controller.ExtraerSeleccionados(Contactos);
  finally
    HideHourglassCursor;
  end;
end;

function TfEditorElegirPacientes.GetMensaje: String;
begin
  Result := lblComments.Caption;
end;

function TfEditorElegirPacientes.GetMultiSelect: Boolean;
begin
  Result := ViewGrid.MultiSelect;  
end;

procedure TfEditorElegirPacientes.SetMensaje(const AValue: String);
begin
  lblComments.Caption := AValue;
end;

procedure TfEditorElegirPacientes.SetMultiSelect(AValue: Boolean);
begin
  ViewGrid.MultiSelect := AValue;
end;

procedure TfEditorElegirPacientes.SetViewGrid(const Value: IViewGridBase);
begin
  inherited;
  ViewGrid.OnDblClick := frViewBarraSeleccion1.actSeleccionar.OnExecute;
end;

end.
