unit uViewControGridStockVARELA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewControlGrid, DB, uDADataTable, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
  cxTextEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxCurrencyEdit, cxCalendar, dxPSGlbl, dxPSUtl, dxPrnPg, dxBkgnd, dxWrap,
  dxPrnDev, dxPSEngn, dxPSCompsProvider, dxPSFillPatterns,
  dxPSEdgePatterns, dxPSCore, dxPScxCommon, dxPScxGridLnk, dxPgsDlg,
  cxDropDownEdit, StdCtrls, cxSpinEdit, uViewGrid, cxMemo,
  cxEditRepositoryItems, uDataModuleStock, uCustomView, uViewBase,
  uViewParametrosControlGrid, uDAInterfaces, TBXDkPanels,
  uViewParametrosColeccion, TB2Dock, uBizStock;

type
  IViewControlGridStockVARELA = interface(IViewGrid)
  ['{19831B1A-1D3B-4352-A848-52B00BFEF4EF}']
    function GetItems: IBizStockVARELA;
    procedure SetItems(const Value: IBizStockVARELA);
    property Items: IBizStockVARELA read GetItems write SetItems;
  end;

  TfrViewControlGridStockVARELA = class(TfrViewGrid, IViewControlGridStockVARELA)
    dxComponentPrinterLink1: TdxGridReportLink;
    cxGridViewRecID: TcxGridDBColumn;
    cxGridViewFILIAL: TcxGridDBColumn;
    cxGridViewCODIGO: TcxGridDBColumn;
    cxGridViewCOLOR: TcxGridDBColumn;
    cxGridViewPRODUCTO: TcxGridDBColumn;
    cxGridViewTIPO_PRODUTO: TcxGridDBColumn;
    cxGridViewGRUPO_PRODUTO: TcxGridDBColumn;
    cxGridViewCOLECCION: TcxGridDBColumn;
    cxGridViewK38: TcxGridDBColumn;
    cxGridViewK40: TcxGridDBColumn;
    cxGridViewK42: TcxGridDBColumn;
    cxGridViewK44: TcxGridDBColumn;
    cxGridViewK46: TcxGridDBColumn;
    cxGridViewK48: TcxGridDBColumn;
    cxGridViewKT: TcxGridDBColumn;
    cxStyleEntrada: TcxStyle;
    cxStyleSalida: TcxStyle;
    cxStyleRepositoryInforme: TcxStyleRepository;
    cxStyleContentInforme: TcxStyle;
    cxStyleFooterInforme: TcxStyle;
    cxStyleGroupInforme: TcxStyle;
    cxStyleHeaderInforme: TcxStyle;
    cxStyleSelectionInforme: TcxStyle;
    cxStyleTotales: TcxStyle;
    TBXDockablePanel1: TTBXDockablePanel;
    frViewParametrosColeccion1: TfrViewParametrosColeccion;
    pnlAgrupaciones: TTBXAlignmentPanel;
    TBXButton3: TTBXButton;
    TBXLabel1: TTBXLabel;
    procedure cxGridViewKTCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure cxGridViewK38GetDataText(Sender: TcxCustomGridTableItem;
      ARecordIndex: Integer; var AText: String);
    procedure cxGridViewKTStylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
  protected
    FItems : IBizStockVARELA;
    function GetFocusedView : TcxGridDBTableView; override;
    function GetItems: IBizStockVARELA;
    procedure SetItems(const Value: IBizStockVARELA);

  public
    procedure Refresh;
    property Items: IBizStockVARELA read GetItems write SetItems;
    procedure Preview; override;
    procedure Print; override;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation
{$R *.dfm}

uses uViewGridBase;

{ TfrViewControlGridResumenVentas }

procedure TfrViewControlGridStockVARELA.Preview;
begin
  inherited; 
  dxComponentPrinterLink1.ReportTitle.Text := 'Control de stock en almacén';
  dxComponentPrinterLink1.Preview;
end;

procedure TfrViewControlGridStockVARELA.Print;
begin
  inherited;
  dxComponentPrinterLink1.ReportTitle.Text := 'Control de stock en almacén';
  dxComponentPrinterLink1.Print(True, Nil);
end;

procedure TfrViewControlGridStockVARELA.Refresh;
var
  AColeccionesList : TStringList;
  AWhere : String;
  i : integer;
begin
  AWhere := '';
  AWhere := AWhere + ' COLECCION in (';

  Items.DataTable.Active := False;
  AColeccionesList := frViewParametrosColeccion1.ColeccionesSeleccionadas;

  ShowHourglassCursor;
  try
    if AColeccionesList.Count = 0 then
      ShowMessage('Debe seleccionar al menos una colección en los parámetros de la consulta.')
    else begin
      with Items.DataTable.Where do
      begin
        Clear;
        for i := 0 to AColeccionesList.Count - 1 do
        begin
          if i > 0 then
            AWhere := AWhere + ', ';
          AWhere := AWhere + '''' + AColeccionesList[i] + '''';
        end;
        AWhere := AWhere + ')';
        AddText(AWhere, False);
      end;
      Items.DataTable.Active := True;
    end;
  finally
    HideHourglassCursor;
    FreeAndNIL(AColeccionesList);
  end;
end;

procedure TfrViewControlGridStockVARELA.cxGridViewKTCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
  if not VarIsNull(AViewInfo.Value) then
    if Pos('-', AViewInfo.Value) > 0 then
       ACanvas.Canvas.Font.Color := $000000CC;
end;

constructor TfrViewControlGridStockVARELA.Create(AOwner: TComponent);
begin
  inherited;
  FItems := Nil;
  frViewParametrosColeccion1.Refresh;
end;

function TfrViewControlGridStockVARELA.GetFocusedView: TcxGridDBTableView;
begin
  Result := cxGridView;
end;

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

procedure TfrViewControlGridStockVARELA.SetItems(const Value: IBizStockVARELA);
begin
  FItems := Value;
  if Assigned(FItems) then
     dsDataSource.DataTable := FItems.DataTable;
end;

procedure TfrViewControlGridStockVARELA.cxGridViewK38GetDataText(
  Sender: TcxCustomGridTableItem; ARecordIndex: Integer;
  var AText: String);
begin
  inherited;
  ShowMessage(AText);
  if AText = '0' then
    AText := '';
end;

procedure TfrViewControlGridStockVARELA.cxGridViewKTStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  inherited;
  AStyle := cxStyleTotales;
end;

destructor TfrViewControlGridStockVARELA.Destroy;
begin
  FItems := Nil;
  inherited;
end;

end.

