unit uEditorDBItem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorItem, ImgList, PngImageList, StdActns, ActnList, TBX,
  TB2Item, TB2Dock, TB2Toolbar, ComCtrls, JvExControls, JvComponent,
  JvNavigationPane, DB, uDADataTable, uEditorDBBase, JvFormAutoSize,
  StdCtrls, uDAScriptingProvider, uDACDSDataTable, AppEvnts, uCustomView,
  uViewBase, JvAppStorage, JvAppRegistryStorage,
  JvFormPlacement, pngimage, ExtCtrls, JvComponentBase, dxLayoutLookAndFeels,
  TBXStatusBars, JvExComCtrls, JvStatusBar;

type
  IEditorDBItem = interface(IEditorDBBase)
  ['{497AE4CE-D061-4F75-A29A-320F8565FF54}']
  end;

  TfEditorDBItem = class(TfEditorDBBase, IEditorDBItem)
    pgPaginas: TPageControl;
    pagGeneral: TTabSheet;
    imgStatus: TImage;
  protected
    procedure EliminarInterno; override;
    procedure PrevisualizarInterno; override;
    procedure ImprimirInterno; override;
    procedure ActualizarEstadoEditor; override;
  end;

var
  fEditorDBItem: TfEditorDBItem;

implementation

uses
  uBizInformesBase, uEditorBase;

{$R *.dfm}

procedure TfEditorDBItem.ActualizarEstadoEditor;
begin
  inherited;
  if HayDatos then
  begin
    if (Self.Modified) and (dsDataTable.DataTable.State <> dsInsert) then
    begin
      StatusBar.Panels[0].Text := '       Se han producido cambios';
      imgStatus.Visible := True;
    end
    else begin
      imgStatus.Visible := False;
      StatusBar.Panels[0].Text := '';
    end
  end;
end;

procedure TfEditorDBItem.EliminarInterno;
begin
  inherited;
  actCerrar.Execute;
end;

procedure TfEditorDBItem.ImprimirInterno;
var
  Respuesta: Integer;
  aInf : IBizInformesAware;
begin
  inherited;
  if Modified then
  begin
    if (Application.MessageBox('Se han producido cambios y no se puede imprimir hasta que no se guarden.' + #10#13 +
      '¿Desea guardarlos ahora?', 'Atención', MB_YESNO) = IDYES) then
      actGuardar.Execute
    else begin
      Application.MessageBox('Recuerde guardar los cambios si quiere previsualizar o imprimir.', 'Información', MB_OK);
      Exit;
    end;
  end;
end;

procedure TfEditorDBItem.PrevisualizarInterno;
var
  Respuesta: Integer;
  aInf : IBizInformesAware;
begin
  inherited;
  if Modified then
  begin
    if (Application.MessageBox('Se han producido cambios y no se puede previsualizar hasta que no se guarden.' + #10#13 +
      '¿Desea guardarlos ahora?', 'Atención', MB_YESNO) = IDYES) then
      actGuardar.Execute
    else begin
      Application.MessageBox('Recuerde guardar los cambios si quiere previsualizar o imprimir.', 'Información', MB_OK);
      Exit;
    end;
  end;
end;

initialization
  RegisterClass(TfEditorDBItem);

finalization
  UnRegisterClass(TfEditorDBItem);

end.
