unit uEditorControlStockVARELA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorControlBase, DB, uDADataTable, JvAppStorage,
  JvAppRegistryStorage, JvComponentBase, JvFormPlacement, ImgList,
  PngImageList, StdActns, ActnList, ComCtrls, TBX, TB2Item, TB2Dock,
  TB2Toolbar, ExtCtrls, JvExControls, JvComponent, JvNavigationPane,
  uCustomView, uViewBase, uViewControlBase, Grids, DBGrids, pngimage, StdCtrls,
  uEditorGridBase, uViewGridBase, uViewGrid, Menus, TB2ExtItems, TBXExtItems,
  uBizStock, uViewControGridStockVARELA, uViewControlGrid;

type
  IEditorControlStockVARELA = interface(IEditorGridBase)
  ['{E73FFD61-E345-43EF-A3D1-56B8A5D3DA8B}']
    function GetItems: IBizStockVARELA;
    procedure SetItems(const Value: IBizStockVARELA);
    property Items: IBizStockVARELA read GetItems write SetItems;
  end;

  TfEditorControlStockVARELA = class(TfEditorGridBase, IEditorControlStockVARELA)
    dsVentasTerminadas: TDADataSource;
    TBXSeparatorItem16: TTBXSeparatorItem;
    tbxiExpandir: TTBXItem;
    tbxiContraer: TTBXItem;
    tbxiAnchoAuto: TTBXItem;
    actExpandir: TAction;
    actContraer: TAction;
    actAnchoAuto: TAction;
    TBXItem37: TTBXItem;
    TBXItem36: TTBXItem;
    TBXItem35: TTBXItem;
    TBXSeparatorItem17: TTBXSeparatorItem;
    frViewControlGridStockVARELA1: TfrViewControlGridStockVARELA;
    procedure actAnchoAutoExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actPrevisualizarExecute(Sender: TObject);
    procedure actImprimirExecute(Sender: TObject);
    procedure actExpandirExecute(Sender: TObject);
    procedure actContraerExecute(Sender: TObject);
  private
    property ViewGrid;
  protected
    FItems : IBizStockVARELA;
    function GetItems: IBizStockVARELA;
    procedure SetItems(const Value: IBizStockVARELA);
  public
    property Items: IBizStockVARELA read GetItems write SetItems;
    constructor Create(AOwner: TComponent); override;
  end;


implementation

uses
  cxControls, uEditorUtils, DateUtils, uCustomEditor, uEditorBase;

{$R *.dfm}

{ TfEditorControlStockEDI }

procedure TfEditorControlStockVARELA.actAnchoAutoExecute(Sender: TObject);
begin
  inherited;
  frViewControlGridStockVARELA1.AjustarAncho;
end;

procedure TfEditorControlStockVARELA.FormShow(Sender: TObject);
begin
  inherited;

  if not Assigned(FItems) then
    raise Exception.Create('No hay items asignados');

  if not Assigned(ViewGrid) then
    raise Exception.Create('No hay una vista asignada');

  ViewGrid.ExpandirTodo;
end;

procedure TfEditorControlStockVARELA.actImprimirExecute(Sender: TObject);
begin
  frViewControlGridStockVARELA1.Print;
end;

constructor TfEditorControlStockVARELA.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewControlGridStockVARELA1;
  Self.Caption := 'Control de stock de almacén';
  JvNavPanelHeader.Caption := Self.Caption;
end;

function TfEditorControlStockVARELA.GetItems: IBizStockVARELA;
begin
  Result := FItems;
end;

procedure TfEditorControlStockVARELA.SetItems(const Value: IBizStockVARELA);
begin
  FItems := Value;
  if Assigned(FItems) then
  begin
    dsDataTable.DataTable := FItems.DataTable;
    frViewControlGridStockVARELA1.dsDataSource.DataTable := FItems.DataTable;

    if not FItems.DataTable.Active then
       FItems.DataTable.Active := True;

    actAnchoAuto.Execute;   
  end;
end;

procedure TfEditorControlStockVARELA.actPrevisualizarExecute(Sender: TObject);
begin
  frViewControlGridStockVARELA1.Preview;
end;

procedure TfEditorControlStockVARELA.actExpandirExecute(Sender: TObject);
begin
  inherited;
  ViewGrid.ExpandirTodo;
end;

procedure TfEditorControlStockVARELA.actContraerExecute(Sender: TObject);
begin
  inherited;
  ViewGrid.ContraerTodo;
end;

end.

