unit uViewArticulos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewGrid, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, uDADataTable, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGrid, uBizArticulos, ActnList, Menus,
  cxGridBandedTableView, cxGridDBBandedTableView, JvComponent,
  JvFormAutoSize, PngImageList, ImgList, dxPSGlbl, dxPSUtl, dxPSEngn,
  dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns,
  dxPSEdgePatterns, dxPSCore, dxPScxCommon, dxPScxGrid6Lnk,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxCurrencyEdit, cxSpinEdit, cxCheckBox,
  cxCheckComboBox, cxImageComboBox, TB2Item, TBX, TB2Toolbar, TBXDkPanels,
  TB2Dock, uViewFiltroBase, dxPgsDlg, uDAInterfaces, uCustomView, uViewBase;

type
  IViewArticulos = interface(IViewGrid)
  ['{4C09BEC8-C82B-4DE8-8C36-40DB62224E95}']
    function GetArticulos: IBizArticulo;
    procedure SetArticulos(const Value: IBizArticulo);
    property Articulos: IBizArticulo read GetArticulos write SetArticulos;
  end;

  TfrViewArticulos = class(TfrViewGrid, IViewArticulos)
    PngImageList: TPngImageList;
    cxGridViewREFERENCIA: TcxGridDBColumn;
    cxGridViewDESCRIPCION: TcxGridDBColumn;
    cxGridViewFAMILIA: TcxGridDBColumn;
    cxGridViewNOMBRE_PROVEEDOR: TcxGridDBColumn;
    actFamilia: TAction;
    actProveedor: TAction;
    TBXItem2: TTBXItem;
    TBXItem3: TTBXItem;
    TBXSeparatorItem1: TTBXSeparatorItem;
    TBXSeparatorItem2: TTBXSeparatorItem;
    cxGridViewINVENTARIABLE: TcxGridDBColumn;
    cxGridViewPRECIO_PVP: TcxGridDBColumn;
    procedure cxGridViewIDCustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure actProveedorExecute(Sender: TObject);
    procedure actProveedorUpdate(Sender: TObject);
    procedure actFamiliaExecute(Sender: TObject);
    procedure actFamiliaUpdate(Sender: TObject);
    procedure cxGridViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  protected
    FArticulos: IBizArticulo;
    function GetArticulos: IBizArticulo; virtual;
    procedure SetArticulos(const Value: IBizArticulo); virtual;
  public
    property Articulos: IBizArticulo read GetArticulos write SetArticulos;
  end;

implementation
{$R *.dfm}

uses //uDataModuleArticulos,

schArticulosClient_Intf;


{ TfrViewArticulos }

{
******************************* TfrViewArticulos *******************************
}
function TfrViewArticulos.GetArticulos: IBizArticulo;
begin
  Result := FArticulos;
end;

procedure TfrViewArticulos.SetArticulos(const Value: IBizArticulo);
begin
  FArticulos := Value;
  if Assigned(FArticulos) then
    dsDataSource.DataTable := FArticulos.DataTable;
end;


procedure TfrViewArticulos.actFamiliaExecute(Sender: TObject);
begin
  if (cxGridViewFAMILIA.GroupIndex < 0) then
  begin
    cxGridViewFAMILIA.GroupIndex := cxGridView.GroupedColumnCount;
    cxGridViewFAMILIA.Visible := False;
  end
  else
  begin
    cxGridViewFAMILIA.GroupIndex := -1;
    cxGridViewFAMILIA.Visible := True;
  end;
end;

procedure TfrViewArticulos.actFamiliaUpdate(Sender: TObject);
begin
  inherited;
  (Sender as TAction).Checked := not (cxGridViewFAMILIA.GroupIndex < 0);
end;

procedure TfrViewArticulos.actProveedorExecute(Sender: TObject);
begin
  inherited;
  if (cxGridViewNOMBRE_PROVEEDOR.GroupIndex < 0) then
  begin
    cxGridViewNOMBRE_PROVEEDOR.GroupIndex := cxGridView.GroupedColumnCount;
    cxGridViewNOMBRE_PROVEEDOR.Visible := False;
  end
  else
  begin
    cxGridViewNOMBRE_PROVEEDOR.GroupIndex := -1;
    cxGridViewNOMBRE_PROVEEDOR.Visible := True;
  end;
end;

procedure TfrViewArticulos.actProveedorUpdate(Sender: TObject);
begin
  inherited;
  (Sender as TAction).Checked := not (cxGridViewNOMBRE_PROVEEDOR.GroupIndex < 0);
end;

procedure TfrViewArticulos.cxGridViewIDCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  R : TRect;
begin
  inherited;
  R := AViewInfo.ContentBounds;
  ACanvas.FillRect(R);
  ACanvas.DrawImage(PngImageList, R.Left, R.Top, 0);
  ADone := True;
end;

procedure TfrViewArticulos.cxGridViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  Site     : TcxGridSite;
  HitTest  : TcxCustomGridHitTest;
  Item     : TcxCustomGridTableItem;
  Rec      : TcxCustomGridRecord;
  sNewHint : string;
begin
{Este método desaparecerá cuando se migre la aplicación, es para sacar la causa de la incidencia sin necesidad de entrar en el documento}
  Site := Sender as TcxGridSite;
  HitTest := Site.GridView.ViewInfo.GetHitTest(X, Y);
  if HitTest is TcxGridRecordCellHitTest then
  begin
    Item := TcxGridRecordCellHitTest(HitTest).Item;
    Rec := TcxGridRecordCellHitTest(HitTest).GridRecord;

    if  (Item.Index = cxGridView.GetColumnByFieldName(fld_ArticulosCOMISIONABLE).Index) then begin
      sNewHint := 'Todo artículo comisionable se tendrá en cuenta para la liquidación de comisiones de los agentes';
      if (cxGrid.Hint <> sNewHint) then begin
        cxGrid.ShowHint := false;
        cxGrid.Hint     := sNewHint;
      end
      else cxGrid.ShowHint := true;
    end
    else if  (Item.Index = cxGridView.GetColumnByFieldName(fld_ArticulosINVENTARIABLE).Index) then begin
      sNewHint := 'Todo artículo inventariable se tendrá en cuenta para el control de almacenes (inventario de almacén)';
      if (cxGrid.Hint <> sNewHint) then begin
        cxGrid.ShowHint := false;
        cxGrid.Hint     := sNewHint;
      end
      else cxGrid.ShowHint := true;
    end
    else begin
      cxGrid.ShowHint := false;
    end;
  end;
end;

end.
