📄 unit7.pas
字号:
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DBCtrls;
type
Tfmlxfsaddormodify = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
DBLookupComboBox1: TDBLookupComboBox;
DBLookupComboBox2: TDBLookupComboBox;
Edit1: TEdit;
Edit2: TEdit;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1Exit(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit2Exit(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fmlxfsaddormodify: Tfmlxfsaddormodify;
implementation
uses unit2, Unit8, Unit6;
{$R *.dfm}
procedure insert;
begin
if fmlxfs.ADOTable1.Locate('contactid;groupid;detail',vararrayof([fmlxfsaddormodify.dblookupcombobox1.Text,fmlxfsaddormodify.dblookupcombobox2.Text,fmlxfsaddormodify.edit3.Text]),[]) then
begin
showmessage('此联系方式已存在!');
fmlxfsaddormodify.dblookupcombobox1.SetFocus;
end
else
begin
fmlxfs.ADOTable1.Append;
fmlxfs.ADOTable1.FieldByName('contactid').AsString:=fmlxfsaddormodify.dblookupcombobox1.Text;
fmlxfs.ADOTable1.FieldByName('groupid').AsString:=fmlxfsaddormodify.dblookupcombobox2.Text;
fmlxfs.ADOTable1.FieldByName('detail').AsString:=fmlxfsaddormodify.edit3.Text;
fmlxfs.ADOTable1.Post;
//fmlxfs.ADOTable1.Refresh; //为什么不可以用refresh方法
showmessage('插入成功!');
fmlxfsaddormodify.close;
end;
end;
procedure modify;
var
bm:string;
begin
bm:=fmlxfs.ADOTable1.Bookmark;
if (fmlxfs.ADOTable1.Locate('contactid;groupid;detail',vararrayof([fmlxfsaddormodify.edit1.Text,fmlxfsaddormodify.edit2.Text,fmlxfsaddormodify.edit3.Text]),[])) and (fmlxfs.ADOTable1.Bookmark<>bm) then
begin
showmessage('此联系方式已存在!');
fmlxfsaddormodify.edit1.SetFocus;
end
else
begin
fmlxfs.ADOTable1.edit;
fmlxfs.ADOTable1.FieldByName('contactid').AsString:=fmlxfsaddormodify.edit1.Text;
fmlxfs.ADOTable1.FieldByName('groupid').AsString:=fmlxfsaddormodify.edit2.Text;
fmlxfs.ADOTable1.FieldByName('detail').AsString:=fmlxfsaddormodify.edit3.Text;
fmlxfs.ADOTable1.Post;
//fmlxfs.ADOTable1.Refresh; //为什么不可以用refresh方法
showmessage('修改成功!');
fmlxfsaddormodify.close;
end;
end;
procedure Tfmlxfsaddormodify.FormShow(Sender: TObject);
begin
dblookupcombobox1.ListSource:=fmlxr.DataSource1;
dblookupcombobox1.ListField:='contactid;contactname';
dblookupcombobox1.KeyField:='contactid';
dblookupcombobox2.ListSource:=fmlxfsz.DataSource1;
dblookupcombobox2.ListField:='groupid;groupname';
dblookupcombobox2.KeyField:='groupid';
end;
procedure Tfmlxfsaddormodify.BitBtn1Click(Sender: TObject);
begin
if isadd then
begin
if dblookupcombobox1.Text='' then
begin
showmessage('联系人ID不能为空!');
dblookupcombobox1.SetFocus;
exit;
end;
if dblookupcombobox2.Text='' then
begin
showmessage('联系方式组ID不能为空!');
dblookupcombobox2.SetFocus;
exit;
end;
end
else
begin
if edit1.Text='' then
begin
showmessage('联系人ID不能为空!');
edit1.SetFocus;
exit;
end;
if edit2.Text='' then
begin
showmessage('联系方式组ID不能为空!');
edit2.SetFocus;
exit;
end;
end;
if edit3.Text='' then
begin
showmessage('联系方式不能为空!');
edit3.SetFocus;
exit;
end;
if isadd then
begin
insert;
end
else
begin
modify;
end;
end;
procedure Tfmlxfsaddormodify.BitBtn2Click(Sender: TObject);
begin
close;
end;
procedure Tfmlxfsaddormodify.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not ( ((ord(key)>=48) and (ord(key)<=57)) or (ord(key)=8)) then
begin
key:=#16;
exit;
end;
end;
procedure Tfmlxfsaddormodify.Edit1Exit(Sender: TObject);
begin
if edit1.text='' then //文本框为空可以退出
exit;
if length(edit1.Text)<>6 then
begin
showmessage('联系人ID为六位数字!');
edit1.SetFocus;
exit;
end;
end;
procedure Tfmlxfsaddormodify.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not ( ((ord(key)>=48) and (ord(key)<=57)) or (ord(key)=8)) then
begin
key:=#16;
exit;
end;
end;
procedure Tfmlxfsaddormodify.Edit2Exit(Sender: TObject);
begin
if edit2.Text='' then //文本框为空可以退出
exit;
if length(edit2.Text)<>2 then
begin
showmessage('联系方式组ID为两位数字!');
edit2.SetFocus;
exit;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -