📄 am_dz_cxs.pas
字号:
unit am_dz_cxs;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, Mask,ExtCtrls, DB, DBClient,
ComCtrls;
type
Tam_dz_cx = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Panel2: TPanel;
BitBtn2: TSpeedButton;
BitBtn1: TSpeedButton;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
DateTimePicker1: TDateTimePicker;
procedure BitBtn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox3Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
am_dz_cx: Tam_dz_cx;
SearchTime,str,s_zdm,s_logic,s_tj:string;//查找字符串,字段名
Const ss:array [0..7] of string=('dz_dm','dz_xm','dz_dw','dz_lxdh','dz_lxdz','zjlb_mc','dz_zjh','dz_djsj');
implementation
uses DBM, main;
{$R *.dfm}
procedure Tam_dz_cx.BitBtn2Click(Sender: TObject);
begin
close;
end;
procedure Tam_dz_cx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
am_dz_cx:=nil;
end;
procedure Tam_dz_cx.FormCreate(Sender: TObject);
begin
Combobox1.Clear;
Combobox1.Items.add('装备名称');
Combobox1.Items.add('型号');
Combobox1.Items.add('装备编号');
Combobox1.Items.add('生产日期');
Combobox1.Items.add('进场时间');
Combobox1.Items.add('生产厂家');
Combobox1.Items.add('技术状况');
Combobox1.Items.add('所在地点');
end;
procedure Tam_dz_cx.SpeedButton2Click(Sender: TObject);
begin
combobox1.ItemIndex:=-1;
combobox2.ItemIndex:=-1;
edit1.Text:='';
combobox3.ItemIndex:=-1;
edit2.text:='';
end;
procedure Tam_dz_cx.SpeedButton1Click(Sender: TObject);
begin
s_logic:='';
if trim(Combobox1.Text)='' then
begin
application.MessageBox('字段名称不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
if trim(Combobox2.Text)='' then
begin
application.MessageBox('条件不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
//有效性验证
case combobox3.ItemIndex of
0: s_logic:=' and ';
1: s_logic:=' or ';
end;
if Combobox2.Text='模糊查询' then
Edit2.Text:=Edit2.Text+s_zdm+' '+' like '+' '+''''+trim(edit1.Text)+'%'+''''+' '+s_logic+' '
else if (combobox1.Text='生产日期') or (combobox1.Text='进场时间') then
begin
SearchTime:=DateToStr(DateTimePicker1.Date);
Edit2.Text:=Edit2.Text+s_zdm+' '+combobox2.Text+' '+''''+SearchTime+''''+' '+s_logic+' '; end
else
Edit2.Text:=Edit2.Text+s_zdm+' '+combobox2.Text+' '+''''+trim(edit1.Text)+''''+' '+s_logic+' ';
combobox1.ItemIndex:=-1;
combobox2.ItemIndex:=-1;
edit1.Text:='';
combobox3.ItemIndex:=-1;
SpeedButton1.Enabled:=false;
end;
procedure Tam_dz_cx.ComboBox1Change(Sender: TObject);
begin
//s_zdm:=ss[combobox1.itemindex];//以上是获得下拉框中的值
s_zdm:=trim(combobox1.Text);
if (combobox1.Text='生产日期') or (combobox1.Text='进场时间') then
begin
combobox2.Clear;
combobox2.Items.Add('=');
combobox2.Items.Add('<>');
combobox2.Items.Add('<');
combobox2.Items.Add('>');
combobox2.Items.Add('>=');
combobox2.Items.Add('<=');
end
else
begin
combobox2.Clear;
combobox2.Items.Add('=');
combobox2.Items.Add('<>');
combobox2.Items.Add('模糊查询');
end;
end;
procedure Tam_dz_cx.ComboBox2Change(Sender: TObject);
begin
if (combobox1.Text='生产日期') or (combobox1.Text='进场时间') then
begin
DateTimePicker1.Visible:=true;
edit1.Visible:=false;
end
else
begin
DateTimePicker1.Visible:=false;
edit1.Visible:=true;
end;
end;
procedure Tam_dz_cx.ComboBox3Change(Sender: TObject);
begin
if trim(Combobox1.Text)='' then
begin
application.MessageBox('字段名称不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
if trim(Combobox2.Text)='' then
begin
application.MessageBox('条件不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
s_logic:='';
case combobox3.ItemIndex of
0: s_logic:=' and ';
1: s_logic:=' or ';
end;
SpeedButton1.Enabled:=true;
end;
procedure Tam_dz_cx.BitBtn1Click(Sender: TObject);
var S_Edit,Hint:string;
begin
SearchTime:=DateToStr(DateTimePicker1.Date);
S_Edit:=Edit2.Text;
if trim(Combobox1.Text)='' then
begin
application.MessageBox('字段名称不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
if trim(Combobox2.Text)='' then
begin
application.MessageBox('条件不能为空','提示',mb_ok+mb_iconinformation);
exit;
end;
//----------------------------------
if trim(Edit2.Text)='' then
begin
if (combobox1.Text<>'生产日期') and (combobox1.Text<>'进场时间') then
begin
if Combobox2.Text='模糊查询' then
str:=s_zdm+' '+' like '+' '+''''+trim(edit1.Text)+'%'+''''
else
str:=s_zdm+' '+combobox2.Text+' '+''''+trim(edit1.Text)+'''';
end else str:=s_zdm+' '+combobox2.Text+' '+''''+SearchTime+'''';
end else
begin
if Combobox2.Text='模糊查询' then
str:=s_Edit+s_zdm+' '+' like '+' '+''''+trim(edit1.Text)+'%'+''''
else if (combobox1.Text='生产日期') or (combobox1.Text='进场时间') then
begin
str:=s_Edit+s_zdm+' '+combobox2.Text+' '+''''+SearchTime+'''';
end else
str:=s_Edit+s_zdm+' '+combobox2.Text+' '+''''+trim(edit1.Text)+'''';
end;
//---------------------------------
with DM do begin
Adoquery2.Close;
Adoquery2.SQL.Clear;
Adoquery2.SQL.Add('select * from info where '+str);
Adoquery2.Open;
{dm.v_dz.active:=false;
dm.v_dz.active:=true;
dm.V_DZ.Data:=ClientDataSet1.Data;
}
if Adoquery2.RecordCount=0 then begin
application.MessageBox('没有找到符合条件的纪录','提示',mb_ok+mb_iconinformation);
mainForm.statusBar1.Panels.Items[2].Text :='共计 0 条记录';
end else
begin
Hint:='当前表中有'+IntToStr(Adoquery2.RecordCount)+'条记录符合条件';
application.MessageBox(Pchar(hint),'提示',mb_ok+mb_iconinformation);
mainForm.statusBar1.Panels.Items[2].Text :='共计 '+inttostr(ADOQuery2.RecordCount)+' 条记录 ';
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -