{
===============================================================================
  Copyright (©) 2006. Rodax Software.
===============================================================================
  Los contenidos de este fichero son propiedad de Rodax Software titular del
  copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
  en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
  acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
  bajo el que se suministra.
  -----------------------------------------------------------------------------
  Web:  www.rodax-software.com
===============================================================================
  Fecha primera versión: 22-05-2006
  Versión actual: 1.0.0
  Fecha versión actual: 22-05-2006
===============================================================================
  Modificaciones:

    Fecha         Comentarios
    ---------------------------------------------------------------------------
===============================================================================
}

unit uEditorBalance;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Grids, DBGrids, StdCtrls, Mask, DBCtrls, DB,
  uBizBalances, uBalancesController,
  uDADataTable, uIEditorBalance, ActnList, ExtCtrls, JvExControls,
  JvComponent, JvEnterTab, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, cxDBData, cxSpinEdit, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, uDAInterfaces, cxContainer, cxTextEdit, cxMaskEdit,
  cxDropDownEdit, cxImageComboBox, cxDBEdit;

type
  TfEditorBalance = class(TForm, IEditorBalance)
    ActionList1: TActionList;
    actAnadir: TAction;
    actEliminar: TAction;
    actAceptar: TAction;
    actCancelar: TAction;
    bAceptar: TButton;
    bCancelar: TButton;
    actCerrar: TAction;
    actModificar: TAction;
    eReferencia: TDBEdit;
    dsBalances: TDADataSource;
    Label1: TLabel;
    Bevel1: TBevel;
    Label2: TLabel;
    Label3: TLabel;
    Bevel4: TBevel;
    JvEnterAsTab1: TJvEnterAsTab;
    eNivel1: TDBEdit;
    eDescripcion1: TDBEdit;
    eNivel2: TDBEdit;
    eDescripcion2: TDBEdit;
    eNivel3: TDBEdit;
    eDescripcion3: TDBEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    cbNaturaleza: TcxDBImageComboBox;
    procedure FormShow(Sender: TObject);

    procedure actAnadirExecute(Sender: TObject);
    procedure actEliminarExecute(Sender: TObject);
    procedure actAceptarExecute(Sender: TObject);
    procedure actCancelarExecute(Sender: TObject);
    procedure actCerrarExecute(Sender: TObject);
    procedure actAnadirUpdate(Sender: TObject);
    procedure actEliminarUpdate(Sender: TObject);
  protected
    FBalance: IBizBalance;
    FController : IBalancesController;
    function GetBalance: IBizBalance;
    procedure SetBalance(const Value: IBizBalance);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Balance: IBizBalance read GetBalance write SetBalance;
  end;


implementation
{$R *.dfm}

{ TfEditorBalances }

uses
  Dialogs, uDialogUtils;

function TfEditorBalance.GetBalance: IBizBalance;
begin
  Result := FBalance;
end;

procedure TfEditorBalance.SetBalance(const Value: IBizBalance);
begin
  FBalance := Value;
  if Assigned(FBalance) then
  begin
    dsBalances.DataTable := FBalance.DataTable;
    dsBalances.DataTable.Open;
  end
  else begin
    dsBalances.DataTable := NIL;
  end;
end;

procedure TfEditorBalance.actAnadirExecute(Sender: TObject);
begin
//  FPlazos.Append;
end;

procedure TfEditorBalance.actEliminarExecute(Sender: TObject);
begin
//  FPlazos.Delete;
end;

procedure TfEditorBalance.actEliminarUpdate(Sender: TObject);
begin
{
  (Sender as TAction).Enabled := Assigned(FPlazos) and
                                 FPlazos.DataTable.Active and
                                 (FPlazos.DataTable.RecordCount > 0);
}
end;

constructor TfEditorBalance.Create(AOwner: TComponent);
begin
  inherited;
  FController := TBalancesController.Create;
end;

destructor TfEditorBalance.Destroy;
begin
  FBalance := NIL;
  FController := NIL;
  inherited;
end;

procedure TfEditorBalance.actAceptarExecute(Sender: TObject);
begin
{
  if (ListaBalances.ActiveView.DataController.RecordCount = 0) then
    if (ShowConfirmMessage('Forma de pago sin plazos', 'No ha indicado plazos de pago para esta forma de pago por lo tanto no se podrán generarar los recibos correspondientes.' + #10#13 + '¿Desea continuar guardando la forma de pago?') = IDNO) then
      Exit;
}
  if FController.Guardar(FBalance) then
    actCerrar.Execute;
end;

procedure TfEditorBalance.actCancelarExecute(Sender: TObject);
begin
  FController.DescartarCambios(FBalance);
  actCerrar.Execute;
end;

procedure TfEditorBalance.actCerrarExecute(Sender: TObject);
begin
  Close;
end;

procedure TfEditorBalance.actAnadirUpdate(Sender: TObject);
begin
{
  (Sender as TAction).Enabled := Assigned(FPlazos) and
                                 FPlazos.DataTable.Active;
}
end;

procedure TfEditorBalance.FormShow(Sender: TObject);
begin
  if not FBalance.DataTable.Active then
     FBalance.DataTable.Active := True;

  if FBalance.EsNuevo then
    Self.Caption := 'Nuevo balance'
  else
    Self.Caption := 'Modificar balance';
end;

end.
