unit Unit1;

interface

uses
  Forms, Types, SysUtils, DB, DBTables, XPMan, ImgList, Controls, ExtCtrls, DBCtrls,
  NxPropertyItemClasses, NxDBPropertyItems, NxPropertyItems, Classes,
  NxScrollControl, NxInspector, NxDBInspector, StdCtrls, Dialogs, Grids,
  DBGrids, Graphics;

type
  TForm1 = class(TForm)
    DBPropertiesView1: TNextDBInspector;
    DataSource1: TDataSource;
    ImageList1: TImageList;
    DBNavigator1: TDBNavigator;
    XPManifest1: TXPManifest;
    Table1: TTable;
    NxDBToolbarItem1: TNxDBToolbarItem;
    itmTableName: TNxDBTextItem;
    itmActive: TNxDBCheckBoxItem;
    itmRecordCount: TNxDBTextItem;
    NxDBToolbarItem2: TNxDBToolbarItem;
    NxDBToolbarItem3: TNxDBToolbarItem;
    NxDBTextItem3: TNxDBTextItem;
    NxDBTextItem4: TNxDBTextItem;
    NxDBToolbarItem4: TNxDBToolbarItem;
    NxDBDateItem1: TNxDBDateItem;
    NxDBSpinItem1: TNxDBSpinItem;
    NxDBToolbarItem5: TNxDBToolbarItem;
    NxDBTextItem1: TNxDBTextItem;
    Table1EmpNo: TIntegerField;
    Table1LastName: TStringField;
    Table1FirstName: TStringField;
    Table1HireDate: TDateField;
    Table1Job: TIntegerField;
    Table1ImageNo: TIntegerField;
    Table1Progress: TFloatField;
    Table1Salary: TFloatField;
    Table1InOffice: TBooleanField;
    Button1: TButton;
    Button2: TButton;
    DBGrid1: TDBGrid;
    NxDBCalcItem1: TNxDBCalcItem;
    procedure DBPropertiesView1ToolbarClick(Sender: TObject;
      Item: TNxPropertyItem; ButtonIndex: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Table1CalcFields(DataSet: TDataSet);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Table1HireDateChange(Sender: TField);
    procedure DBPropertiesView1Change(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString);
    procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DBPropertiesView1ToolbarClick(Sender: TObject;
  Item: TNxPropertyItem; ButtonIndex: Integer);
begin
  if Item.Items.Count > 0 then
  begin
    with Item as TNxToolbarItem do
    begin
      ExpandLock := Buttons[ButtonIndex].Checked;
      if Buttons.Count = 3 then
        if ButtonIndex = 0 then Visible := False;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Table1.DatabaseName := ExtractFilePath(ParamStr(0)) + 'Data';
//  ShowMessage(Table1.DatabaseName);
  Table1.TableName := 'employee';
  Table1.Active := True;
  itmTableName.AsString := Table1.TableName;
  itmActive.AsBoolean := Table1.Active;
  itmRecordCount.AsInteger := Table1.RecordCount;
end;

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
//  Table1FullName.Value := Table1FirstName.AsString + ' ' + Table1LastName.AsString;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Edit;
  Table1.FindField(NxDBCalcItem1.FieldName).Clear;
  Table1.Post;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Table1.Edit;
  Table1.FindField(NxDBDateItem1.FieldName).AsDateTime := Now;
  Table1.Post;
end;

procedure TForm1.Table1HireDateChange(Sender: TField);
begin
 // NxDBDateItem1.Empty := Sender.IsNull;
end;

procedure TForm1.DBPropertiesView1Change(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString);
begin
  DBPropertiesView1.BeginUpdate;
  if (Item = NxDBDateItem1) then
  begin
    if Item.AsDateTime = 0 then
    begin
      Table1.Edit;
      Table1.FieldByName(NxDBDateItem1.FieldName).Clear;
      Table1.Post;
    end;
  end;
  DBPropertiesView1.EndUpdate;
end;

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
  if Field.IsNull then
  begin
    DBGrid1.Canvas.Brush.Color := clRed;
    DBGrid1.Canvas.FillRect(Rect);
  end;
end;

end.
