unit Unit1;
                                                     
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, DB, FIBDataSet, pFIBDataSet, FIBDatabase, pFIBDatabase,
  ExtCtrls, StdCtrls, Grids, DBGrids, FIBQuery, pFIBQuery, pFIBStoredProc;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    db: TpFIBDatabase;
    tr: TpFIBTransaction;
    dtOrgChart: TpFIBDataSet;
    dsOrgChart: TDataSource;
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    DBGrid1: TDBGrid;
    dtDept: TpFIBDataSet;
    spSubTotalBudget: TpFIBStoredProc;
    DBGrid2: TDBGrid;
    dsDept: TDataSource;
    Button1: TButton;
    pFIBTransaction1: TpFIBTransaction;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses uCommon;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Text := GetExampleNotes;
  Caption := 'FIBPlus Example - ' + Application.Title;
  db.DBName := 'localhost:' + ExtractFileDir(Application.ExeName) + '\db\employee.fdb';
  db.Connected := True;
  dtOrgChart.Open;
  dtDept.Open;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not db.Connected then Exit;
  db.CloseDataSets;
  db.Close;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := MessageDlg('This will end your ' + QuotedStr(Caption) + ' session. Proceed?',
    mtConfirmation, [mbOk, mbCancel], 0) = mrOk;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with spSubTotalBudget do begin
    Params[0].AsString := dtDept.FBN('DEPT_NO').AsString;
    ExecProc;
    ShowMessageFmt('Total: %m'#10'Avg  : %m'#10'Min  : %m'#10'Max  : %m',
      [FieldByName('TOT_BUDGET').AsCurrency, FieldByName('AVG_BUDGET').AsCurrency,
       FieldByName('MIN_BUDGET').AsCurrency, FieldByName('MAX_BUDGET').AsCurrency]);
  end;
end;

end.
