?? 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 + -