{********************************************************************}
{                                                                    }
{     Copyright (c) 04.2000 by Serge Buzadzhy                        }
{     email:  serge_buzadzhy@mail.ru,                                }
{             FidoNet: 2:467/44.37                                   }
{                                                                    }
{                                                                    }
{********************************************************************}
unit DM;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  FIBDatabase, pFIBDatabase, DSContainer,DB, FIBDataSet, pFIBDataSet
  {$IFDEF VER140}
  ,Variants
  {$ELSE}
    {$IFDEF VER150}
     ,Variants
    {$ENDIF}
  {$ENDIF}
  ;

type
  TDataModule2 = class(TDataModule)
    Database: TpFIBDatabase;
    Transaction: TpFIBTransaction;
    DataSetsContainer1: TDataSetsContainer;
    procedure DataSetsContainer1DataSetEvent(DataSet: TDataSet;
      Event: TKindDataSetEvent);
    procedure DataSetsContainer1UserEvent(Sender: TObject;
      Receiver: TDataSet; const EventName: String; var Info: String);
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DataModule2: TDataModule2;

implementation

{$R *.DFM}

procedure TDataModule2.DataSetsContainer1DataSetEvent(DataSet: TDataSet;
  Event: TKindDataSetEvent);
var Info: string;
begin
  if Event = deAfterPost then
    if DataSet.Owner.Name = 'Form1' then
        DataSetsContainer1.NotifyDataSets(DataSet,
          'Form2.ArrayDataSet', 'JOB_TABLE_CHANGED', Info)
    else
      if DataSet.Owner.Name = 'Form2' then
        DataSetsContainer1.NotifyDataSets(DataSet,
          'Form1.ArrayDataSet', 'JOB_TABLE_CHANGED', Info);
end;

procedure TDataModule2.DataSetsContainer1UserEvent(Sender: TObject;
  Receiver: TDataSet; const EventName: String; var Info: String);
begin
  if EventName = 'JOB_TABLE_CHANGED' then begin
    with TpFIBDataSet(Sender) do
      if (not CachedUpdates) and
         (not TpFIBDataSet(Receiver).CachedUpdates) then
      // При CU рефреш ничего умного не сделает
       if TpFIBDataSet(Receiver).Locate('JOB_CODE;JOB_GRADE;JOB_COUNTRY',
          varArrayOf([
            FieldByName('JOB_CODE').AsString,
            FieldByName('JOB_GRADE').AsString,
            FieldByName('JOB_COUNTRY').AsString
          ]), []) then TpFIBDataSet(Receiver).Refresh
  end;
end;

procedure TDataModule2.DataModuleCreate(Sender: TObject);
begin
  // Set database path
  Database.DBName := 'localhost:' + ExtractFileDir(Application.ExeName) + '\db\employee.fdb';
  Database.Open;
end;

end.
