
{                                                                              }
{ FRM_SearchingLinks                                                           }
{                                                                              }

{***************************************************************}
{                                                               }
{          IB Objects Components and Resources Library          }
{                                                               }
{          Copyright (C) 1996-2015 Jason Wharton                }
{          and CPS - Computer Programming Solutions, Malta, ID  }
{                                                               }
{  This source code unit is released under the terms of the     }
{  CPS Trustware License.                                       }
{  It may be distributed or deployed as source code or in       }
{  compiled form only in compliance with the terms and          }
{  conditions of the CPS Trustware License which may be         }
{  examined at http://www.ibobjects.com/ibo_trustware.html      }
{                                                               }
{***************************************************************}

{******************************************************************************}
{  CONTRIBUTED MODIFICATIONS                                                   }
{  Additions or modifications listed below using format:                       }
{                                                                              }
{  Jason Wharton <jwharton@ibobjects.com>                                      }
{  11/07/2003                                                                  }
{     <comments here>                                                          }
{            Copyright (C) 2013 Jason Wharton                                  }
{                                                                              }
{------------------------------------------------------------------------------}
{  Place your credits and information in the top of the section                }
{  below with any other descriptions or explanations desired.                  }
{------------------------------------------------------------------------------}
{                                                                              }
{                                                                              }
{******************************************************************************}

{$INCLUDE IB_Directives.inc}

unit
  FRM_SearchingLinks;

interface

uses
{$IFnDEF IBO_FPC_USEFPCUNITS}
  Mask, Windows,
{$ELSE}
  Masks, MaskEdit, LCLIntf, LCLType, LMessages,
{$ENDIF}
  Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls, ExtCtrls,

  IB_Session,
//  IB_Samples,
  IB_Components,
  IB_Grid,
  IB_ParamEdit,
  IB_SearchEdit,
  IB_Dialogs, IB_Access;

type
  TfrmSearchingLinks = class(TForm)
    cnSearchingLinks: TIB_Connection;
    qrSearchingLinks: TIB_Query;
    dsSearchingLinks: TIB_DataSource;
    pnSearchingLinks: TPanel;
    grSearchingLinks: TIB_Grid;
    seSearchingLinks: TIB_SearchEdit;
    cbSearchingLinks: TComboBox;
    lbSortOrder: TLabel;
    lbSearchCriteria: TLabel;
    lbEnter: TLabel;
    odGDB: TOpenDialog;
    IB_MonitorDialog1: TIB_MonitorDialog;
    procedure FormActivate(Sender: TObject);
    procedure qrSearchingLinksPrepareSQL(Sender: TIB_Statement);
    procedure cbSearchingLinksChange(Sender: TObject);
    procedure qrSearchingLinksAfterPrepare(Sender: TIB_Statement);
    procedure qrSearchingLinksOrderingChanged(IB_Dataset: TIB_Dataset);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSearchingLinks: TfrmSearchingLinks;

implementation

{$R *.dfm}

procedure TfrmSearchingLinks.FormActivate(Sender: TObject);
begin
  qrSearchingLinks.Prepare;
  qrSearchingLinks.Active := True;
end;

procedure TfrmSearchingLinks.qrSearchingLinksPrepareSQL(Sender: TIB_Statement);
var
  tmpStr: string;
begin
  with qrSearchingLinks do begin
    case Abs( OrderingItemNo ) of
      5: begin
        tmpStr := OldParamValueLinks.LinkValues[ 'ID' ];
        if OrderingItemNo > 0 then begin
          SQLWhereItems.Add( 'ID >= :ID' );
          if (tmpStr = '-999') or (tmpStr = '') or (tmpStr = '999') then begin
            ParamValueLinks.Add( 'ID=-999' );
          end;
        end else begin
          SQLWhereItems.Add( 'ID <= :EMP_NO' );
          if (tmpStr = '-999') or (tmpStr = '') or (tmpStr = '999') then begin
            ParamValueLinks.Add( 'ID=999' );
          end;
        end;
        seSearchingLinks.ParamRefinePos := 6;
      end;
      4: begin
        SQLWhereItems.Add( 'UPPER( CNAME ) STARTING WITH :CNAME' );
        seSearchingLinks.ParamRefinePos := 4;
      end;
      6: begin
        SQLWhereItems.Add( 'UPPER( NAMESITE ) STARTING WITH :NAMESITE' );
        seSearchingLinks.ParamRefinePos := 4;
      end;
    end;
    if cbSearchingLinks.ItemIndex <> Abs( OrderingItemNo ) - 1 then
      cbSearchingLinks.ItemIndex := Abs( OrderingItemNo ) - 1;
  end;
end;

procedure TfrmSearchingLinks.cbSearchingLinksChange(Sender: TObject);
begin
  if qrSearchingLinks.OrderingItemNo <> cbSearchingLinks.ItemIndex + 1 then
    qrSearchingLinks.OrderingItemNo := cbSearchingLinks.ItemIndex + 1;
end;

procedure TfrmSearchingLinks.qrSearchingLinksAfterPrepare(
  Sender: TIB_Statement);
begin
  qrSearchingLinks.GetOrderingItemsList( cbSearchingLinks.Items );
end;

procedure TfrmSearchingLinks.qrSearchingLinksOrderingChanged(
  IB_Dataset: TIB_Dataset);
begin
  with qrSearchingLinks do begin
    cbSearchingLinks.ItemIndex := Abs( OrderingItemNo ) - 1;
    if Assigned( OrderingField ) and OrderingField.IsText then begin
      seSearchingLinks.AutoUpdate := true;
      lbEnter.Visible := false;
    end else begin
      seSearchingLinks.AutoUpdate := false;
      lbEnter.Visible := true;
    end;
  end;
  seSearchingLinks.SetFocus;
end;

procedure TfrmSearchingLinks.FormCreate(Sender: TObject);
begin
//  IB_MonitorDialog1.Show;
//  SampleAppHandler.ConnectDatabase( cnSearchingLinks );
end;

end.


