unit uEditorReciboObra;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uEditorReciboCliente, dxLayoutLookAndFeels, JvAppStorage,
  JvAppRegistryStorage, DB, uDADataTable, JvComponentBase, JvFormPlacement,
  ImgList, PngImageList, StdActns, ActnList, ComCtrls, uViewTextoRecibo,
  uCustomView, uViewBase, uViewReciboCliente, TBX, TB2Item, TB2Dock,
  TB2Toolbar, pngimage, ExtCtrls, JvExControls, JvComponent,
  JvNavigationPane, uViewDatosYSeleccionContacto2, cxContainer, cxEdit,
  cxTextEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, cxDBEdit,
  dxLayoutControl, cxControls, cxCurrencyEdit;

type
  TfEditorReciboObra = class(TfEditorReciboCliente)
    procedure frViewTextoRecibo1ItalicButtonClick(Sender: TObject);
  protected
    function GetModified: Boolean; override;
  end;

implementation
{$R *.dfm}

uses uDataTableUtils, uEditorUtils, uBizObraFinal;

function ShowEditorReciboObra (ABizObject : TDADataTableRules) : TModalResult;
var
  AEditor: TfEditorReciboObra;
begin
  AEditor := TfEditorReciboObra.Create(Application);
  try
    AEditor.ReciboCliente := (ABizObject as IBizRecibosObras);
    Result := AEditor.ShowModal;
  finally
    AEditor.Release;
  end;
end;

procedure TfEditorReciboObra.frViewTextoRecibo1ItalicButtonClick(
  Sender: TObject);
begin
//  inherited;
  frViewTextoRecibo1.ItalicButtonClick(Sender);
end;

function TfEditorReciboObra.GetModified: Boolean;
var
  dtDetails : TList;
  i : integer;
  bCambiado : Boolean;
begin
  bCambiado := False;
  if Assigned(dsDataTable.DataTable) then
  begin
    bCambiado := (dsDataTable.DataTable.State = dsEdit);

    if FApplyUpdates then
       if (not bCambiado) then
          bCambiado := DeltaValuesAreDifferent(dsDataTable.DataTable.Delta);

    if (not bCambiado) then
    begin
      dtDetails := dsDataTable.DataTable.GetDetailDataTables;
      for i := 0 to dtDetails.Count - 1 do
      begin
        bCambiado := bCambiado or ((TDADataTable(dtDetails.Items[i])).State = dsEdit);

        if FApplyUpdates then
           if (not bCambiado) then
              bCambiado := bCambiado or (DeltaValuesAreDifferent((TDADataTable(dtDetails.Items[i])).Delta));

        if bCambiado then
          Break;
      end;
    end;
  end;

//  if (not bCambiado) then
//    bCambiado := inherited GetModified;

  Result := bCambiado;
end;

initialization
  RegisterEditor(IBizRecibosObras, ShowEditorReciboObra, etItem);

end.
