unit uEditorDBItem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  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, ExtCtrls, uDAInterfaces,
  JvComponentBase, JvFormPlacement, JvExComCtrls, JvStatusBar, pngimage;

type
  IEditorDBItem = interface(IEditorDBBase)
  ['{497AE4CE-D061-4F75-A29A-320F8565FF54}']
    function GetComentario: Variant;
    procedure SetComentario(const Value: Variant);
    property Comentario: Variant read GetComentario write SetComentario;
  end;

  TfEditorDBItem = class(TfEditorDBBase, IEditorDBItem)
    pgPaginas: TPageControl;
    pagGeneral: TTabSheet;
    imgStatus: TImage;
    PnlComentario: TPanel;
    lbComentario: TLabel;

  protected
    FComentario: Variant;
    function GetComentario: Variant;
    procedure SetComentario(const Value: Variant);

    procedure EliminarInterno; override;
    procedure ActualizarEstadoEditor; override;

  public
    property Comentario: Variant read GetComentario write SetComentario;
    constructor Create(AOwner: TComponent); override;
  end;

implementation

uses
  uEditorBase, uDialogUtils;

{$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;

constructor TfEditorDBItem.Create(AOwner: TComponent);
begin
  inherited;
  Comentario := Null;
end;

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

function TfEditorDBItem.GetComentario: Variant;
begin
  Result := FComentario;
end;

procedure TfEditorDBItem.SetComentario(const Value: Variant);
begin
  FComentario := Value;
  lbComentario.Caption := '';
  lbComentario.Caption := VarToStr(FComentario);

  if VarIsNull(FComentario) then
     PnlComentario.Visible := False
  else
     PnlComentario.Visible := True;
end;

initialization
  RegisterClass(TfEditorDBItem);

finalization
  UnRegisterClass(TfEditorDBItem);

end.
