📄 login.pas
字号:
unit login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg, StdCtrls, Buttons;
type
TLoginForm = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Label3: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure ComboBox1Change(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
bianhao:String;//定义全局变量bianhao(员工编号),为以后的界面传递数值
end;
var
LoginForm: TLoginForm;
implementation
uses DataModule, cw, xs;
{$R *.dfm}
procedure TLoginForm.ComboBox1Change(Sender: TObject);
//部门选择ComboBox的OnChange事件
begin
Label2.Visible:=true;
Combobox2.Visible:=true;
Combobox2.Items.Clear;
Combobox2.Text:='请选择';
with DM.LoginQuery do
begin
Close;
SQL.Clear;
SQL.Add('select distinct EmpName') ;
SQL.Add('from Department,Employee') ;
SQL.Add('where Department.DepId = Employee.DepId') ;
SQL.Add('and DepName=:dname') ;
Parameters.ParamByName('dname').Value:=Trim(Combobox1.Text);
Open;
First;
end;
while not DM.LoginQuery.Eof do
begin
Combobox2.Items.Add(DM.LoginQuery.FieldByName('EmpName').AsString);
DM.LoginQuery.Next;
end;
end;
procedure TLoginForm.ComboBox2Change(Sender: TObject);
//姓名选择ComboBox的OnChange事件
begin
with DM.LoginQuery do
begin
Close;
SQL.Clear;
SQL.Add('Select * From Employee ');
SQL.Add('Where EmpName=:ename');
Parameters.ParamByName('ename').Value:=Trim(ComboBox2.Text);
Open;
if RecordCount>1 then
begin
ShowMessage('你所在的部门有人和你同名!');
InputQuery('编号身份认证','请输入你的编号',bianhao);
end
else
begin
bianhao:=FieldByName('EmpId').Value;
end;
end;
Label3.Visible:=True;
Edit1.Visible:=True;
BitBtn1.Visible:=True;
BitBtn2.Visible:=True;
end;
procedure TLoginForm.BitBtn1Click(Sender: TObject);
//确定按钮的OnClick事件
begin
with DM.LoginQuery do
begin
Close;
SQL.Clear;
SQL.Add('select *') ;
SQL.Add('from Employee') ;
SQL.Add('where EmpId =:eid') ;
Parameters.ParamByName('eid').Value:=bianhao;
SQL.Add('and PassWord =:pswd') ;
Parameters.ParamByName('pswd').Value:=Trim(Edit1.Text);
Open;
if RecordCount>=1 then
begin
Hide;
if ComboBox1.Text='销售部' then
xsForm.Show
else if ComboBox1.Text='财务部' then
cwForm.Show;
end
else
Application.MessageBox('请确认姓名和密码!','用户身份验证失败',MB_OK);
end;
end;
procedure TLoginForm.BitBtn2Click(Sender: TObject);
begin
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -