unit uEditorEpigrafes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorBase, ToolWin, ComCtrls, JvExControls, JvComponent,
  JvNavigationPane, uViewEpigrafes, uBizEpigrafes, 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, uIEditorEpigrafes, uEditorGridBase,
  JvComponentBase, uViewGridBase, uEpigrafesController, JvExComCtrls,
  JvStatusBar, uDAInterfaces, dxGDIPlusClasses;

type
  TfEditorEpigrafes = class(TfEditorGridBase, IEditorEpigrafes)
    frViewEpigrafes1: TfrViewEpigrafes;
    procedure FormShow(Sender: TObject);
    procedure actEliminarUpdate(Sender: TObject);
    procedure actNuevoUpdate(Sender: TObject);
    procedure actModificarUpdate(Sender: TObject);
  private
    FEpigrafes: IBizEpigrafe;
    FController : IEpigrafesController;
  protected
    function GetEpigrafes: IBizEpigrafe;
    procedure SetEpigrafes(const Value: IBizEpigrafe);
    function GetController : IEpigrafesController; virtual;
    procedure SetController (const Value : IEpigrafesController); virtual;

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

  public
    procedure PonerTitulos(const ATitulo: string = ''); override;
    property Epigrafes: IBizEpigrafe read GetEpigrafes write SetEpigrafes;
    property Controller : IEpigrafesController read GetController write SetController;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation

uses
  uCustomEditor, uDataModuleUsuarios, uBizEjercicios,
//  uEditorEpigrafe,
  uEditorDBBase, uFactuGES_App,
  cxGrid, cxGridCustomTableView; //, uListaEpigrafes;

{$R *.dfm}

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

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

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

  Epigrafes.DataTable.Active := True;
  ViewGrid.GotoFirst;
end;

function TfEditorEpigrafes.GetEpigrafes: IBizEpigrafe;
begin
  Result := FEpigrafes;
end;

function TfEditorEpigrafes.GetController: IEpigrafesController;
begin
  Result := FController;
end;

procedure TfEditorEpigrafes.ModificarInterno;
begin
  inherited;
  FController.Ver(Epigrafes);
end;

procedure TfEditorEpigrafes.NuevoInterno;
begin
  inherited;
  FController.Anadir(Epigrafes);
  FController.Ver(Epigrafes);
end;

procedure TfEditorEpigrafes.PonerTitulos(const ATitulo: string);
var
  FTitulo : String;
begin
  FTitulo := 'Lista de Epigrafes - ' + AppFactuGES.EmpresaActiva.NOMBRE + ' - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')';
  inherited PonerTitulos(FTitulo);
end;

procedure TfEditorEpigrafes.SetEpigrafes(const Value: IBizEpigrafe);
begin
  FEpigrafes := Value;
  dsDataTable.DataTable := FEpigrafes.DataTable;
  if Assigned(ViewGrid) then
    (ViewGrid as IViewEpigrafes).Epigrafes := Epigrafes;
end;

procedure TfEditorEpigrafes.SetController(const Value: IEpigrafesController);
begin
  FController := Value;
end;

destructor TfEditorEpigrafes.Destroy;
begin
  FEpigrafes := NIL;
  inherited;
end;

procedure TfEditorEpigrafes.DuplicarInterno;
{var
  AEpigrafe : IBizEpigrafe;}
begin
{
  inherited;
  AEpigrafe := FController.Duplicar(Epigrafes);
  try
    FController.Ver(AEpigrafe);
  finally
    actRefrescar.Execute;
  end;
}  
end;

procedure TfEditorEpigrafes.EliminarInterno;
begin

  if (Application.MessageBox('¿Desea borrar este epígrafe?', '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(Epigrafes) then
       actRefrescar.Execute;
  end;
end;

procedure TfEditorEpigrafes.actEliminarUpdate(Sender: TObject);
begin
  inherited;
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := (Epigrafes.ESTADO = CTE_ABIERTO);
end;

procedure TfEditorEpigrafes.actModificarUpdate(Sender: TObject);
begin
  inherited;
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := (Epigrafes.ESTADO = CTE_ABIERTO);
end;

procedure TfEditorEpigrafes.actNuevoUpdate(Sender: TObject);
begin
  inherited;
  if (Sender as TAction).Enabled then
     (Sender as TAction).Enabled := (AppFactuGES.EjercicioActivo.ESTADO = CTE_ABIERTO);
end;

constructor TfEditorEpigrafes.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewEpigrafes1; //CreateView(TfrViewEpigrafes) as IViewEpigrafes;
end;

end.

  