RxFPC:enable find in RxDBGrid for all collumns

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7088 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2019-07-30 07:23:31 +00:00
parent 9436da6a2c
commit 4dd550b2df
10 changed files with 181 additions and 78 deletions

View File

@ -522,6 +522,10 @@ msgstr "Sensitivo MAY/min"
msgid "Direction"
msgstr "Dirección"
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr ""
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr "Buscar en campo"

View File

@ -514,6 +514,10 @@ msgstr "Rozróżniaj wielkość liter"
msgid "Direction"
msgstr "Kierunek"
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr ""
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr "Szukaj w polu"

View File

@ -503,6 +503,10 @@ msgstr ""
msgid "Direction"
msgstr ""
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr ""
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr ""

View File

@ -513,6 +513,10 @@ msgstr "Регистро-зависимо"
msgid "Direction"
msgstr "Направление"
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr "Поиск во всех полях"
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr "Искать по полю"

View File

@ -514,6 +514,10 @@ msgstr "Harfe duyarlı"
msgid "Direction"
msgstr "Yön"
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr ""
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr "Alanda bul"

View File

@ -518,6 +518,10 @@ msgstr "Регістрозалежно"
msgid "Direction"
msgstr "Напрямок"
#: rxdconst.srxdbgridfindinallfileds
msgid "Find in all fields"
msgstr ""
#: rxdconst.srxdbgridfindonfield
msgid "Find on field"
msgstr "Шукати по полю"

View File

@ -1,12 +1,12 @@
object rxDBGridFindForm: TrxDBGridFindForm
Left = 688
Height = 260
Height = 287
Top = 327
Width = 493
Width = 508
ActiveControl = Edit1
Caption = 'Find'
ClientHeight = 260
ClientWidth = 493
ClientHeight = 287
ClientWidth = 508
OnCreate = FormCreate
OnShow = FormShow
Position = poScreenCenter
@ -17,36 +17,22 @@ object rxDBGridFindForm: TrxDBGridFindForm
AnchorSideBottom.Control = Edit1
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 13
Height = 17
Top = 6
Width = 56
Width = 69
BorderSpacing.Around = 6
Caption = 'Text to find'
FocusControl = Edit1
ParentColor = False
end
object Label2: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Edit1
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = ComboBox1
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 13
Top = 52
Width = 56
BorderSpacing.Around = 6
Caption = 'Find at filed'
ParentColor = False
end
object BtnFind: TButton
AnchorSideRight.Control = Button2
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 340
Height = 31
Top = 223
Width = 81
Left = 352
Height = 41
Top = 240
Width = 86
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -63,13 +49,12 @@ object rxDBGridFindForm: TrxDBGridFindForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 427
Height = 31
Top = 223
Width = 60
Left = 444
Height = 41
Top = 240
Width = 58
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Around = 6
BorderSpacing.InnerBorder = 4
Cancel = True
@ -84,42 +69,42 @@ object rxDBGridFindForm: TrxDBGridFindForm
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 18
Height = 21
Top = 25
Width = 469
Height = 34
Top = 29
Width = 484
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
TabOrder = 0
end
object ComboBox1: TComboBox
AnchorSideLeft.Control = Label2
AnchorSideTop.Control = Label2
AnchorSideLeft.Control = RadioButton1
AnchorSideTop.Control = RadioButton1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 12
Height = 21
Top = 71
Width = 475
Height = 33
Top = 98
Width = 490
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
ItemHeight = 13
ItemHeight = 0
Style = csDropDownList
TabOrder = 1
end
object RadioGroup1: TRadioGroup
AnchorSideLeft.Control = Panel1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ComboBox1
AnchorSideTop.Control = RadioButton2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 119
Height = 54
Top = 98
Width = 368
Left = 139
Height = 66
Top = 166
Width = 363
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
AutoSize = True
@ -135,8 +120,8 @@ object rxDBGridFindForm: TrxDBGridFindForm
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 36
ClientWidth = 364
ClientHeight = 48
ClientWidth = 361
Columns = 3
Items.Strings = (
'All'
@ -147,25 +132,25 @@ object rxDBGridFindForm: TrxDBGridFindForm
end
object Panel1: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ComboBox1
AnchorSideTop.Control = RadioButton2
AnchorSideTop.Side = asrBottom
Left = 6
Height = 54
Top = 98
Width = 107
Height = 66
Top = 166
Width = 127
AutoSize = True
BorderSpacing.Around = 6
ClientHeight = 54
ClientWidth = 107
ClientHeight = 66
ClientWidth = 127
TabOrder = 5
object CheckBox2: TCheckBox
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = CheckBox1
AnchorSideTop.Side = asrBottom
Left = 7
Height = 17
Top = 30
Width = 70
Height = 23
Top = 36
Width = 88
BorderSpacing.Around = 6
Caption = 'Partial key'
TabOrder = 0
@ -174,12 +159,39 @@ object rxDBGridFindForm: TrxDBGridFindForm
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
Left = 7
Height = 17
Height = 23
Top = 7
Width = 93
Width = 113
BorderSpacing.Around = 6
Caption = 'Case sensetive'
TabOrder = 1
end
end
object RadioButton1: TRadioButton
AnchorSideLeft.Control = Label1
AnchorSideTop.Control = Edit1
AnchorSideTop.Side = asrBottom
Left = 6
Height = 23
Top = 69
Width = 98
Caption = 'Find at field'
Checked = True
OnClick = RadioButton1Click
TabOrder = 6
TabStop = True
end
object RadioButton2: TRadioButton
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ComboBox1
AnchorSideTop.Side = asrBottom
Left = 6
Height = 23
Top = 137
Width = 121
BorderSpacing.Around = 6
Caption = 'Find in all fields'
OnClick = RadioButton1Click
TabOrder = 7
end
end

View File

@ -51,13 +51,15 @@ type
ComboBox1: TComboBox;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Panel1: TPanel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioGroup1: TRadioGroup;
procedure BtnFindClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
private
FGrid:TRxDBGrid;
FDataSet:TDataSet;
@ -69,7 +71,7 @@ type
procedure ShowRxDBGridFindForm(Grid:TRxDBGrid);
implementation
uses rxdbutils, DBGrids, rxdconst;
uses rxdbutils, DBGrids, rxdconst, Variants;
{$R *.lfm}
@ -94,7 +96,8 @@ procedure TrxDBGridFindForm.FormCreate(Sender: TObject);
begin
Caption:=sRxDbGridFindCaption;
Label1.Caption:=sRxDbGridFindText;
Label2.Caption:=sRxDbGridFindOnField;
RadioButton1.Caption:=sRxDbGridFindOnField;
RadioButton2.Caption:=sRxDbGridFindInAllFileds;
CheckBox1.Caption:=sRxDbGridFindCaseSens;
CheckBox2.Caption:=sRxDbGridFindPartial;
RadioGroup1.Caption:=sRxDbGridFindDirecion;
@ -113,14 +116,21 @@ begin
Edit1.SetFocus;
end;
procedure TrxDBGridFindForm.RadioButton1Click(Sender: TObject);
begin
ComboBox1.Enabled:=RadioButton1.Checked;
end;
procedure TrxDBGridFindForm.BtnFindClick(Sender: TObject);
var
FieldName:string;
FieldName, S:string;
LOptions: TLocateOptions;
SearchOrigin:TRxSearchDirection;
P:TBookMark;
R:boolean;
FC: TRxColumn;
RF:TField;
i: Integer;
begin
{ TODO -oalexs : Необходимо переделать поиск по колонке - искать всегда по строковому представлению. Иначе не ищет по дате-времени }
if (Edit1.Text<>'') and (ComboBox1.ItemIndex>=0) and (ComboBox1.ItemIndex<ComboBox1.Items.Count) and (ComboBox1.Text<>'') then
@ -147,7 +157,20 @@ begin
else
if SearchOrigin = rsdBackward then
FDataSet.Prior;
R:=DataSetLocateThrough(FDataSet, FieldName, Edit1.Text, LOptions, SearchOrigin);
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;
finally
{$IFDEF NoAutomatedBookmark}
if not R then

View File

@ -111,6 +111,9 @@ procedure InternalRestoreFields(DataSet: TDataSet; IniFile: TObject;
function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string;
const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll; ASearchFromStart:boolean = false): Boolean;
function DataSetLocateThroughEx(DataSet: TDataSet; const KeyFields: string;
const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection; ASearchFromStart:boolean; out ResultField:TField): Boolean;
procedure SaveFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile);
procedure RestoreFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile;
RestoreVisible: Boolean);
@ -167,7 +170,7 @@ procedure _DBError(const Msg: string);
implementation
uses Forms, Controls, Dialogs, RXDConst, rxlclutils, FileUtil,
uses Forms, Controls, Dialogs, RXDConst, rxlclutils, FileUtil, Variants,
RxAppUtils, RxStrUtils, Math, rxdateutil, LazUTF8;
{ Utility routines }
@ -389,16 +392,38 @@ end;
function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string;
const KeyValues: Variant; Options: TLocateOptions; SearchOrigin:TRxSearchDirection = rsdAll;
ASearchFromStart:boolean = false): Boolean;
var
R: TField;
begin
Result:=DataSetLocateThroughEx(DataSet, KeyFields, KeyValues, Options, SearchOrigin, ASearchFromStart, R)
end;
procedure SaveFields(DataSet: TDataSet; IniFile: TIniFile);
begin
InternalSaveFields(DataSet, IniFile, DataSetSectionName(DataSet));
end;
procedure RestoreFields(DataSet: TDataSet; IniFile: TIniFile;
RestoreVisible: Boolean);
begin
InternalRestoreFields(DataSet, IniFile, DataSetSectionName(DataSet),
RestoreVisible);
end;
function DataSetLocateThroughEx(DataSet: TDataSet; const KeyFields: string;
const KeyValues: Variant; Options: TLocateOptions;
SearchOrigin: TRxSearchDirection; ASearchFromStart: boolean; out
ResultField: TField): Boolean;
var
FieldCount: Integer;
Fields: TList;
SingleValueFind:boolean;
function CompareField(Field: TField; Value: Variant): Boolean;
var
S,S1: string;
begin
if (Field.DataType = ftString) or (loPartialKey in Options) then
if (Field.DataType = ftString) or (loPartialKey in Options) or SingleValueFind then
begin
if loCaseInsensitive in Options then
begin
@ -439,15 +464,43 @@ var
function CompareRecord: Boolean;
var
I: Integer;
V:Variant;
B: Boolean;
begin
if FieldCount = 1 then
Result := CompareField(TField(Fields.First), KeyValues)
else
begin
Result := True;
if not VarIsArray(KeyValues) then
begin
SingleValueFind:=true;
V:=KeyValues;
end
else
if (Length(KeyValues)=1) then
begin
SingleValueFind:=true;
V:=KeyValues[0];
end;
if SingleValueFind then
begin
B:=false;
for I := 0 to FieldCount - 1 do
begin
B:=B or CompareField(TField(Fields[I]), V);
if B then
begin
ResultField:=TField(Fields[I]);
Exit(B);
end;
end;
Exit(B);
end
else
for I := 0 to FieldCount - 1 do
begin
//Result := Result and CompareField(TField(Fields[I]), KeyValues[I]);
if not CompareField(TField(Fields[I]), KeyValues[I]) then
Exit(false);
end;
@ -458,6 +511,8 @@ var
Bookmark: TBookmark;
begin
Result := False;
ResultField:=nil;
SingleValueFind:=false;
with DataSet do
begin
CheckBrowseMode;
@ -524,18 +579,6 @@ begin
Fields.Free;
end;
procedure SaveFields(DataSet: TDataSet; IniFile: TIniFile);
begin
InternalSaveFields(DataSet, IniFile, DataSetSectionName(DataSet));
end;
procedure RestoreFields(DataSet: TDataSet; IniFile: TIniFile;
RestoreVisible: Boolean);
begin
InternalRestoreFields(DataSet, IniFile, DataSetSectionName(DataSet),
RestoreVisible);
end;
procedure SaveFieldsReg(DataSet: TDataSet; IniFile: TRegIniFile);
begin
InternalSaveFields(DataSet, IniFile, DataSetSectionName(DataSet));

View File

@ -150,6 +150,7 @@ resourcestring
sRxDbGridFindCaption = 'Find data';
sRxDbGridFindText = 'Text to find';
sRxDbGridFindOnField = 'Find on field';
sRxDbGridFindInAllFileds = 'Find in all fields';
sRxDbGridFindCaseSens = 'Case sensetive';
sRxDbGridFindPartial = 'Partial key';
sRxDbGridFindDirecion = 'Direction';