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,
  JvFormPlacement, pngimage, ExtCtrls, JvComponentBase, dxLayoutLookAndFeels,
  JvExComCtrls, JvStatusBar, uDAInterfaces, cxControls, cxContainer, cxEdit,
  cxLabel;

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

  TfEditorDBItem = class(TfEditorDBBase, IEditorDBItem)
    pgPaginas: TPageControl;
    pagGeneral: TTabSheet;
    imgStatus: TImage;
    lblDesbloquear: TcxLabel;
    procedure lblDesbloquearClick(Sender: TObject);
  protected
    procedure EliminarInterno; override;
    procedure ActualizarEstadoEditor; override;
  end;

implementation

uses
  uEditorBase, uDialogUtils, uDataTableUtils;

{$R *.dfm}

procedure TfEditorDBItem.ActualizarEstadoEditor;
begin
  inherited;
  if HayDatos then
  begin
    if lblDesbloquear.Enabled then
      lblDesbloquear.Visible := ReadOnly;

    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.lblDesbloquearClick(Sender: TObject);
begin
  inherited;

  if (ShowConfirmMessage('żDesbloquear los datos para permitir cambios?', 'Actualmente, los datos de esta ficha no se pueden modificar.' + #13#10 +
      'Temporalmente puede desbloquear la ficha para realizar cambios puntuales. żDesea continuar?') = IDYES) then
  begin
    lblDesbloquear.Visible := False;
    lblDesbloquear.Enabled := False;
    SetDataTableReadOnly(dsDataTable.DataTable, False);
    Self.ReadOnly := False;
    ActualizarEstadoEditor;
  end;
end;

initialization
  RegisterClass(TfEditorDBItem);

finalization
  UnRegisterClass(TfEditorDBItem);

end.
