📄 unit11.pas
字号:
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids;
type
Tchaxunbumen = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
chaxunbumen: Tchaxunbumen;
implementation
uses Unit1, Unit10, Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9;
{$R *.dfm}
procedure Tchaxunbumen.Button3Click(Sender: TObject);
begin
application.CreateForm(Tshanchubumen,shanchubumen);
shanchubumen.ShowModal;
shanchubumen.Free;
end;
procedure Tchaxunbumen.Button2Click(Sender: TObject);
begin
application.CreateForm(TForm5,Form5);
Form5.ShowModal;
Form5.Free;
end;
procedure Tchaxunbumen.Button4Click(Sender: TObject);
begin
chaxunbumen.Close;
end;
procedure Tchaxunbumen.Button1Click(Sender: TObject);
begin
if (edit1.Text='') and (edit2.Text='') then
begin
application.MessageBox('请输入查询条件!!','木鱼工作室',mb_iconhand+mb_yesno);
edit1.SetFocus;
end //都为空,出错 焦点放到部门代码上面
else
begin
if (edit1.Text<>'') and (edit2.Text='') then
begin
with dm.ADOQuery1 do
begin
sql.Clear;
sql.Add('select * from bumenxinxi where 部门代码='''+edit1.Text+'''' );
Open;
dbgrid1.Columns[0].FieldName:='部门代码';
dbgrid1.Columns[1].FieldName:='部门名称';
dbgrid1.Columns[2].FieldName:='领导姓名';
dbgrid1.Columns[3].FieldName:='联系地址';
dbgrid1.Columns[4].FieldName:='联系电话';
dbgrid1.Columns[5].FieldName:='简介';
end
end //按部门代码查询
else
begin
if (edit1.Text='') and (edit2.Text<>'') then
begin
with dm.ADOQuery1 do
begin
sql.Clear;
sql.Add('select * from bumenxinxi where 部门名称='''+edit2.Text+'''' );
Open;
dbgrid1.Columns[0].FieldName:='部门代码';
dbgrid1.Columns[1].FieldName:='部门名称';
dbgrid1.Columns[2].FieldName:='领导姓名';
dbgrid1.Columns[3].FieldName:='联系地址';
dbgrid1.Columns[4].FieldName:='联系电话';
dbgrid1.Columns[5].FieldName:='简介';
end
end //按部门名称查询
else
begin
with dm.ADOQuery1 do
begin
sql.Clear;
sql.Add('select * from bumenxinxi where 部门代码='''+edit1.Text+''' and 部门名称='''+edit2.Text+'''' );
Open;
dbgrid1.Columns[0].FieldName:='部门代码';
dbgrid1.Columns[1].FieldName:='部门名称';
dbgrid1.Columns[2].FieldName:='领导姓名';
dbgrid1.Columns[3].FieldName:='联系地址';
dbgrid1.Columns[4].FieldName:='联系电话';
dbgrid1.Columns[5].FieldName:='简介';
end
end;//都不为空的情况
end;
if dm.ADOQuery1.Eof then
begin
application.MessageBox('对不起,数据库中没有您所要的信息。请与管理员联系!!','错误',mb_iconhand+mb_yesno);
edit1.Text:='';
edit2.Text:='';
edit1.SetFocus;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -