login.pas

来自「delphi 学生选课系统的实现 附有sql 语句」· PAS 代码 · 共 127 行

PAS
127
字号
unit Login;

interface

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

type
  TLoginForm = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure OnClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  LoginForm: TLoginForm;
  UseId,Passwd,Types:String;

implementation

uses DataModule,Main;

{$R *.dfm}

procedure TLoginForm.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TLoginForm.Button1Click(Sender: TObject);
begin
  UseId := Edit1.Text;
  Passwd := Edit2.Text;
  Types := ComboBox1.Text;
  if UseId='' then  //登录证号为空
  begin
    Application.MessageBox('请输入用户名!','登录错误信息',MB_OK);
  end
  else
  begin
    with DataModule.DataModuleForm.A_Login do
    if Types='学生' then
    begin
      Close;
      SQL.Clear;
      SQL.Add('select 学号,口令 from 学生基础信息');
      SQL.Add('where 学号 = ''' + UseId + ''' and 口令 = ''' + Passwd +'''');
      Open;

      if recordcount = 0 then //未在数据库中找到对应记录
      begin
        Application.MessageBox('无效的登录证号或密码!请确认无误后再输入','登录错误信息',MB_OK);
      end

      else
      begin
        MainForm.N3.Visible := false;
        MainForm.N4.Visible := false;
        MainForm.Show;
        LoginForm.Hide;
      end
    end
    else if Types='教师' then
    begin
      Close;
      SQL.Clear;
      SQL.Add('select 工号,口令 from 教师基础信息');
      SQL.Add('where 工号 = ''' + UseId + ''' and 口令 = ''' + Passwd +'''');
      Open;

      if recordcount = 0 then //未在数据库中找到对应记录
      begin
        Application.MessageBox('无效的登录证号或密码!请确认无误后再输入','登录错误信息',MB_OK);
      end

      else
      begin
        MainForm.N2.Visible := false;
        MainForm.N4.Visible := false;
        MainForm.Show;
        LoginForm.Hide;
      end
    end
    else if Types='管理员' then
    begin
      Close;
      SQL.Clear;
      SQL.Add('select 编号,口令 from 管理员信息');
      SQL.Add('where 编号 = ''' + UseId + ''' and 口令 = ''' + Passwd +'''');
      Open;

      if recordcount = 0 then //未在数据库中找到对应记录
      begin
        Application.MessageBox('无效的登录证号或密码!请确认无误后再输入','登录错误信息',MB_OK);
      end

      else
      begin
        MainForm.N2.Visible := false;
        MainForm.N3.Visible := false;
        MainForm.Show;
        LoginForm.Hide;
      end
    end
  end
end;

procedure TLoginForm.OnClose(Sender: TObject; var Action: TCloseAction);
begin
  Application.Terminate;
end;

end.

⌨️ 快捷键说明

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