📄 findpublic.pas
字号:
{*******************************************************}
{ }
{ 记录查找 }
{ }
{ 版权所有 (C) 2007 咏南工作室 }
{ }
{*******************************************************}
unit FindPublic;
interface
uses
SysUtils, Classes, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, db,DBGridEh;
type
TfrmFindPublic = class(TForm)
Label1: TLabel;
edtName: TEdit;
bbFind: TBitBtn;
bbNo: TBitBtn;
bbFindDown: TBitBtn;
Panel1: TPanel;
Label2: TLabel;
Label3: TLabel;
edtField: TComboBox;
edtDirection: TComboBox;
edtCaption: TComboBox;
checkAll: TCheckBox;
chkUpCase: TCheckBox;
procedure bbNoClick(Sender: TObject);
procedure bbFindClick(Sender: TObject);
procedure bbFindDownClick(Sender: TObject);
private
{ Private declarations }
sPubText: string;
lPubFiled: Integer;
FGrid: TDBGridEh;
procedure MainShow;
procedure LoadData;
function GridFind(lDirect: Integer): Boolean;
public
{ Public declarations }
end;
procedure FindPublicShow(AGrid:TDBGridEh);
implementation
uses Math, StrUtils;
{$R *.DFM}
procedure FindPublicShow(AGrid:TDBGridEh);
var
frmFindPublic:TfrmFindPublic;
begin
if (not Assigned(AGrid)) or (not AGrid.DataSource.DataSet.Active)
or (AGrid.DataSource.DataSet.IsEmpty) then exit;
frmFindPublic := TfrmFindPublic.Create(nil);
try
frmFindPublic.FGrid:=AGrid;
frmFindPublic.MainShow;
finally
FreeAndNil(frmFindPublic);
end;
end;
procedure TfrmFindPublic.MainShow;
begin
LoadData;
ShowModal;
end;
procedure TfrmFindPublic.LoadData;
var
lCol: Integer;
sCaption, sField: string;
begin
sCaption := '';
edtDirection.ItemIndex := 0;
edtName.Text := sPubText;
//得到GRID的列名称
for lCol := 0 to FGrid.Columns.Count - 1 do
if FGrid.Columns[lCol].Visible then
begin
sCaption := sCaption + FGrid.Columns[lCol].Title.Caption + #13;
sField := sField + FGrid.Columns[lCol].FieldName + #13;
end;
edtField.Items.Text := sField;
edtCaption.Items.Text := sCaption;
if edtCaption.items.Count > 0 then
edtCaption.ItemIndex := 0;
if lPubFiled >= 0 then
edtCaption.ItemIndex := lPubFiled;
end;
procedure TfrmFindPublic.bbNoClick(Sender: TObject);
begin
inherited;
Close;
end;
function TfrmFindPublic.GridFind(lDirect: Integer): Boolean;
var
bFind: Boolean;
lRow: Integer;
begin
FGrid.DataSource.DataSet.DisableControls;
try
bFind := false;
lPubFiled := edtCaption.ItemIndex;
sPubText := edtName.Text;
lRow := FGrid.DataSource.DataSet.RecNo;
if lDirect = 0 then
FGrid.DataSource.DataSet.First
else
FGrid.DataSource.DataSet.RecNo := lRow + 1;
while not FGrid.DataSource.DataSet.Eof do
begin
if checkAll.Checked then
begin
if IfThen(chkUpCase.Checked, edtName.Text, UpperCase(edtName.Text)) <>
IfThen(chkUpCase.Checked,
FGrid.DataSource.DataSet.FieldByName(edtField.Items.Strings[edtCaption.ItemIndex]).AsString,
UpperCase(FGrid.DataSource.DataSet.FieldByName(edtField.Items.Strings[edtCaption.ItemIndex]).AsString)) then
FGrid.DataSource.DataSet.Next
else
begin
bFind := true;
break;
end;
end
else
begin
if Pos(IfThen(chkUpCase.Checked, edtName.Text, UpperCase(edtName.Text)),
IfThen(chkUpCase.Checked,
FGrid.DataSource.DataSet.FieldByName(edtField.Items.Strings[edtCaption.ItemIndex]).AsString,
UpperCase(FGrid.DataSource.DataSet.FieldByName(edtField.Items.Strings[edtCaption.ItemIndex]).AsString))) = 0 then
FGrid.DataSource.DataSet.Next
else
begin
bFind := true;
break;
end;
end;
end;
if not bFind then
begin
FGrid.DataSource.DataSet.RecNo := lRow;
Application.MessageBox('数据没找到,请重新输入条件', '提示', 64);
end;
Result := bFind;
finally
FGrid.DataSource.DataSet.EnableControls;
end;
end;
procedure TfrmFindPublic.bbFindClick(Sender: TObject);
begin
inherited;
if edtName.Text = '' then
exit;
if GridFind(edtDirection.ItemIndex) then
Close;
end;
procedure TfrmFindPublic.bbFindDownClick(Sender: TObject);
begin
inherited;
if edtName.Text = '' then
exit;
GridFind(1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -