📄 friendsqryunit.~pas
字号:
unit FriendsQryUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;
type
TFriendsQryForm = class(TForm)
Panel1: TPanel;
Bevel1: TBevel;
ComboBox1: TComboBox;
Label1: TLabel;
ComboBox2: TComboBox;
YesButton: TSpeedButton;
CloseButton: TSpeedButton;
Edit1: TEdit;
CheckBox1: TCheckBox;
procedure ComboBox1Change(Sender: TObject);
procedure CloseButtonClick(Sender: TObject);
procedure YesButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FriendsQryForm: TFriendsQryForm;
implementation
uses DataUnit,PublicUnit;
{$R *.dfm}
procedure TFriendsQryForm.ComboBox1Change(Sender: TObject);
begin
if trim(ComboBox1.Text) = '' then Exit;
Edit1.Text := '';
ComboBox2.Text := '';
CheckBox1.Checked := False;
if trim(ComboBox1.Text)= '姓名' then
begin
ComboBox2.Visible := False;
CheckBox1.Enabled := true;
Edit1.Visible := True;
Edit1.SetFocus;
end else
begin
Edit1.Visible := False;
CheckBox1.Enabled := False;
ComboBox2.Visible := true;
combobox2.Items.clear;
ComboBox2.SetFocus;
if Trim(ComboBox1.Text) = '性别' then
begin
ComboBox2.Items.Add('男');
ComboBox2.Items.Add('女');
end
else if Trim(ComboBox1.Text) = '分类' then
begin
ComboBox2.Items.Add('家人');
combobox2.Items.Add('亲戚');
combobox2.Items.Add('朋友');
ComboBox2.Items.Add('同事');
combobox2.Items.Add('同学');
ComboBox2.Items.Add('合作伙伴');
end;
end;
end;
procedure TFriendsQryForm.CloseButtonClick(Sender: TObject);
begin
close;
end;
procedure TFriendsQryForm.YesButtonClick(Sender: TObject);
var
SQLText,Fiel,Cond:string;
begin
if Trim(ComboBox1.Text) = '' then
begin
ShowMessage('请选择查询条件。');
ComboBox1.SetFocus;
end;
if trim(ComboBox1.Text) = '姓名' then
Fiel := 'Name'
else if trim(ComboBox1.Text) = '性别' then
Fiel := 'Sex'
else if trim(ComboBox1.Text) = '分类' then
Fiel := 'Class';
if Edit1.Visible then
Cond := Trim(Edit1.Text)
else
Cond := Trim(ComboBox2.Text);
if CheckBox1.Checked then
SQLText := 'Select * From myfriends where ' + Fiel + ' like ''%'+Cond+'%'''
else
SQLText := 'Select * From myfriends where ' + Fiel + ' = '''+Cond+'''';
try
OpenSQL(DataForm.qrySource,SQLText);
Except
ShowMessage('访问数据库出错,查询失败。');
Exit;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -