unit AsyncNav;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes,
  IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWTMSCtrls,
  IWDBTMSCtrls, IWDBStdCtrls, IWDBAsyncNavigator, IWCompListbox, IWCompEdit,
  IWTMSEdit, IWDBTMSEdit, IWTMSCal, DB, ADODB, IWWebGrid, IWDBAdvWebGrid,
  LeftFrame, Controls, Forms, TopFrame, IWCompLabel;

type
  TformAsyncNav = class(TIWAppForm)
    FrameTopFrame1: TFrameTopFrame;
    FrameLeftFrame1: TFrameLeftFrame;
    IWLabel7: TIWLabel;
    TIWDBAdvWebGrid1: TTIWDBAdvWebGrid;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    IWLabel14: TIWLabel;
    TIWDBDatePicker1: TTIWDBDatePicker;
    IWLabel12: TIWLabel;
    IWLabel9: TIWLabel;
    IWLabel11: TIWLabel;
    TIWDBAdvSpinEdit1: TTIWDBAdvSpinEdit;
    cbImages: TIWComboBox;
    IWLabel8: TIWLabel;
    cbDisplay: TIWComboBox;
    IWLabel1: TIWLabel;
    cbButtonType: TIWComboBox;
    IWLabel6: TIWLabel;
    cbHints: TIWComboBox;
    IWLabel5: TIWLabel;
    cbOrientation: TIWComboBox;
    IWLabel4: TIWLabel;
    IWLabel3: TIWLabel;
    IWLabel2: TIWLabel;
    IWLabel13: TIWLabel;
    TIWDBAsyncNavigator1: TTIWDBAsyncNavigator;
    TIWDBAdvEdit2: TTIWDBAdvEdit;
    TIWDBAdvEdit1: TTIWDBAdvEdit;

    procedure UseDefaultImages();
    procedure UseCustomImages();

    procedure IWAppFormCreate(Sender: TObject);
    procedure TIWDBAsyncNavigator1CustomButtonClick(ASender: TObject;
      const Index: Integer);
    procedure TIWDBAsyncNavigator1AsyncCustomButtonClick(Sender: TObject;
      EventParams: TStringList; const Index: Integer);
    procedure cbOrientationAsyncChange(Sender: TObject;
      EventParams: TStringList);
    procedure cbHintsAsyncChange(Sender: TObject; EventParams: TStringList);
    procedure cbButtonTypeAsyncChange(Sender: TObject;
      EventParams: TStringList);
    procedure cbDisplayAsyncChange(Sender: TObject; EventParams: TStringList);
    procedure cbImagesChange(Sender: TObject);
    procedure TIWDBAsyncNavigator1AsyncInsert(Sender: TObject;
      EventParams: TStringList);
  public
  end;

implementation

{$R *.dfm}

uses
  ServerController;


procedure TformAsyncNav.cbButtonTypeAsyncChange(Sender: TObject;
  EventParams: TStringList);
begin
  if cbButtonType.ItemIndex = 0 then
    TIWDBAsyncNavigator1.ButtonType := btImageButton
  else
    TIWDBAsyncNavigator1.ButtonType := btImage;
end;

procedure TformAsyncNav.cbDisplayAsyncChange(Sender: TObject;
  EventParams: TStringList);
begin
  if cbDisplay.ItemIndex = 0 then
    TIWDBAsyncNavigator1.VisibleButtons := [nbNext,nbPrior,nbFirst,nbLast,nbRefresh,nbEdit,nbInsert,nbPost,nbCancel,nbDelete]
  else
    TIWDBAsyncNavigator1.VisibleButtons := [nbNext,nbPrior,nbFirst,nbLast,nbRefresh];
end;

procedure TformAsyncNav.cbHintsAsyncChange(Sender: TObject;
  EventParams: TStringList);
begin
  if cbHints.ItemIndex = 0 then
    TIWDBAsyncNavigator1.ShowHint := true
  else
    TIWDBAsyncNavigator1.ShowHint := false
end;

procedure TformAsyncNav.cbImagesChange(Sender: TObject);
begin
  if cbImages.ItemIndex = 0 then
  begin
    UseDefaultImages;
  end
  else
  begin
    UseCustomImages;
  end;
end;

procedure TformAsyncNav.cbOrientationAsyncChange(Sender: TObject;
  EventParams: TStringList);
begin
  if cbOrientation.ItemIndex = 0 then
    TIWDBAsyncNavigator1.Orientation := orHorizontal
  else
    TIWDBAsyncNavigator1.Orientation := orVertical;
end;

procedure TformAsyncNav.IWAppFormCreate(Sender: TObject);
begin
  FrameTopFrame1.Align := alTop;
  FrameLeftFrame1.Align := alLeft;

  DataSource1.DataSet.Active := false;
  ADOConnection1.ConnectionString :=
    'Provider=Microsoft.Jet.OLEDB.4.0;Password="";Persist Security Info=True;Data Source= ' +
  WebApplication.ApplicationPath + 'cars.mdb';
  DataSource1.DataSet.Active := true;

  TIWDBAdvWebGrid1.Columns[1].DataField := 'Brand';
  TIWDBAdvWebGrid1.Columns[2].DataField := 'Type';
  TIWDBAdvWebGrid1.Columns[3].DataField := 'KW';
  TIWDBAdvWebGrid1.Columns[4].DataField := 'MyDate';

  UseCustomImages;
  TIWDBAsyncNavigator1.ButtonType := btImage;
end;

procedure TformAsyncNav.TIWDBAsyncNavigator1AsyncCustomButtonClick(Sender: TObject;
  EventParams: TStringList; const Index: Integer);
begin
  WebApplication.ShowMessage('Custom button clicked: ' + IntToStr(Index));
end;

procedure TformAsyncNav.TIWDBAsyncNavigator1AsyncInsert(Sender: TObject;
  EventParams: TStringList);
begin
  //InsertNewRecord
  TIWDBAdvWebGrid1.DataSource.DataSet.Insert;
  TIWDBAdvWebGrid1.DataSource.DataSet.FieldValues['Brand'] := '';
  TIWDBAdvWebGrid1.DataSource.DataSet.Post;
  TIWDBAdvWebGrid1.AsyncUpdateAllCells;
  TIWDBAdvWebGrid1.AsyncSetEditMode(TIWDBAdvWebGrid1.Row);
end;

procedure TformAsyncNav.TIWDBAsyncNavigator1CustomButtonClick(ASender: TObject;
  const Index: Integer);
begin
  WebApplication.ShowMessage('Custom button clicked: ' + IntToStr(Index));
end;

procedure TformAsyncNav.UseCustomImages;
begin
    TIWDBAsyncNavigator1.CustomImages.Cancel_Enabled.URL := '/files/cancel.png';
    TIWDBAsyncNavigator1.CustomImages.Cancel_Disabled.URL := '/files/canceld.png';

    TIWDBAsyncNavigator1.CustomImages.Delete_Enabled.URL := '/files/delete.png';
    TIWDBAsyncNavigator1.CustomImages.Delete_Disabled.URL := '/files/deleted.png';

    TIWDBAsyncNavigator1.CustomImages.Edit_Enabled.URL := '/files/edit.png';
    TIWDBAsyncNavigator1.CustomImages.Edit_Disabled.URL := '/files/editd.png';

    TIWDBAsyncNavigator1.CustomImages.First_Enabled.URL := '/files/first.png';
    TIWDBAsyncNavigator1.CustomImages.First_Disabled.URL := '/files/firstd.png';

    TIWDBAsyncNavigator1.CustomImages.Insert_Enabled.URL := '/files/insert.png';
    TIWDBAsyncNavigator1.CustomImages.Insert_Disabled.URL := '/files/insertd.png';

    TIWDBAsyncNavigator1.CustomImages.Last_Enabled.URL := '/files/last.png';
    TIWDBAsyncNavigator1.CustomImages.Last_Disabled.URL := '/files/lastd.png';

    TIWDBAsyncNavigator1.CustomImages.Next_Enabled.URL := '/files/next.png';
    TIWDBAsyncNavigator1.CustomImages.Next_Disabled.URL := '/files/nextd.png';

    TIWDBAsyncNavigator1.CustomImages.Post_Enabled.URL := '/files/post.png';
    TIWDBAsyncNavigator1.CustomImages.Post_Disabled.URL := '/files/postd.png';

    TIWDBAsyncNavigator1.CustomImages.Prior_Enabled.URL := '/files/prior.png';
    TIWDBAsyncNavigator1.CustomImages.Prior_Disabled.URL := '/files/priord.png';

    TIWDBAsyncNavigator1.CustomImages.Refresh_Enabled.URL := '/files/refresh.png';
    TIWDBAsyncNavigator1.CustomImages.Refresh_Disabled.URL := '/files/refreshd.png';

    TIWDBAsyncNavigator1.ImageHeight := 30;
    TIWDBAsyncNavigator1.ImageWidth := 30;
end;

procedure TformAsyncNav.UseDefaultImages;
begin
    TIWDBAsyncNavigator1.CustomImages.Cancel_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Cancel_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Delete_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Delete_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Edit_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Edit_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.First_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.First_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Insert_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Insert_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Last_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Last_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Next_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Next_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Post_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Post_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Prior_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Prior_Disabled.URL := '';

    TIWDBAsyncNavigator1.CustomImages.Refresh_Enabled.URL := '';
    TIWDBAsyncNavigator1.CustomImages.Refresh_Disabled.URL := '';

    TIWDBAsyncNavigator1.ImageHeight := 24;
    TIWDBAsyncNavigator1.ImageWidth := 24;
end;

end.
