unit uEditorBalances;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorBase, ToolWin, ComCtrls, JvExControls, JvComponent,
  JvNavigationPane, uViewBalances, uBizBalances, ActnList, DBActns, uViewGrid,
  Menus, uDataModuleBase, ImgList, PngImageList, TB2Dock, TB2Toolbar, TBX,
  TB2Item, StdActns, TB2ExtItems, TBXExtItems, TB2MRU, DB, uDADataTable,
  JvFormAutoSize, uDAScriptingProvider, uDACDSDataTable, JvAppStorage,
  JvAppRegistryStorage, JvFormPlacement, ExtCtrls, uCustomView, uViewBase,
  uViewBarraSeleccion, pngimage, uIEditorBalances, uEditorGridBase,
  JvComponentBase, uViewGridBase, uBalancesController, JvExComCtrls,
  JvStatusBar, uDAInterfaces, dxGDIPlusClasses;

type
  TfEditorBalances = class(TfEditorGridBase, IEditorBalances)
    frViewBalances1: TfrViewBalances;
    procedure FormShow(Sender: TObject);
  private
    FBalances: IBizBalance;
    FController : IBalancesController;
  protected
    function GetBalances: IBizBalance;
    procedure SetBalances(const Value: IBizBalance);
    function GetController : IBalancesController; virtual;
    procedure SetController (const Value : IBalancesController); virtual;

    procedure NuevoInterno; override;
    procedure EliminarInterno; override;
    procedure ModificarInterno; override;
    procedure DuplicarInterno; override;

  public
    procedure PonerTitulos(const ATitulo: string = ''); override;  
    property Balances: IBizBalance read GetBalances write SetBalances;
    property Controller : IBalancesController read GetController write SetController;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation

uses
  uCustomEditor, uDataModuleUsuarios,
//  uEditorBalance,
  uEditorDBBase, uFactuGES_App,
  cxGrid, cxGridCustomTableView; //, uListaBalances;

{$R *.dfm}

{
****************************** TfEditorBalances *******************************
}
procedure TfEditorBalances.FormShow(Sender: TObject);
begin
  inherited;

  if not Assigned(ViewGrid) then
    raise Exception.Create('No hay ninguna vista asignada');

  if not Assigned(Balances) then
    raise Exception.Create('No hay ningún Balance asignado');

  Balances.DataTable.Active := True;
  ViewGrid.GotoFirst;
  //Para que coja el ancho automático
  actAnchoAuto.Execute;    
end;

function TfEditorBalances.GetBalances: IBizBalance;
begin
  Result := FBalances;
end;

function TfEditorBalances.GetController: IBalancesController;
begin
  Result := FController;
end;

procedure TfEditorBalances.ModificarInterno;
begin
  inherited;
  FController.Ver(Balances);
end;

procedure TfEditorBalances.NuevoInterno;
begin
  inherited;
  FController.Anadir(Balances);
  FController.Ver(Balances);
end;

procedure TfEditorBalances.PonerTitulos(const ATitulo: string);
var
  FTitulo : String;
begin
  FTitulo := 'Lista de Balances '; // + AppFactuGES.EmpresaActiva.NOMBRE;
  inherited PonerTitulos(FTitulo);
end;

procedure TfEditorBalances.SetBalances(const Value: IBizBalance);
begin
  FBalances := Value;
  dsDataTable.DataTable := FBalances.DataTable;
  if Assigned(ViewGrid) then
    (ViewGrid as IViewBalances).Balances := Balances;
end;

procedure TfEditorBalances.SetController(const Value: IBalancesController);
begin
  FController := Value;
end;

destructor TfEditorBalances.Destroy;
begin
  FBalances := NIL;
  inherited;
end;

procedure TfEditorBalances.DuplicarInterno;
var
  ABalance : IBizBalance;
begin
AppFactuGES.ShowCapado;
{
  inherited;
  ABalance := FController.Duplicar(Balances);
  try
    FController.Ver(ABalance);
  finally
    actRefrescar.Execute;
  end;
}  
end;

procedure TfEditorBalances.EliminarInterno;
begin

  if (Application.MessageBox('¿Desea borrar este almacén?', 'Atención', MB_YESNO) = IDYES) then
  begin
    inherited;
    //Para que en el caso de no poderse realizar la operación se refresquen
    //los datos y no nos permita eliminar un registro a la segunda
    if not FController.Eliminar(Balances) then
       actRefrescar.Execute;
  end;
end;

constructor TfEditorBalances.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewBalances1; //CreateView(TfrViewBalances) as IViewBalances;
end;

end.

  