unit uViewComision;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewBase, DB, uDADataTable, uCustomView, uDMBase,
  uBizComisiones,
  cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit, dxLayoutControl,
  cxMemo, cxMaskEdit, cxDropDownEdit, cxCalendar, cxSpinEdit, StdCtrls, Mask,
  DBCtrls, cxGraphics, dxLayoutLookAndFeels, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, uFormasPagoController, uDAInterfaces, uBizFormasPago,
  ActnList, uComisionesController, uBizContactos, uVendedoresController,
  cxLookAndFeels, cxLookAndFeelPainters, dxLayoutcxEditAdapters;

type
  IViewComision = interface(IViewBase)
  ['{2813FE84-ADCC-4635-A0A8-975D7BB4D915}']
    function GetComision: IBizComision;
    procedure SetComision(const Value: IBizComision);
    property Comision: IBizComision read GetComision write SetComision;
    function GetController : IComisionesController;
    procedure SetController (const Value : IComisionesController);
    property Controller : IComisionesController read GetController write SetController;
  end;

  TfrViewComision = class(TfrViewBase, IViewComision)
    DADataSource: TDADataSource;
    dxLayoutControl1Group_Root: TdxLayoutGroup;
    dxLayoutControl1: TdxLayoutControl;
    dxLayoutControl1Item1: TdxLayoutItem;
    eReferencia: TcxDBTextEdit;
    dxLayoutControl1Item2: TdxLayoutItem;
    edtFecha: TcxDBDateEdit;
    dxLayoutControl1Group1: TdxLayoutGroup;
    dsVendedores: TDADataSource;
    dxLayoutControl1Group2: TdxLayoutGroup;
    dxLayoutControl1Item6: TdxLayoutItem;
    eVendedor: TcxDBLookupComboBox;
    dxLayoutControl1Item3: TdxLayoutItem;
    eDescripcion: TcxDBTextEdit;
    procedure CustomViewDestroy(Sender: TObject);
    procedure CustomViewCreate(Sender: TObject);
    procedure OnVendedorEditValueChanged(Sender: TObject);
    procedure CustomViewShow(Sender: TObject);
  protected
    FComision : IBizComision;
    FController : IComisionesController;
    FVendedores : IBizContacto;
    FVendedoresController : IVendedoresController;
    function GetComision: IBizComision;
    procedure SetComision(const Value: IBizComision);
    function GetController : IComisionesController;
    procedure SetController (const Value : IComisionesController);

  public
    property Comision: IBizComision read GetComision write SetComision;
    property Controller : IComisionesController read GetController write SetController;
  end;


implementation

uses
  uDataModuleContactos, schComisionesClient_Intf, uFactuGES_App,
  uEmpresasController;

{$R *.dfm}

{ TfrViewComision }


procedure TfrViewComision.CustomViewCreate(Sender: TObject);
begin
  inherited;
  FVendedores := Nil;
  FVendedoresController := TVendedoresController.Create;
end;

procedure TfrViewComision.CustomViewDestroy(Sender: TObject);
begin
  eVendedor.Properties.OnEditValueChanged := Nil;
  FVendedores := Nil;
  FVendedoresController := NIL;
  inherited;
end;

procedure TfrViewComision.CustomViewShow(Sender: TObject);
begin
  inherited;
  eVendedor.Properties.OnEditValueChanged := OnVendedorEditValueChanged;
end;

procedure TfrViewComision.OnVendedorEditValueChanged(Sender: TObject);
begin
  inherited;
  Comision.Edit;
  Comision.AGENTE := eVendedor.Text;
end;

function TfrViewComision.GetController: IComisionesController;
begin
  Result := FController;
end;

function TfrViewComision.GetComision: IBizComision;
begin
  Result := FComision;
end;

procedure TfrViewComision.SetController(const Value: IComisionesController);
begin
  FController := Value;
end;

procedure TfrViewComision.SetComision(const Value: IBizComision);
var
  ACadena : String;
begin
  FComision := Value;

  if Assigned(FComision) then
  begin
    DADataSource.DataTable := FComision.DataTable;
    FVendedores := FVendedoresController.BuscarTodos;
    dsVendedores.DataTable := FVendedores.DataTable;
    dsVendedores.DataTable.Active := True;
  end
  else begin
    DADataSource.DataTable := NIL;
    dsVendedores.DataTable := NIL;    
  end;
end;

end.
