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

📄 unit1.pas

📁 program kehuji uses Forms, Unit1 in ..zxcUnit1.pas {Form1}, Unit2 in ..zxcUnit2.pas {Form2
💻 PAS
字号:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button3: TButton;
    Button4: TButton;
    ADOTable1: TADOTable;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  g_connection : TAdoConnection = nil;
    Bresult: boolean =True;
    count:integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  strpath:string;     //配置文件路径
  strsyspara:Tinifile;  //系统特殊数据存放文件

begin
  strpath := ExtractFilePath(Application.ExeName);
  strsyspara := Tinifile.Create(strpath+'shenchang_CONFIG.INI');
  if NOT FileExists(strpath+'shenchang_CONFIG.INI')  then
     begin
            showmessage('警告:系统配置文件不存在!');
            Bresult:=False;
            Exit;
     end;
  g_connection:=TADOConnection.Create(nil);
  g_connection.ConnectionString:=strsyspara.ReadString('system','connectionstring','');
  g_connection.LoginPrompt := False;
  g_connection.Open;
  self.ADOTable1.Connection:=g_Connection;
  self.ADOTable1.TableName:='user1';
  adotable1.Active:=true;
  statictext1.Caption:='用户名';
  statictext2.Caption:='密码';


  //self.ADOCommand1.Connection := g_Connection;
  //self.ADODataSet1.Connection := g_Connection;

end;

procedure TForm1.Button3Click(Sender: TObject);
var
results:variant;
i:integer;
begin

with  adotable1 do
  begin
      adotable1.Filtered:=false;
      adotable1.Filter:='';


      close;
      adotable1.TableName:='user1';
      open;
      if edit1.Text<>''
      then
      begin
      count:=count+1;
      adotable1.Filter:='用户名='''+edit1.Text+'''';
      adotable1.Filtered:=true;
      if (adotable1.Lookup('用户名',edit1.Text,'密码')=null )and (adotable1.FindFirst<>false)   //在医师表里查找密码
      then
      begin
        results:='';                                            //没设密码
      end
      else
      results:=adotable1.Lookup('用户名',edit1.Text,'密码');  //将找到的密码赋予result变量



      if (results = edit2.Text)                                 //比较输入密码与密码表中密码是否相同
      then
      begin
        showmessage('用户验证通过,欢迎进入');                   //欢迎进入
   {     unit1.username:=edit1.text;                             //记录登陆名
        unit1.usertype:=combobox1.Text;                         //记录登陆用户类型
        unit1.userpass:=edit2.Text;   }                          //记录登陆用户密码
        unit2.Form2.Show;                                      //打开主界面
        form1.hide;                                           //关闭登陆界面
        count:=0;
        edit1.Text:='';
        edit2.Text:='';                                          //清空登陆参数
      end
      else
      begin
        showmessage('用户名或密码错误');                         //登陆失败提示
        if count= 3
        then
        begin
          showmessage('很遗憾,登陆退出');
          form2.close;
          form1.Close;
          count:=0;                                               //密码输入错误次数过多
        end;
      end;

      end;
    end;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin

form1.Close;

end;

end.

⌨️ 快捷键说明

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