2010-03-05 21:57:25 +00:00
|
|
|
{ rxdbgrid_findunit unit
|
|
|
|
|
2021-05-20 06:28:45 +00:00
|
|
|
Copyright (C) 2005-2021 Lagunov Aleksey alexs75@yandex.ru and Lazarus team
|
2017-01-25 09:56:51 +00:00
|
|
|
original conception from rx library for Delphi (c)
|
2010-03-05 21:57:25 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Library General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
option) any later version with the following modification:
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent modules,and
|
|
|
|
to copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the terms
|
|
|
|
and conditions of the license of that module. An independent module is a
|
|
|
|
module which is not derived from or based on this library. If you modify
|
|
|
|
this library, you may extend this exception to your version of the library,
|
|
|
|
but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
}
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
unit rxdbgrid_findunit;
|
|
|
|
|
2013-02-17 14:31:05 +00:00
|
|
|
{$I rx.inc}
|
2007-08-10 22:15:51 +00:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
|
2018-12-12 06:37:09 +00:00
|
|
|
StdCtrls, ExtCtrls, rxdbgrid, DB, LCLType;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TrxDBGridFindForm }
|
|
|
|
|
|
|
|
TrxDBGridFindForm = class(TForm)
|
|
|
|
BtnFind: TButton;
|
|
|
|
Button2: TButton;
|
|
|
|
CheckBox1: TCheckBox;
|
|
|
|
CheckBox2: TCheckBox;
|
|
|
|
ComboBox1: TComboBox;
|
|
|
|
Edit1: TEdit;
|
|
|
|
Label1: TLabel;
|
2013-02-15 06:46:24 +00:00
|
|
|
Panel1: TPanel;
|
2019-07-30 07:23:31 +00:00
|
|
|
RadioButton1: TRadioButton;
|
|
|
|
RadioButton2: TRadioButton;
|
2007-08-10 22:15:51 +00:00
|
|
|
RadioGroup1: TRadioGroup;
|
|
|
|
procedure BtnFindClick(Sender: TObject);
|
|
|
|
procedure Button2Click(Sender: TObject);
|
2021-04-12 06:33:16 +00:00
|
|
|
procedure Edit1Change(Sender: TObject);
|
2009-08-06 16:59:07 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure FormShow(Sender: TObject);
|
2019-07-30 07:23:31 +00:00
|
|
|
procedure RadioButton1Click(Sender: TObject);
|
2021-04-12 06:33:16 +00:00
|
|
|
procedure RadioGroup1SelectionChanged(Sender: TObject);
|
2007-08-10 22:15:51 +00:00
|
|
|
private
|
2021-04-12 06:33:16 +00:00
|
|
|
FFirstSearch: Boolean;
|
2007-08-10 22:15:51 +00:00
|
|
|
FGrid:TRxDBGrid;
|
|
|
|
FDataSet:TDataSet;
|
|
|
|
procedure SetGrid(AGrid:TRxDBGrid);
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure ShowRxDBGridFindForm(Grid:TRxDBGrid);
|
|
|
|
|
|
|
|
implementation
|
2019-07-30 07:23:31 +00:00
|
|
|
uses rxdbutils, DBGrids, rxdconst, Variants;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
2011-08-27 19:43:40 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure ShowRxDBGridFindForm(Grid: TRxDBGrid);
|
|
|
|
var
|
|
|
|
rxDBGridFindForm: TrxDBGridFindForm;
|
|
|
|
begin
|
|
|
|
rxDBGridFindForm:=TrxDBGridFindForm.Create(Application);
|
|
|
|
rxDBGridFindForm.SetGrid(Grid);
|
|
|
|
rxDBGridFindForm.ShowModal;
|
|
|
|
rxDBGridFindForm.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TrxDBGridFindForm }
|
|
|
|
|
|
|
|
procedure TrxDBGridFindForm.Button2Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
|
2021-04-12 06:33:16 +00:00
|
|
|
procedure TrxDBGridFindForm.Edit1Change(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if RadioGroup1.ItemIndex = 0 then
|
|
|
|
FFirstSearch:=true;
|
|
|
|
end;
|
|
|
|
|
2009-08-06 16:59:07 +00:00
|
|
|
procedure TrxDBGridFindForm.FormCreate(Sender: TObject);
|
2007-09-01 11:39:17 +00:00
|
|
|
begin
|
2009-08-06 16:59:07 +00:00
|
|
|
Caption:=sRxDbGridFindCaption;
|
|
|
|
Label1.Caption:=sRxDbGridFindText;
|
2019-07-30 07:23:31 +00:00
|
|
|
RadioButton1.Caption:=sRxDbGridFindOnField;
|
|
|
|
RadioButton2.Caption:=sRxDbGridFindInAllFileds;
|
2009-08-06 16:59:07 +00:00
|
|
|
CheckBox1.Caption:=sRxDbGridFindCaseSens;
|
|
|
|
CheckBox2.Caption:=sRxDbGridFindPartial;
|
|
|
|
RadioGroup1.Caption:=sRxDbGridFindDirecion;
|
|
|
|
RadioGroup1.Items.Clear;
|
|
|
|
RadioGroup1.Items.Add(sRxDbGridFindRangeAll);
|
|
|
|
RadioGroup1.Items.Add(sRxDbGridFindRangeForw);
|
|
|
|
RadioGroup1.Items.Add(sRxDbGridFindRangeBack);
|
2012-09-19 14:06:46 +00:00
|
|
|
BtnFind.Caption:=sRxFindMore;
|
2018-12-12 06:37:09 +00:00
|
|
|
Button2.Caption:=GetButtonCaption(idButtonCancel);
|
2013-02-15 06:46:24 +00:00
|
|
|
|
|
|
|
RadioGroup1.ItemIndex:=0;
|
2007-09-01 11:39:17 +00:00
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TrxDBGridFindForm.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Edit1.SetFocus;
|
|
|
|
end;
|
|
|
|
|
2019-07-30 07:23:31 +00:00
|
|
|
procedure TrxDBGridFindForm.RadioButton1Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ComboBox1.Enabled:=RadioButton1.Checked;
|
|
|
|
end;
|
|
|
|
|
2021-04-12 06:33:16 +00:00
|
|
|
procedure TrxDBGridFindForm.RadioGroup1SelectionChanged(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if RadioGroup1.ItemIndex = 0 then
|
|
|
|
FFirstSearch:=True;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TrxDBGridFindForm.BtnFindClick(Sender: TObject);
|
|
|
|
var
|
2019-07-30 07:23:31 +00:00
|
|
|
FieldName, S:string;
|
2007-08-10 22:15:51 +00:00
|
|
|
LOptions: TLocateOptions;
|
2013-02-15 06:46:24 +00:00
|
|
|
SearchOrigin:TRxSearchDirection;
|
|
|
|
P:TBookMark;
|
|
|
|
R:boolean;
|
2019-05-17 10:51:57 +00:00
|
|
|
FC: TRxColumn;
|
2019-07-30 07:23:31 +00:00
|
|
|
RF:TField;
|
|
|
|
i: Integer;
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
2014-05-19 12:41:29 +00:00
|
|
|
{ TODO -oalexs : Необходимо переделать поиск по колонке - искать всегда по строковому представлению. Иначе не ищет по дате-времени }
|
2019-05-17 06:56:30 +00:00
|
|
|
if (Edit1.Text<>'') and (ComboBox1.ItemIndex>=0) and (ComboBox1.ItemIndex<ComboBox1.Items.Count) and (ComboBox1.Text<>'') then
|
2010-03-02 17:47:14 +00:00
|
|
|
begin
|
|
|
|
try
|
2019-05-17 10:51:57 +00:00
|
|
|
FC:=FGrid.ColumnByCaption(ComboBox1.Text);
|
|
|
|
if not Assigned(FC) then Exit;
|
|
|
|
FieldName:=FC.FieldName;
|
2010-03-02 17:47:14 +00:00
|
|
|
LOptions:=[];
|
|
|
|
if not CheckBox1.Checked then
|
|
|
|
LOptions:=LOptions+[loCaseInsensitive];
|
|
|
|
|
|
|
|
if CheckBox2.Checked then
|
|
|
|
LOptions:=LOptions+[loPartialKey];
|
2013-02-15 06:46:24 +00:00
|
|
|
|
|
|
|
SearchOrigin:=TRxSearchDirection(RadioGroup1.ItemIndex);
|
2013-02-17 14:31:05 +00:00
|
|
|
{$IFDEF NoAutomatedBookmark}
|
|
|
|
P:=FDataSet.GetBookmark;
|
|
|
|
{$ELSE}
|
2013-02-15 06:46:24 +00:00
|
|
|
P:=FDataSet.Bookmark;
|
2013-02-17 14:31:05 +00:00
|
|
|
{$ENDIF}
|
2021-04-12 06:33:16 +00:00
|
|
|
if SearchOrigin = rsdAll Then
|
|
|
|
begin
|
|
|
|
if FFirstSearch then
|
|
|
|
FDataSet.First
|
|
|
|
else
|
|
|
|
FDataSet.Next;
|
|
|
|
SearchOrigin:=rsdForward;
|
|
|
|
end
|
|
|
|
else
|
2013-02-15 06:46:24 +00:00
|
|
|
if SearchOrigin = rsdForward then
|
|
|
|
FDataSet.Next
|
|
|
|
else
|
|
|
|
if SearchOrigin = rsdBackward then
|
|
|
|
FDataSet.Prior;
|
2019-07-30 07:23:31 +00:00
|
|
|
if RadioButton1.Checked then
|
|
|
|
R:=DataSetLocateThrough(FDataSet, FieldName, Edit1.Text, LOptions, SearchOrigin)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
S:='';
|
|
|
|
for i:=0 to FDataSet.Fields.Count-1 do
|
|
|
|
begin
|
|
|
|
if S<>'' then S:=S + ';';
|
|
|
|
S:=S + FDataSet.Fields[i].FieldName;
|
|
|
|
end;
|
|
|
|
R:=DataSetLocateThroughEx(FDataSet, S, Edit1.Text, LOptions, SearchOrigin, false, RF);
|
|
|
|
if R then
|
|
|
|
FGrid.SelectedField:=RF;
|
|
|
|
end;
|
2010-03-02 17:47:14 +00:00
|
|
|
finally
|
2013-02-17 14:31:05 +00:00
|
|
|
{$IFDEF NoAutomatedBookmark}
|
|
|
|
if not R then
|
|
|
|
FDataSet.GotoBookmark(P);
|
|
|
|
FDataSet.FreeBookmark(P);
|
|
|
|
{$ELSE}
|
2013-02-15 06:46:24 +00:00
|
|
|
if not R then
|
|
|
|
FDataSet.Bookmark:=P;
|
2013-02-17 14:31:05 +00:00
|
|
|
{$ENDIF}
|
2021-04-12 06:33:16 +00:00
|
|
|
FFirstSearch := False;
|
2010-03-02 17:47:14 +00:00
|
|
|
end;
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
2019-05-17 06:56:30 +00:00
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TrxDBGridFindForm.SetGrid(AGrid: TRxDBGrid);
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
begin
|
|
|
|
if AGrid=FGrid then exit;
|
|
|
|
FGrid:=AGrid;
|
|
|
|
ComboBox1.Items.Clear;
|
|
|
|
if Assigned(AGrid) then
|
|
|
|
begin
|
|
|
|
for i:=0 to AGrid.Columns.Count-1 do
|
2015-07-27 12:32:43 +00:00
|
|
|
begin
|
|
|
|
if not (coDisableDialogFind in AGrid.Columns[i].Options) then
|
|
|
|
ComboBox1.Items.Add(AGrid.Columns[i].Title.Caption);
|
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(AGrid.SelectedColumn.Title.Caption);
|
2021-04-12 06:33:16 +00:00
|
|
|
CheckBox1.Checked := not (loCaseInsensitive in AGrid.SearchOptions.QuickSearchOptions);
|
|
|
|
CheckBox2.Checked := loPartialKey in AGrid.SearchOptions.QuickSearchOptions;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
FDataSet:=nil;
|
2017-02-27 05:44:48 +00:00
|
|
|
if Assigned(FGrid) and Assigned(FGrid.DataSource) then
|
|
|
|
FDataSet:=FGrid.DataSource.DataSet;
|
2007-08-10 22:15:51 +00:00
|
|
|
BtnFind.Enabled:=Assigned(FDataSet) and FDataSet.Active
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|