?? ucombinationquery.pas
字號:
unit UCombinationQuery;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, Buttons, StdCtrls,dateutils;
type
TForm_CombinationQuery = class(TForm)
GroupBox1: TGroupBox;
ShowListBox: TListBox;
Label1: TLabel;
SpeedButton1: TSpeedButton;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SQLListBox: TListBox;
edit2: TEdit;
FieldListBox: TListBox;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure ComboBox1Click(Sender: TObject);
procedure ShowListBoxClick(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form_CombinationQuery: TForm_CombinationQuery;
implementation
uses Umain;
{$R *.dfm}
procedure TForm_CombinationQuery.SpeedButton3Click(Sender: TObject);
begin
if (trim(edit1.text) <> '') or (Length(trim(edit1.Text)) < 25) then
begin
if ComboBox2.Text = '等于' then
begin
ShowListbox.Items.Add(copy(ComboBox1.Text + ' ', 0, 20) + copy(ComboBox2.Text + ' ', 0, 20) + edit1.Text);
SQLListBox.ItemS.Add(trim(edit2.Text) + ' = ''' + trim(edit1.Text) + '''');
end
else
if ComboBox2.Text = '包含' then
begin
ShowListbox.Items.Add(copy(ComboBox1.Text + ' ', 0, 20) + copy(ComboBox2.Text + ' ', 0, 20) + edit1.Text);
SQLListBox.ItemS.Add(trim(edit2.Text) + ' like''%' + trim(edit1.Text) + '%''');
end;
end
else
begin
beep;
showmessage('您輸入的條件不正確,請重新輸入');
edit1.SetFocus;
end;
end;
procedure TForm_CombinationQuery.SpeedButton1Click(Sender: TObject);
var i: integer;
begin
i := ShowListBox.ItemIndex;
if i < 0 then
begin
showmessage('當前沒有選中記錄');
exit;
end;
ShowListBox.DeleteSelected; //刪除選中的條
SQLListBox.DeleteSelected;
end;
procedure TForm_CombinationQuery.FormShow(Sender: TObject);
var i: integer;
begin
ComboBox2.Items.Clear;
ComboBox2.Text := '等于';
ComboBox2.Items.Add('等于');
ComboBox2.Items.Add('包含');
ComboBox1.Text := '職工編號';
edit2.Text := 'Employee_id ';
with Form_Main.DBGridEhEmployee do
begin
for i := 0 to 32 do
begin
ComboBox1.Items.Add(Columns[i].Title.Caption);
FieldListBox.Items.Add(Columns[i].FieldName);
end;
end;
end;
procedure TForm_CombinationQuery.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
if key = #13 then
SpeedButton3Click(Sender);
end;
procedure TForm_CombinationQuery.ComboBox1Click(Sender: TObject);
var i: integer; //記錄當前選中的combobox選項序列數
begin
i := ComboBox1.ItemIndex + 1;
if i < 0 then //當前沒有選中記錄
exit;
edit2.Text := FieldListbox.Items[i - 1];
end;
procedure TForm_CombinationQuery.ShowListBoxClick(Sender: TObject);
var i: integer;
begin
i := ShowListbox.ItemIndex;
SQLlistbox.Selected[i] := true;
end;
procedure TForm_CombinationQuery.SpeedButton2Click(Sender: TObject);
var i: integer;
begin
if SQLListBox.Count = 0 then
begin
showmessage('未添加條件');
exit;
end;
for i := 0 to SQLListBox.Count - 1 do
begin
if i = 0 then
edit3.Text := ' WHERE ' + SQLListBox.Items[i]
else
edit3.text := edit3.Text + ' AND ' + SQLListBox.Items[i];
end;
// showmessage('等一等,先看看');
if edit3.Text <> '' then
begin
with Form_Main.ADOQDBGrid do
begin
close;
SQL.Clear;
SQL.Add('SELECT * FROM EMPLOYEE');
sql.Add(edit3.Text);
open;
end;
Form_CombinationQuery.WindowState := wsMinimized;
Form_Main.label2.Caption := '共有 ' + inttostr(Form_Main.ADOQDBGrid.RecordCount) + ' 位符合查詢條件的職工';
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -