unit uEditorElegirAlbaranesCliente;

interface

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

type
  TfEditorElegirAlbaranesCliente = class(TfEditorAlbaranesCliente, IEditorElegirAlbaranesCliente)
    frViewBarraSeleccion1: TfrViewBarraSeleccion;
    EditorSeleccionActionList: TActionList;
    actBuscar2: TAction;
    actQuitarFiltro2: TAction;
    actAnchoAuto2: TAction;
    pnlHeader: TPanel;
    lblTitle: TLabel;
    lblComments: TLabel;
    procedure frViewBarraSeleccion1actSeleccionarUpdate(Sender: TObject);
    procedure frViewBarraSeleccion1actCancelarExecute(Sender: TObject);
    procedure frViewBarraSeleccion1actSeleccionarExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actAnchoAuto2Execute(Sender: TObject);
    procedure actQuitarFiltro2Execute(Sender: TObject);

  protected
    function GetAlbaranesClienteSeleccionados: IBizAlbaranCliente;
    procedure SetViewGrid(const Value: IViewGridBase); override;
    procedure SetMensaje (const AValue: String);
    function GetMensaje: String;

  public
    property Mensaje : String read GetMensaje write SetMensaje;
    property AlbaranesClienteSeleccionados: IBizAlbaranCliente read GetAlbaranesClienteSeleccionados;
  end;

implementation

uses
  uEditorGridBase, cxGridCustomTableView, uIntegerListUtils, uDBSelectionListUtils,
  uGridUtils, uEditorBase, uAlbaranesClienteController, cxGridLevel;

{$R *.dfm}

{ TfEditorElegirAlbaranesCliente }

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

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

procedure TfEditorElegirAlbaranesCliente.FormShow(Sender: TObject);
begin
  inherited;
  EditorActionList.State := asSuspended;
end;

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

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

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

function TfEditorElegirAlbaranesCliente.GetAlbaranesClienteSeleccionados: IBizAlbaranCliente;
begin
  SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Albaranes as ISeleccionable).SelectedRecords);
  // En SelectedRecords tengo los ID de las filas seleccionadas del grid
  Result := (Controller as IAlbaranesClienteController).ExtraerSeleccionados(Albaranes) as IBizAlbaranCliente;
end;

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

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

procedure TfEditorElegirAlbaranesCliente.SetViewGrid(const Value: IViewGridBase);
begin
  inherited;
  //Para que no salgan las pestaņas de filtrado
  ViewGrid._Grid.RootLevelOptions.DetailTabsPosition := dtpNone;
  ViewGrid.OnDblClick := frViewBarraSeleccion1.actSeleccionar.OnExecute;
end;

end.
