implementation uses main; {$R *.dfm} var itimes:integer=0;
procedure Tloginform.usernameDropDown(Sender: TObject); var i:integer; begin // 当用户选择已经存在的或用户可以输入数据 username.Clear; with ADOQuery_login do begin close; sql.Clear; sql.Add('select * from psw'); open; if recordcount>0 then begin first; for i:=0 to recordcount-1 do begin username.Items.Add(fieldbyname('用户名').AsString); next; end; end else showmessage('当前没有用户。请原谅'); //当前没有记录就不能对数据进行操作 end; end;
procedure Tloginform.btnokClick(Sender: TObject); var mima,mingzi:string; begin mima:=username.Text; // 用户名 mingzi:=password.Text; //密码 inc(itimes); if username.Items.Count>0 then begin username.ItemIndex:=0; with ADOQuery_login do begin // 当用户名与密码正确并且输入次数少于三次时就登录成功 if locate('用户名',mingzi,[lopartialkey]) and locate('密码',mima,[lopartialkey]) and (itimes<4) then begin close; sql.Clear; sql.Add('select * from psw where 用户名='''+mingzi+''''+' and 密码='''+mima+''''); open; application.CreateForm(TmainForm,mainform); //mainform.StatusBar1.Panels.Items[1].Text:=name; //mainform.StatusBar1.Panels.Items[3].Text:=fieldbyname('权限').AsString; if fieldbyname('权限').AsString='操作员' then begin with mainform do begin N12.Enabled:=false; N13.Enabled:=false; N14.Enabled:=false; end end; loginform.Hide; loginform.Free; mainform.ShowModal; mainform.Free; end else begin if MessageDlg('密码错误,请重新输入',mtConfirmation, [mbYes, mbNo],0)=mrYes then begin username.Clear; username.SetFocus; end else close; end; if itimes>3 then begin showmessage('很抱歉。你没有权力使用本系统'); application.Terminate; end; end; end else showmessage('数据库没有用户名'); end;
procedure Tloginform.btncancelClick(Sender: TObject); begin application.Terminate; end;