home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / d3456 / KBMWABD.ZIP / WABD_DBNavigator.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-15  |  9KB  |  301 lines

  1. unit WABD_DBNavigator;
  2.  
  3. {$I kbmWABD.inc}
  4.  
  5. interface
  6.  
  7. uses SysUtils, Classes, WABD_Objects,Dialogs,DB,Graphics;
  8.  
  9. type
  10.    TWABD_DBNavigator = class;
  11.  
  12.    // Derive from TWABD_FormSection_Base insead of just TWABD_FormSection
  13.    // so that the user can NOT edit the child controls in the WABD Form
  14.    // designer
  15. {
  16.    TWABD_OnResizeTable = procedure(Sender:TObject) of object;
  17.    TWABD_OnRenderTable = procedure(Sender:TObject) of object;
  18.    TWABD_OnRenderTableCell = procedure(Sender:TObject; Cell:TWABD_SectionObject; Col,Row:integer) of object;
  19.    TWABD_OnRenderTableHeaderCell = procedure(Sender:TObject; HeaderCell:TWABD_Label; Col:integer) of object;
  20. }
  21.  
  22.    TWABD_DBNavigator_DataLink = class(TDataLink)
  23.    private
  24.       FOnActiveChanged:TNotifyEvent;
  25.       FOnDatasetChanged:TNotifyEvent;
  26.       FNavigator:TWABD_DBNavigator;
  27.    protected
  28.       procedure DatasetChanged; override;
  29.       procedure ActiveChanged; override;
  30.    published
  31.       property OnActiveChanged:TNotifyEvent read FOnActiveChanged write FOnActiveChanged;
  32.       property OnDatasetChanged:TNotifyEvent read FOnDatasetChanged write FOnDatasetChanged;
  33.    end;
  34.  
  35.    TWABD_DBNavigator = class(TWABD_Object)
  36.    protected
  37.       FDataLink   : TWABD_DBNavigator_DataLink;
  38.       FImgPrevPage: TWABD_Base_Image;
  39.       FImgPrev    : TWABD_Base_Image;
  40.       FImgNext    : TWABD_Base_Image;
  41.       FImgFirst   : TWABD_Base_Image;
  42.       FImgLast    : TWABD_Base_Image;
  43.       FImgNextPage: TWABD_Base_Image;
  44.       FImgEdit    : TWABD_Base_Image;
  45.       FImgDelete  : TWABD_Base_Image;
  46.       FImgAdd     : TWABD_Base_Image;
  47.       FImgRefresh : TWABD_Base_Image;
  48.       FImgPost    : TWABD_Base_Image;
  49.       FImgCancel  : TWABD_Base_Image;
  50.       procedure   Notification(AComponent: TComponent; Operation: TOperation); override;
  51.       function    IsLinked:boolean;
  52.       function    GetDataSource: TDataSource;
  53.       procedure   SetDataSource(NewDataSource: TDataSource);
  54.    public
  55.       constructor Create(AOwner: TComponent); override;
  56.       destructor  Destroy; override;
  57.       function    Object_To_HTML:string; override;
  58.    published
  59.       property    DataSource: TDataSource read GetDataSource write SetDataSource;
  60.       property    ImgPrevPage:TWABD_Base_Image read FImgPrevPage write FImgPrevPage;
  61.       property    ImgPrev:TWABD_Base_Image read FImgPrev write FImgPrev;
  62.       property    ImgNextPage:TWABD_Base_Image read FImgNextPage write FImgNextPage;
  63.       property    ImgNext:TWABD_Base_Image read FImgNext write FImgNext;
  64.       property    ImgFirst:TWABD_Base_Image read FImgFirst write FImgFirst;
  65.       property    ImgLast:TWABD_Base_Image read FImgLast write FImgLast;
  66.       property    ImgEdit:TWABD_Base_Image read FImgEdit write FImgEdit;
  67.       property    ImgDelete:TWABD_Base_Image read FImgDelete write FImgDelete;
  68.       property    ImgAdd:TWABD_Base_Image read FImgAdd write FImgAdd;
  69.       property    ImgRefresh:TWABD_Base_Image read FImgRefresh write FImgRefresh;
  70.       property    ImgPost:TWABD_Base_Image read FImgPost write FImgPost;
  71.       property    ImgCancel:TWABD_Base_Image read FImgCancel write FImgCancel;
  72.    end;
  73.  
  74. implementation
  75.  
  76. // TWABD_DBNavigator_DataLink
  77. procedure TWABD_DBNavigator_DataLink.ActiveChanged;
  78. begin
  79.      if assigned(FOnActiveChanged) then FOnActiveChanged(self);
  80. end;
  81.  
  82. procedure TWABD_DBNavigator_DataLink.DatasetChanged;
  83. begin
  84.      if assigned(FOnDatasetChanged) then FOnDatasetChanged(self);
  85. end;
  86.  
  87. // TWABD_DBNavigator.
  88. constructor TWABD_DBNavigator.Create(AOwner: TComponent);
  89. begin
  90.      inherited;
  91. //     GridX      := 30;
  92. //     GridY      := 30;
  93. //     CellBorder := 0;
  94.  
  95.      FImgPrev:=nil;
  96.      FImgNext:=nil;
  97.      FImgPrevPage:=nil;
  98.      FImgNextPage:=nil;
  99.      FImgFirst:=nil;
  100.      FImgLast:=nil;
  101.      FImgEdit:=nil;
  102.      FImgDelete:=nil;
  103.      FImgAdd:=nil;
  104.      FImgRefresh:=nil;
  105.      FImgPost:=nil;
  106.      FImgCancel:=nil;
  107.  
  108.      FDataLink:=TWABD_DBNavigator_DataLink.Create;
  109.      FDataLink.FNavigator:=self;
  110.      FDataLink.DataSource:=nil;
  111. end;
  112.  
  113. destructor TWABD_DBNavigator.Destroy;
  114. begin
  115.      FDataLink.free;
  116.      inherited;
  117. end;
  118.  
  119. procedure TWABD_DBNavigator.Notification(AComponent: TComponent; Operation: TOperation);
  120. begin
  121.      inherited;
  122.      if (Operation = opRemove) then
  123.      begin
  124.           if AComponent = FDataLink.DataSource then FDataLink.DataSource := nil
  125.           else if AComponent = FImgPrev then FImgPrev:=nil
  126.           else if AComponent = FImgNext then FImgNext:=nil
  127.           else if AComponent = FImgPrevPage then FImgPrevPage:=nil
  128.           else if AComponent = FImgNextPage then FImgNextPage:=nil
  129.           else if AComponent = FImgFirst then FImgFirst:=nil
  130.           else if AComponent = FImgLast then FImgLast:=nil
  131.           else if AComponent = FImgEdit then FImgEdit:=nil
  132.           else if AComponent = FImgDelete then FImgDelete:=nil
  133.           else if AComponent = FImgAdd then FImgAdd:=nil
  134.           else if AComponent = FImgRefresh then FImgRefresh:=nil
  135.           else if AComponent = FImgPost then FImgPost:=nil
  136.           else if AComponent = FImgCancel then FImgCancel:=nil;
  137.      end;
  138. end;
  139.  
  140. function TWABD_DBNavigator.GetDataSource: TDataSource;
  141. begin
  142.      Result := FDataLink.DataSource;
  143. end;
  144.  
  145. procedure TWABD_DBNavigator.SetDataSource(NewDataSource: TDataSource);
  146. begin
  147.      FDataLink.DataSource := NewDataSource;
  148.      if NewDataSource<>nil then NewDataSource.FreeNotification(self);
  149. end;
  150.  
  151. function TWABD_DBNavigator.IsLinked:boolean;
  152. begin
  153.      Result:=(FDataLink<>nil) and (FDataLink.DataSource<>nil) and (FDataLink.DataSource.DataSet<>nil) and
  154.          (FDataLink.DataSource.DataSet.Active);
  155. end;
  156.  
  157. function TWABD_DBNavigator.Object_To_HTML:string;
  158. begin
  159.      // Output images.
  160.      Result:='<p>'+CR;
  161.      if FImgFirst<>nil then Result:=Result+FImgFirst.Object_To_HTML+CR;
  162.      if FImgPrevPage<>nil then Result:=Result+FImgPrevPage.Object_To_HTML+CR;
  163.      if FImgPrev<>nil then Result:=Result+FImgPrev.Object_To_HTML+CR;
  164.      if FImgNext<>nil then Result:=Result+FImgNext.Object_To_HTML+CR;
  165.      if FImgNextPage<>nil then Result:=Result+FImgNextPage.Object_To_HTML+CR;
  166.      if FImgLast<>nil then Result:=Result+FImgLast.Object_To_HTML+CR;
  167.      Result:=Result+'<br>'+CR;
  168.      if FImgAdd<>nil then Result:=Result+FImgAdd.Object_To_HTML+CR;
  169.      if FImgDelete<>nil then Result:=Result+FImgDelete.Object_To_HTML+CR;
  170.      if FImgEdit<>nil then Result:=Result+FImgEdit.Object_To_HTML+CR;
  171.      if FImgRefresh<>nil then Result:=Result+FImgRefresh.Object_To_HTML+CR;
  172.      if FImgPost<>nil then Result:=Result+FImgPost.Object_To_HTML+CR;
  173.      if FImgCancel<>nil then Result:=Result+FImgCancel.Object_To_HTML+CR;
  174.      Result:=Result+'</p>'+CR;
  175. end;
  176.  
  177. (*
  178.         with FImgFirst do
  179.         begin
  180.              AltText:='First';
  181.              LeftPos:=0;
  182.              TopPos:=0;
  183.              Width:=30;
  184.              Height:=30;
  185.         end;
  186.  
  187.      if FImgPrevPage<>nil then
  188.         with FImgPrevPage do
  189.         begin
  190.              AltText:='Prev. Page';
  191.              LeftPos:=31;
  192.              TopPos:=0;
  193.              Width:=30;
  194.              Height:=30;
  195.         end;
  196.  
  197.      if FImgPrev<>nil then
  198.         with FImgPrev do
  199.         begin
  200.              AltText:='Prev';
  201.              LeftPos:=61;
  202.              TopPos:=0;
  203.              Width:=30;
  204.              Height:=30;
  205.         end;
  206.  
  207.      if FImgNext<>nil then
  208.         with FImgNext do
  209.         begin
  210.              AltText:='Next';
  211.              LeftPos:=91;
  212.              TopPos:=0;
  213.              Width:=30;
  214.              Height:=30;
  215.         end;
  216.  
  217.      if FImgNextPage<>nil then
  218.         with FImgNextPage do
  219.         begin
  220.              AltText:='Next Page';
  221.              LeftPos:=121;
  222.              TopPos:=0;
  223.              Width:=30;
  224.              Height:=30;
  225.         end;
  226.  
  227.      if FImgLast<>nil then
  228.         with FImgLast do
  229.         begin
  230.              AltText:='Last';
  231.              LeftPos:=151;
  232.              TopPos:=0;
  233.              Width:=30;
  234.              Height:=30;
  235.         end;
  236.  
  237.  
  238.      if FImgAdd<>nil then
  239.         with FImgAdd do
  240.         begin
  241.              AltText:='Add';
  242.              LeftPos:=0;
  243.              TopPos:=31;
  244.              Width:=30;
  245.              Height:=30;
  246.         end;
  247.  
  248.  
  249.      if FImgDelete<>nil then
  250.         with FImgDelete do
  251.         begin
  252.              AltText:='Delete';
  253.              LeftPos:=31;
  254.              TopPos:=31;
  255.              Width:=30;
  256.              Height:=30;
  257.         end;
  258.  
  259.      if FImgEdit<>nil then
  260.         with FImgEdit do
  261.         begin
  262.              AltText:='Edit';
  263.              LeftPos:=61;
  264.              TopPos:=31;
  265.              Width:=30;
  266.              Height:=30;
  267.         end;
  268.  
  269.      if FImgRefresh<>nil then
  270.         with FImgRefresh do
  271.         begin
  272.              AltText:='Refresh';
  273.              LeftPos:=91;
  274.              TopPos:=31;
  275.              Width:=30;
  276.              Height:=30;
  277.         end;
  278.  
  279.      if FImgPost<>nil then
  280.         with FImgPost do
  281.         begin
  282.              AltText:='Post';
  283.              LeftPos:=121;
  284.              TopPos:=31;
  285.              Width:=30;
  286.              Height:=30;
  287.         end;
  288.  
  289.      if FImgCancel<>nil then
  290.         with FImgCancel do
  291.         begin
  292.              AltText:='Cancel';
  293.              LeftPos:=151;
  294.              TopPos:=31;
  295.              Width:=30;
  296.              Height:=30;
  297.         end;
  298. *)
  299.  
  300. end.
  301.