unit uViewRecibosRemesaCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uViewDetallesGenerico, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, ActnList, ImgList, PngImageList,
  uDADataTable, ComCtrls, ToolWin, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, cxImageComboBox, cxCurrencyEdit,
  uBizRemesasCliente, uRemesasClienteController, uDAInterfaces;
   
type
  IViewRecibosRemesaCliente = interface
  ['{5342D4B0-4BE0-4123-9515-D8ADC9058243}']
    function GetRemesaCliente: IBizRemesaCliente;
    procedure SetRemesaCliente(const Value: IBizRemesaCliente);
    property RemesaCliente: IBizRemesaCliente read GetRemesaCliente write SetRemesaCliente;

    function GetController : IRemesasClienteController;
    procedure SetController (const Value : IRemesasClienteController);
    property Controller : IRemesasClienteController read GetController write SetController;
  end;

  TfrViewRecibosRemesaCliente = class(TfrViewDetallesGenerico, IViewRecibosRemesaCliente)
    cxGridViewIMPORTE: TcxGridDBColumn;
    cxGridViewOTROS_GASTOS: TcxGridDBColumn;
    cxGridViewIMPORTE_TOTAL: TcxGridDBColumn;
    procedure CustomViewShow(Sender: TObject);
  protected
    FHayCambios : Boolean;
    FRemesa : IBizRemesaCliente;
    FController : IRemesasClienteController;
    FListaRecibosIniciales: TStringList;

    procedure AnadirInterno; override;
    procedure EliminarInterno; override;

    function GetRemesaCliente: IBizRemesaCliente;
    procedure SetRemesaCliente(const Value: IBizRemesaCliente);

    function GetModified: Boolean; override;
    procedure SetModified(const Value: Boolean); override;

    function GetController : IRemesasClienteController;
    procedure SetController (const Value : IRemesasClienteController);
    
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property RemesaCliente: IBizRemesaCliente read GetRemesaCliente write SetRemesaCliente;
    property Controller : IRemesasClienteController read GetController write SetController;
  end;


implementation

{$R *.dfm}

uses
  uBizRecibosCliente, uCustomView;

{ TfrViewRecibosRemesaCliente }

procedure TfrViewRecibosRemesaCliente.AnadirInterno;
begin
  //inherited;  // No hacer el comportamiento normal
  if FController.ElegirRecibosCliente(RemesaCliente, FListaRecibosIniciales) then
  begin
    Modified := True;
  end;
end;

constructor TfrViewRecibosRemesaCliente.Create(AOwner: TComponent);
begin
  inherited;
  FHayCambios := False;
  FListaRecibosIniciales := TStringList.Create;
end;

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

  FRemesa.Recibos.DataTable.First;
  while not FRemesa.Recibos.DataTable.eof do
  begin
    FListaRecibosIniciales.Add(IntToStr(FRemesa.Recibos.ID));
    FRemesa.Recibos.DataTable.next;
  end;
  FRemesa.Recibos.DataTable.First;
end;

destructor TfrViewRecibosRemesaCliente.Destroy;
begin
  FListaRecibosIniciales.Free;
  inherited;
end;

procedure TfrViewRecibosRemesaCliente.EliminarInterno;
begin
  //inherited;  // No hacer el comportamiento normal
  FController.EliminarReciboCliente(RemesaCliente);
  Modified := True;
end;

function TfrViewRecibosRemesaCliente.GetController: IRemesasClienteController;
begin
  Result := FController;
end;

function TfrViewRecibosRemesaCliente.GetModified: Boolean;
begin
  Result := FHayCambios or inherited GetModified;
end;

function TfrViewRecibosRemesaCliente.GetRemesaCliente: IBizRemesaCliente;
begin
  Result := FRemesa;
end;

procedure TfrViewRecibosRemesaCliente.SetController(
  const Value: IRemesasClienteController);
begin
  FController := Value;
end;

procedure TfrViewRecibosRemesaCliente.SetModified(const Value: Boolean);
begin
  FHayCambios := Value;
  inherited;
end;

procedure TfrViewRecibosRemesaCliente.SetRemesaCliente(
  const Value: IBizRemesaCliente);
begin
  FRemesa := Value;
  FHayCambios := False;
  if Assigned(FRemesa) then
    dsDetalles.DataTable := FRemesa.Recibos.DataTable
  else
    dsDetalles.DataTable := NIL; 
end;

end.
