📄 bmadd.pas
字号:
unit BMadd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons;
type
TFormBmAdd = class(TForm)
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
ADOQuery1: TADOQuery;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
tys:integer;
public
{ Public declarations }
property ty:integer read tys write tys;
end;
var
FormBmAdd: TFormBmAdd;
implementation
uses Data;
{$R *.dfm}
procedure TFormBmAdd.FormShow(Sender: TObject);
begin
edit1.Enabled:=tys=1;
if tys<>1 then //读取
begin
adoquery1.Connection:=dm.ADOConnection1;
adoquery1.SQL.Text:='select * from 部门 where 部门编码='''
+trim(edit1.Text)+'''';
adoquery1.Open;
edit2.text:=adoquery1.fieldbyname('部门名称').AsString;
adoquery1.Close;
adoquery1.free;
end;
end;
procedure TFormBmAdd.BitBtn1Click(Sender: TObject);
var
s:string;
begin
if trim(edit1.Text)='' then
begin
edit1.SetFocus;
application.MessageBox('请输入部门编码','',64);
modalresult:=mrnone;
exit;
end;
if trim(edit2.Text)='' then
begin
edit2.SetFocus;
application.MessageBox('请输入名称','',64);
modalresult:=mrnone;
exit;
end;
if ty=1 then //新
begin
if not dm.ADOConnection1.Execute('select 部门编码 from 部门 where 部门编码='''
+trim(edit1.Text)+'''').EOF then
begin
edit1.SetFocus;
application.MessageBox('已有此部门编码','',64);
modalresult:=mrnone;
exit;
end;
s:='insert into 部门(部门编码,部门名称) values ('''
+trim(edit1.Text)+''','''+trim(edit2.Text)+''')';
dm.ADOConnection1.execute(s);
end
else
begin
s:='update 部门 set 部门名称='''+trim(edit2.Text)+''' where 部门编码='''+trim(edit1.Text)+'''';
dm.ADOConnection1.Execute(s);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -