delphi新手,急求“用户密码修改”窗体代码~窗体界面如下:登录名:edit1旧密码:edit2新密码:edit3确定 取消
我的用户表名:user_inf,它的字段有“登录名”“密码”“权限(此功能还没用)”
希望各位大侠啊,能帮帮我这个菜鸟~感恩不尽!
我的用户表名:user_inf,它的字段有“登录名”“密码”“权限(此功能还没用)”
希望各位大侠啊,能帮帮我这个菜鸟~感恩不尽!
begin if (edit2.Text=edit3.Text)and(edit1.Text<>'')and(edit2.Text<>'')and(edit3.Text<>'') then
begin
adoquery1.Close;
adoquery1.Prepared;
ADOQuery1.SQL.Clear;
adoquery1.SQL.Add('select * from 管理人员 where 登陆名 = '''+s+'''');
adoquery1.Open;
if ADOQuery1.RecordCount>0 then
begin
if adoquery1.FieldByName('密码').AsString=trim(edit1.text) then
begin
adoquery1.Close;
adoquery1.Prepared;
ADOQuery1.SQL.Clear;
adoquery1.SQL.Add('update 管理人员 set 密码 = '''+trim(edit3.Text)+''' where 登陆名 ='''+s+'''');
adoquery1.ExecSQL;
showmessage('修改成功!!!');
form3.Close;
end
else
showmessage('密码不正确!!!');
end;
end
else
showmessage('不能为空!'#13'或者两次密码不正确!!!');
edit1.Clear;
edit2.Clear;
edit3.Clear;end;procedure TForm3.Button2Click(Sender: TObject);
begin form3.Close;
end;procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
end;procedure TForm3.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then
edit2.setfocus;
end;procedure TForm3.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then
edit3.setfocus;
end;procedure TForm3.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then
Button1.setfocus;
end;
上面的这是源代码.PAS
object Form3: TForm3
Left = 378
Top = 220
Width = 302
Height = 209
Align = alCustom
BorderIcons = [biSystemMenu, biMinimize]
Caption = #20462#25913#23494#30721
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 68
Top = 34
Width = 57
Height = 13
AutoSize = False
Caption = #26087#23494#30721#65306
end
object Label2: TLabel
Left = 67
Top = 68
Width = 48
Height = 13
Caption = #26032#23494#30721#65306
end
object Label3: TLabel
Left = 40
Top = 99
Width = 72
Height = 13
Caption = #30830#35748#26032#23494#30721#65306
end
object Edit1: TEdit
Left = 120
Top = 32
Width = 121
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
PasswordChar = '*'
TabOrder = 0
OnKeyPress = Edit1KeyPress
end
object Button1: TButton
Left = 40
Top = 136
Width = 65
Height = 25
Caption = #30830#35748
TabOrder = 3
OnClick = Button1Click
end
object Button2: TButton
Left = 176
Top = 136
Width = 65
Height = 25
Caption = #21462#28040
TabOrder = 4
OnClick = Button2Click
end
object Edit2: TEdit
Left = 120
Top = 64
Width = 121
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
PasswordChar = '*'
TabOrder = 1
OnKeyPress = Edit2KeyPress
end
object Edit3: TEdit
Left = 120
Top = 96
Width = 121
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
PasswordChar = '*'
TabOrder = 2
OnKeyPress = Edit3KeyPress
end
object ADOQuery1: TADOQuery
Connection = Fmain.ADOConnection1
Parameters = <>
Left = 24
Top = 8
end
end
上面这段是窗体的.DFM
var
note:array[1..4]of string;
begin////在代码里可以设定密码的edit属性passwordchar为*,这样输入的密码我们可以看到的是*,被屏蔽
reuslt:=true;
note[1]:='用户名不能为空!';
note[2]:='用户不存在!';
note[3]:='密码不正确';
note[4]:='密码修改成功!';
if edit1.text='' then begin
result:=false;
showmessge(note[1]);
exit;
end;
query1.close;
query1.filter:='登录名='''+edit2.text+''''';
query1.filtered:=true;
query1.open;
//////注意在这个过滤前要query1的sql为select * from uer_inf;
if query1.recordcount= 0 then begin
result:=false;
showmessage(note[2]);
exit;
end;
if query1.fieldvalues['密码']<>edit2.text then begin
result:=false;
showmessage(note[3]);
exit;
end
else
query1.clear;
query1.sql.add(update uer_inf set '密码='''+edit3.text+''''where '登录名='''+edit1.text+'''');
query1.execsql;
showmessage(note[4]);
end;
end;///好了,下面你就可以在确定的click事件中调用canmodify函数了,这个确定和取消你肯定可以搞定了
end;
Text2是新密码
Text1是旧密码
这几个TEXT 要和你那Form上面关连的
begin
if Trim(Edit2.Text)='' then
begin
application.MessageBox('新密码不能为空!','提示',mb_ok+mb_iconinformation);
exit;
end;
if (Trim(Edit2.Text))<>(Trim(Edit3.Text)) then
begin
application.MessageBox('两次输入的密码不一致!','提示',mb_ok+mb_iconinformation);
exit;
end;
tmp:=TADOQuery.Create(nil);
tmp.Connection :=dm_main.adocnmain;
ShowRecord(tmp,'*','SysUser','UserName');
if Trim(Edit1.Text)<>tmp.FieldByName('UserPass').AsString then
begin
application.MessageBox('原密码不正确!','警告',mb_ok+mb_iconwarning);
tmp.close;
tmp.Free;
exit;
end
else
begin
with tmp do
begin
sql.Clear;
sql.Add('UPDATE SysUser SET UserPass=:v1');
parameters.ParamByName('v1').Value :=Trim(Edit2.Text);
ExecSql;
end;
application.MessageBox('密码修改成功!','提示',mb_ok+mb_iconinformation);
end;
procedure ShowRecord(Query:tadoquery;Field:string;Table:string;Order:string);
begin
with query do
begin
close;
sql.Clear;
sql.Add('SELECT '+Field+' FROM '+Table+' ORDER BY '+Order);
//showmessage(sql.Text);
open;
end;
end;
'''+s+''' 是什么意思?