unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, DB, DBClient, Grids, DBGrids, MConnect,
  Menus, StdCtrls;

type
  TForm2 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    StatusBar1: TStatusBar;
    pnl: TPanel;
    dtCusts: TClientDataSet;
    dtDelta: TClientDataSet;
    dsCusts: TDataSource;
    dsSales: TDataSource;
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    dcomConn: TDCOMConnection;
    mm: TMainMenu;
    mmiFile: TMenuItem;
    N1: TMenuItem;
    mmiExit: TMenuItem;
    btnApplyUpdates: TButton;
    btnCancelUpdates: TButton;
    btnRevertRecord: TButton;
    btnUndoLastChange: TButton;
    btnSetSavePoint: TButton;
    btnGotoSavePoint: TButton;
    btnRefresh: TButton;
    procedure mmiExitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnApplyUpdatesClick(Sender: TObject);
    procedure btnCancelUpdatesClick(Sender: TObject);
    procedure btnRevertRecordClick(Sender: TObject);
    procedure btnUndoLastChangeClick(Sender: TObject);
    procedure btnSetSavePointClick(Sender: TObject);
    procedure btnGotoSavePointClick(Sender: TObject);
    procedure dsCustsUpdateData(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure dsCustsDataChange(Sender: TObject; Field: TField);
    procedure dtCustsReconcileError(DataSet: TCustomClientDataSet;
      E: EReconcileError; UpdateKind: TUpdateKind;
      var Action: TReconcileAction);
    procedure btnRefreshClick(Sender: TObject);
  private
    FSavePoint: integer;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit3;

{$R *.dfm}

procedure TForm2.mmiExitClick(Sender: TObject);
begin
  Close;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  dtCusts.Open;
end;

procedure TForm2.btnApplyUpdatesClick(Sender: TObject);
begin
  dtCusts.ApplyUpdates(-1);
  dsCustsUpdateData(nil);
  dsCustsDataChange(nil, nil);
end;

procedure TForm2.btnCancelUpdatesClick(Sender: TObject);
begin
  dtCusts.CancelUpdates;
  dsCustsUpdateData(nil);
  dsCustsDataChange(nil, nil);
end;

procedure TForm2.btnRevertRecordClick(Sender: TObject);
begin
  dtCusts.RevertRecord;
end;

procedure TForm2.btnUndoLastChangeClick(Sender: TObject);
begin
  dtCusts.UndoLastChange(true);
end;

procedure TForm2.btnSetSavePointClick(Sender: TObject);
begin
  FSavePoint := dtCusts.SavePoint;
  btnGotoSavePoint.Enabled := True;
end;

procedure TForm2.btnGotoSavePointClick(Sender: TObject);
begin
  dtCusts.SavePoint := FSavePoint;
end;

procedure TForm2.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage = TabSheet2
  then dtDelta.Data := dtCusts.Delta
  else dtDelta.Close;
end;

procedure TForm2.dsCustsUpdateData(Sender: TObject);
begin
  TabSheet2.TabVisible := True;
  btnApplyUpdates.Enabled := dtCusts.ChangeCount >= 0;
  btnCancelUpdates.Enabled:= btnApplyUpdates.Enabled;
  btnUndoLastChange.Enabled := btnApplyUpdates.Enabled;
end;


procedure TForm2.dsCustsDataChange(Sender: TObject; Field: TField);
begin btnRevertRecord.Enabled := dtCusts.Modified;
end;

procedure TForm2.dtCustsReconcileError(DataSet: TCustomClientDataSet;
  E: EReconcileError; UpdateKind: TUpdateKind;
  var Action: TReconcileAction);
begin
  Action := HandleReconcileError(Dataset, UpdateKind, E);
end;

procedure TForm2.btnRefreshClick(Sender: TObject);
begin
  dtCusts.Refresh;
end;

end.
