unit uViewDetallesArticulosParaVenta;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewDetallesArticulos, cxStyles,  
  cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, cxCheckBox, cxImageComboBox,
  cxButtonEdit, cxRichEdit, cxMaskEdit, cxDropDownEdit, cxCurrencyEdit,
  cxEditRepositoryItems, Menus, cxGridCustomPopupMenu, cxGridPopupMenu, ImgList,
  PngImageList, uDAInterfaces, uDADataTable, StdActns, ExtActns, ActnList,
  TB2Item, TBX, TB2Dock, TB2Toolbar, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, ComCtrls, StdCtrls, JvExStdCtrls, JvCombobox, JvColorCombo, ToolWin;

type
  TfrViewDetallesArticulosParaVenta = class(TfrViewDetallesArticulos)
    procedure OnIMPORTEUNIDADGetProperties(Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
      var AProperties: TcxCustomEditProperties);
    procedure CustomViewDestroy(Sender: TObject);
    procedure CustomViewShow(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation
{$R *.dfm}

uses uControllerDetallesArticulos;

{ TfrViewDetallesArticulosParaVenta }

procedure TfrViewDetallesArticulosParaVenta.CustomViewDestroy(Sender: TObject);
begin
  inherited;
  cxGridViewIMPORTEUNIDAD.OnGetPropertiesForEdit := Nil;
end;

procedure TfrViewDetallesArticulosParaVenta.CustomViewShow(Sender: TObject);
begin
  inherited;

  with DADataSource.DataTable do
  begin
    cxGridView.BeginUpdate;
    try
      cxGridViewIMPORTEUNIDAD.OnGetPropertiesForEdit := OnIMPORTEUNIDADGetProperties;
    finally
      cxGridView.EndUpdate;
    end;
  end;
end;

procedure TfrViewDetallesArticulosParaVenta.OnIMPORTEUNIDADGetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
var
  Aux_IDArticulo: Variant;
begin
  Aux_IDArticulo := Null;
  cxEditRepositoryComboBox_IMPORTEUNIDAD.Properties.Items.Clear;

  if (_FocusedView.DataController.RecordCount > 0) then
  begin
    Aux_IDArticulo := ARecord.Values[cxGridViewID_ARTICULO.Index];
    if not VarIsNull(Aux_IDArticulo) and (Aux_IDArticulo > 0) then
    begin
      with cxEditRepositoryComboBox_IMPORTEUNIDAD.Properties do
      begin
         ShowHourglassCursor;
         Items.BeginUpdate;
         try
           Items.Clear;
           Items.AddStrings((Controller as IControllerDetallesArticulos).DarPrecioPVPVenta(Aux_IDArticulo));
         finally
           Items.EndUpdate;
           HideHourglassCursor;
         end;
      end;
      AProperties := cxEditRepositoryComboBox_IMPORTEUNIDAD.Properties;
    end
    else begin
      AProperties := cxEditRepositoryCurrencyItem_IMPORTEUNIDAD.Properties;

    end;
  end;
end;

end.
