unit uViewFiltroProveedores;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit,
  StdCtrls, Buttons, SpTBXDkPanels, uViewParametrosInforme, uBizContactos,
  uProveedoresController, SpTBXControls;

type
  IViewFiltroProveedores = interface(IViewParametrosInforme)
    ['{129906DA-8E64-4312-8095-A04F8007CF7F}']
  end;
  
  TfrViewFiltroProveedores = class(TfrViewParametrosInforme, IViewFiltroProveedores)
    TBXLabel2: TSpTBXLabel;
    rbTodosProveedores: TRadioButton;
    rbUnProveedor: TRadioButton;
    cbxDesglosado: TCheckBox;
    bElegirProveedor: TBitBtn;
    edtProveedor: TcxTextEdit;
    procedure rbTodosProveedoresClick(Sender: TObject);
    procedure rbUnProveedorClick(Sender: TObject);
    procedure CustomViewCreate(Sender: TObject);
    procedure bElegirProveedorClick(Sender: TObject);
    procedure CustomViewDestroy(Sender: TObject);
  private
    FProveedor : IBizProveedor;
    FProveedoresController : IProveedoresController; 
  public
    property Proveedor : IBizProveedor read FProveedor;
  end;

implementation

{$R *.dfm}

procedure TfrViewFiltroProveedores.bElegirProveedorClick(Sender: TObject);
var
  AProveedores : IBizProveedor;
begin
  inherited;
  AProveedores := IBizProveedor(FProveedoresController.BuscarTodos);
  try
    FProveedor := IBizProveedor(FProveedoresController.ElegirContacto(AProveedores, '', False));
    if Assigned(FProveedor) then
    begin
      FProveedor.Open;
      edtProveedor.Text := FProveedor.NOMBRE;
    end;
  finally
    AProveedores := NIL;
  end;
end;

procedure TfrViewFiltroProveedores.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FProveedor := NIL;
  FProveedoresController := NIL;
end;

procedure TfrViewFiltroProveedores.CustomViewDestroy(Sender: TObject);
begin
  inherited;
  FProveedor := NIL;
  FProveedoresController := NIL;
end;

procedure TfrViewFiltroProveedores.rbTodosProveedoresClick(Sender: TObject);
begin
  if rbTodosProveedores.Checked then
  begin
    cbxDesglosado.Enabled := True;
    FProveedor := NIL;
    bElegirProveedor.Enabled := False;
    edtProveedor.Clear;
    edtProveedor.Enabled := False;    
  end;
end;

procedure TfrViewFiltroProveedores.rbUnProveedorClick(Sender: TObject);
begin
  if rbUnProveedor.Checked then
  begin
    cbxDesglosado.Enabled := False;
    bElegirProveedor.Enabled := True;
    edtProveedor.Enabled := True;
    if not Assigned(FProveedoresController) then
      FProveedoresController := TProveedoresController.Create;
  end;
end;

end.
