📄 unit4.~pas
字号:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls, DBCtrls, Buttons, DB, ADODB,
Grids, DBGrids;
type
TForm4 = class(TForm)
Image1: TImage;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label6: TLabel;
ComboBox1: TComboBox;
Label7: TLabel;
ComboBox2: TComboBox;
Label8: TLabel;
Label9: TLabel;
Edit4: TEdit;
Label10: TLabel;
Edit5: TEdit;
Label11: TLabel;
Edit6: TEdit;
Label12: TLabel;
Edit7: TEdit;
Label13: TLabel;
Edit8: TEdit;
Label14: TLabel;
Edit9: TEdit;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Memo1: TMemo;
Label18: TLabel;
Memo2: TMemo;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
ADOQuery1: TADOQuery;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
Image2: TImage;
Panel7: TPanel;
Panel8: TPanel;
Panel9: TPanel;
Panel10: TPanel;
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure ComboBox4Change(Sender: TObject);
procedure Edit5KeyPress(Sender: TObject; var Key: Char);
procedure Edit6KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.SpeedButton3Click(Sender: TObject);
begin
application.ProcessMessages;
form4.Close;
end;
procedure TForm4.SpeedButton2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
edit7.Text:='';
edit8.Text:='';
edit9.Text:='';
memo1.Text:='';
memo2.Text:='';
end;
function IsVaildEmailAddr(EmailAddr:String):boolean;
var
Number,I:integer; //Number用于给字符'@'计数
TempStr:String;
begin
TempStr:=EmailAddr;
Number:=0;
for I:=1 to Length(TempStr) do
begin
if (TempStr [I]='@') then
INC(Number);
end;
if ((Number =0)or(Number >1)) then
Result:=False//如果不含有字符'@',或者其个数大于1,则不合法
else
begin
if ((TempStr [1]='@')or (TempStr [length(TempStr)]='@')) then
Result:=False//如果字符'@'的位置在字符串开头或者末尾,则不合法
else
begin
I:=pos('@',TempStr);//获取字符'@'在字符串当中的位置
delete(TempStr,1,I);//获取字符串中字符'@'后面的剩余子串
if (Length(TempStr)<3) then
Result:=False //如果剩余子串的长度小于3,则不合法
else
begin
if ((pos('.',TempStr)=0)or(pos('.',TempStr)=length(TempStr))
or (pos('.',TempStr)=1))then
Result:=False//如果剩余的子串当中不含有字符'.',或者其位置在//子串的开头或者末尾,则不合法
else
Result:=True; //以上的判断都通过,则表示地址字符串为合法
end;
end;
end;
end;
procedure TForm4.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8])then
begin
key:=#0;
Application.MessageBox('电话号码只能用数字表示,请重新输入!','警告',0+64)
end;
end;
procedure TForm4.Edit6KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8])then
begin
key:=#0;
Application.MessageBox('邮政编码只能用数字表示,请重新输入!','警告',0+64)
end;
end;
procedure TForm4.SpeedButton1Click(Sender: TObject);
var
h,k:string;
begin
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select * from 用户表 where 用户表.用户名=:a');
parameters.ParamByName('a').Value:=Trim(Edit1.Text);
Open;
end;
h:=edit2.Text;
k:=edit3.Text;
if (edit1.Text='')or(edit2.Text='')or(edit3.Text='') or (edit4.Text='')or (edit5.Text='')or (edit6.Text='')or (edit7.Text='')or (edit8.Text='')or (edit9.Text='')then
begin
application.MessageBox('信息不完整!','错误操作',mb_ok);
exit;
end
else if h<>k then
begin
application.MessageBox('密码不匹配!','错误操作',mb_ok);
exit;
end
else
if ADOQuery1.Eof=false then
begin
ShowMessage('该用户已经存在,请重新填写');
Edit1.Clear
end
else
if not (IsVaildEmailAddr(Edit7.Text)) then
begin
ShowMessage('您输入的电子邮件地址格式不合法!');
Edit7.Clear;
end
else
begin
adoquery1.close;
adoquery1.sql.clear;
Adoquery1.sql.add('insert into 用户表(用户名,密码,性别,出生年,出生月,联系地址,联系电话,邮政编码,电子邮箱,所在系别,所在班级,个人爱好,用户头像,用户备注)values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14)');
Adoquery1.parameters.parambyname('1').value:=''+Edit1.Text+'';
Adoquery1.parameters.parambyname('2').value:=''+Edit2.Text+'';
Adoquery1.parameters.parambyname('3').value:=''+combobox3.Text+'';
Adoquery1.parameters.parambyname('4').value:=''+combobox1.Text+'';
Adoquery1.parameters.parambyname('5').value:=''+combobox2.Text+'';
Adoquery1.parameters.parambyname('6').value:=''+Edit4.Text+'';
Adoquery1.parameters.parambyname('7').value:=''+Edit5.Text+'';
Adoquery1.parameters.parambyname('8').value:=''+Edit6.Text+'';
Adoquery1.parameters.parambyname('9').value:=''+Edit7.Text+'';
Adoquery1.parameters.parambyname('10').value:=''+Edit8.Text+'';
Adoquery1.parameters.parambyname('11').value:=''+Edit8.Text+'';
Adoquery1.parameters.parambyname('12').value:=''+memo1.Text+'';
Adoquery1.parameters.parambyname('13').value:=''+combobox4.Text+'';
Adoquery1.parameters.parambyname('14').value:=''+memo2.Text+'';
Adoquery1.execsql;
application.MessageBox('数据已录入,请查看!','完成提示',mb_ok);
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
edit7.Text:='';
edit8.Text:='';
edit9.Text:='';
memo1.Text:='';
memo2.Text:='';
end
end;
procedure TForm4.ComboBox4Change(Sender: TObject);
begin
case combobox4.ItemIndex of
0:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/A.ico');
1:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/B.ico');
2:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/C.ico');
3:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/D.ico');
4:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/E.ico');
5:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/F.ico');
6:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/G.ico');
7:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/H.ico');
8:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/I.ico');
9:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/J.ico');
10:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/K.ico');
11:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/L.ico');
12:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/M.ico');
13:image2.Picture.LoadFromFile(extractfilepath(paramstr(0))+'./picture/N.ico');
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -