⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.~pas

📁 使用Delphi 6.0开发用于控制空调的程序
💻 ~PAS
字号:
unit Login;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, ExtCtrls, DB, ADODB, Buttons;

type
  TF_Login = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    E_Password: TEdit;
    Label3: TLabel;
    ADOqryLogin: TADOQuery;
    edt1: TEdit;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure E_PasswordKeyPress(Sender: TObject; var Key: Char);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private

  public
    { Public declarations }
  end;

var
  F_Login: TF_Login;

implementation

uses
 Main;

{$R *.dfm}

procedure TF_Login.BitBtn1Click(Sender: TObject);
var
  str :string;
begin  {*****登录按钮点击事件******}
    if (edt1.Text = '') then       //用户工号输入框为空判断
    begin
      Application.MessageBox('请输入用户工号','提示',MB_ICONWARNING+MB_OK);
      edt1.SetFocus;             //焦点仍在工号输入框中
      exit;
    end
    else
    with ADOqryLogin do
    begin                           //以下代码判断用户的合法性和权限
      Close;
      SQL.Clear;        //清除SQL语句
      SQL.Add('SELECT * FROM Users'); //增加SQL语句
      SQL.Add('WHERE name=:ID');  //条件为用户工号等于输入工号,设置一个参数ID
      Parameters.ParamByName('ID').Value := edt1.Text; //参数ID赋值
      Open;              //执行Add的SQL语句
      if (RecordCount <>1) or (Trim(FieldByName('pw').AsString) <> E_Password.Text) then //如果用户工号或密码不对则提示密码错
      begin
        if (RecordCount <> 1) then
        begin
          Application.MessageBox('用户不存在,请您重新输入','错误',MB_ICONERROR+MB_OK);
          edt1.SetFocus;
          exit;
        end;
        //str := Encrypt(E_Password.Text);
        str := Trim(FieldByName('pw').AsString);
        if E_Password.Text <> Trim(FieldByName('pw').AsString) then
        begin
//          AnsiString str=DM.AQ_SQL.FieldByName("User_Password").AsString;
          Application.MessageBox('用户密码不正确,请您重新输入','提示',MB_ICONERROR+MB_OK+MB_TASKMODAL);
          E_Password.SetFocus;
          exit;
        end;
      end
      else
      begin
        Main.User := FieldByName('name').AsString;
        Main.Operater := Trim(FieldByName('power').AsString) ;
        if frmain.Showing = False then
        begin
                if Main.Operater = '管理员' then
                begin
                    Main.frmain.mm1.Items[0].Items[0].Enabled := True;
                    Main.frmain.mm1.Items[0].Items[1].Enabled := True;
                    Main.frmain.mm1.Items[0].Items[2].Enabled := True;
                    Main.frmain.mm1.Items[0].Items[3].Enabled := True;

                    Main.frmain.mm1.Items[1].Enabled := True;
                    Main.frmain.mm1.Items[2].Enabled := True;
                end
                else
                if Main.Operater = '用户' then
                begin
                    Main.frmain.mm1.Items[0].Items[0].Enabled := False;
                    Main.frmain.mm1.Items[0].Items[1].Enabled := True;
                    Main.frmain.mm1.Items[0].Items[2].Enabled := True;
                    Main.frmain.mm1.Items[0].Items[3].Enabled := False;

                    Main.frmain.mm1.Items[1].Enabled := True;
                    Main.frmain.mm1.Items[2].Enabled := True;
                    Main.frmain.mxBar.Header[1].Button[0].Enabled  := False;
                    Main.frmain.mxBar.Header[1].Button[2].Enabled := False;
                    Main.frmain.mxBar.Header[1].Button[3].Enabled := False;
                end;    

                Main.frmain.tmrTC.Enabled := True;
                F_Login.Tag := 1;  //点击确定按钮标志
     //关闭用户登录窗口
                F_Login.Hide;
         end;
         frmain.ShowModal;
    end;
   
end;
end;

procedure TF_Login.BitBtn2Click(Sender: TObject);
begin  {*****取消按钮点击事件******}
    Close;  //关闭窗口
end;

procedure TF_Login.E_PasswordKeyPress(Sender: TObject; var Key: Char);
begin  {*****密码输入框KeyPress事件******}
    if (Key = #13) then        //按下回车键执行
       BitBtn1Click(self);     //调用BitBtn1按钮点击事件
end;

procedure TF_Login.FormClose(Sender: TObject; var Action: TCloseAction);
begin  {*****登录窗口关闭事件******}
    if(F_Login.Tag <> 1) then
      Application.Terminate;  //中止程序运行
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -