E
evenzaj
Unregistered / Unconfirmed
GUEST, unregistred user!
各位,我做了一个登陆窗体loginfrm和一个修改密码窗体passwordchangefrm.
还有就是建立一个数据模块:datamoudel,名字为dm_andy
各个窗体的代码为:
unit loginform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Buttons;
type
Tloginfrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ComboBox1: TComboBox;
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
function openfrm:boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
loginfrm: Tloginfrm;
LoginUser:String;
implementation
uses adminform, passwordchangeform, mainform, queryform, operatorform,
data_andy;
{$R *.DFM}
procedure Tloginfrm.BitBtn2Click(Sender: TObject);
begin
application.Terminate ;
end;
procedure Tloginfrm.FormShow(Sender: TObject);
var
i :integer;
begin
with dm_andy.passwrd_query1 do
begin
sql.Text:='select distinct username from passcheck';
open;
comboBox1.Items.Clear;
for i:=1 to recordcount do
begin
comboBox1.Items.Add(fieldbyname('username').asstring);
next;
end;
close;
end;
end;
procedure Tloginfrm.BitBtn1Click(Sender: TObject);
var
a:string;
begin
with dm_andy.passwrd_query1 do
begin
close;
sql.clear;
sql.Add('SELECT username,password FROM passcheck WHERE username=''' +COMBOBOX1.TEXT +'''');
open;
end;
if dm_andy.passwrd_query1.eof then
begin
showmessage(' 无此用户!! ');
combobox1.SetFocus;
end
else
begin
a := edit1.text;
trim(a);
//a:=query1.fieldbyname('password').asstring;
LoginUser:=COMBOBOX1.Text;
if a <> dm_andy.passwrd_query1.fieldbyname('password').asstring then
begin
showmessage(' 密码错误!!');
edit1.SetFocus;
end
else
MODALRESULT := mrok;
end;
end;
function tloginfrm.openfrm: boolean;
begin
if showModal = mrok then
result:=true
else
result:=false;
end;
procedure Tloginfrm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.
unit passwordchangeform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBTables;
type
Tpasswordchangefrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
passwordchangefrm: Tpasswordchangefrm;
implementation
uses loginform, mainform, data_andy;
{$R *.DFM}
procedure Tpasswordchangefrm.BitBtn1Click(Sender: TObject);
var
asql:string;
begin
if trim(edit1.Text)='' then
begin
messagedlg('请输入新密码!',mtinformation,[mbok],0);
edit1.SetFocus;
end
else
if trim(edit2.Text)='' then
begin
messagedlg('请确认新密码!',mtinformation,[mbok],0);
edit2.SetFocus;
end
else
if trim(edit1.Text)<>trim(edit2.Text) then
begin
messagedlg('两次输入结果不一致!',mterror,[mbok],0);
edit1.SetFocus;
end
else
begin
dm_andy.passwrd_query1.close;
dm_andy.passwrd_query1.sql.Clear;
asql:='update passcheck set password='''+edit1.text+''' where username='''+loginfrm.ComboBox1.Text+'''';
dm_andy.passwrd_query1.SQL.text:=asql;
showmessage(asql);
try
dm_andy.passwrd_query1.ExecSQL;
messagedlg('密码修改成功!请记住新密码.',mtinformation,[mbok],0);
edit1.Clear;
edit2.Clear;
passwordchangefrm.Hide;
except
messagedlg('密码修改失败!', mtinformation,[mbok],0);
abort;
end;
end;
end;
procedure Tpasswordchangefrm.BitBtn2Click(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
self.Close;
end;
procedure Tpasswordchangefrm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.
为什么就是改不了密码????????我问过一次了,都说是由于是在passwordchangefrm
窗体里update语句时,不能将loginfrm.combobox1.text值过来,但可以用什么方法呢?
建立数据模块不是可以解决此问题了吗?难道真的没有人会吗????????
我很急,明天要交系统了,今晚要加班了!!!!!!!谢谢!!!
还有就是建立一个数据模块:datamoudel,名字为dm_andy
各个窗体的代码为:
unit loginform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Buttons;
type
Tloginfrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ComboBox1: TComboBox;
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
function openfrm:boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
loginfrm: Tloginfrm;
LoginUser:String;
implementation
uses adminform, passwordchangeform, mainform, queryform, operatorform,
data_andy;
{$R *.DFM}
procedure Tloginfrm.BitBtn2Click(Sender: TObject);
begin
application.Terminate ;
end;
procedure Tloginfrm.FormShow(Sender: TObject);
var
i :integer;
begin
with dm_andy.passwrd_query1 do
begin
sql.Text:='select distinct username from passcheck';
open;
comboBox1.Items.Clear;
for i:=1 to recordcount do
begin
comboBox1.Items.Add(fieldbyname('username').asstring);
next;
end;
close;
end;
end;
procedure Tloginfrm.BitBtn1Click(Sender: TObject);
var
a:string;
begin
with dm_andy.passwrd_query1 do
begin
close;
sql.clear;
sql.Add('SELECT username,password FROM passcheck WHERE username=''' +COMBOBOX1.TEXT +'''');
open;
end;
if dm_andy.passwrd_query1.eof then
begin
showmessage(' 无此用户!! ');
combobox1.SetFocus;
end
else
begin
a := edit1.text;
trim(a);
//a:=query1.fieldbyname('password').asstring;
LoginUser:=COMBOBOX1.Text;
if a <> dm_andy.passwrd_query1.fieldbyname('password').asstring then
begin
showmessage(' 密码错误!!');
edit1.SetFocus;
end
else
MODALRESULT := mrok;
end;
end;
function tloginfrm.openfrm: boolean;
begin
if showModal = mrok then
result:=true
else
result:=false;
end;
procedure Tloginfrm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.
unit passwordchangeform;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBTables;
type
Tpasswordchangefrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
passwordchangefrm: Tpasswordchangefrm;
implementation
uses loginform, mainform, data_andy;
{$R *.DFM}
procedure Tpasswordchangefrm.BitBtn1Click(Sender: TObject);
var
asql:string;
begin
if trim(edit1.Text)='' then
begin
messagedlg('请输入新密码!',mtinformation,[mbok],0);
edit1.SetFocus;
end
else
if trim(edit2.Text)='' then
begin
messagedlg('请确认新密码!',mtinformation,[mbok],0);
edit2.SetFocus;
end
else
if trim(edit1.Text)<>trim(edit2.Text) then
begin
messagedlg('两次输入结果不一致!',mterror,[mbok],0);
edit1.SetFocus;
end
else
begin
dm_andy.passwrd_query1.close;
dm_andy.passwrd_query1.sql.Clear;
asql:='update passcheck set password='''+edit1.text+''' where username='''+loginfrm.ComboBox1.Text+'''';
dm_andy.passwrd_query1.SQL.text:=asql;
showmessage(asql);
try
dm_andy.passwrd_query1.ExecSQL;
messagedlg('密码修改成功!请记住新密码.',mtinformation,[mbok],0);
edit1.Clear;
edit2.Clear;
passwordchangefrm.Hide;
except
messagedlg('密码修改失败!', mtinformation,[mbok],0);
abort;
end;
end;
end;
procedure Tpasswordchangefrm.BitBtn2Click(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
self.Close;
end;
procedure Tpasswordchangefrm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.
为什么就是改不了密码????????我问过一次了,都说是由于是在passwordchangefrm
窗体里update语句时,不能将loginfrm.combobox1.text值过来,但可以用什么方法呢?
建立数据模块不是可以解决此问题了吗?难道真的没有人会吗????????
我很急,明天要交系统了,今晚要加班了!!!!!!!谢谢!!!