一百分不够啊,一百元还差不多。:=)自己不做,你怎么提高啊。

解决方案 »

  1.   

    unit Ulogin;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Buttons, ExtCtrls, StdCtrls, jpeg,inifiles,DBCtrls;type
      TFlogin = class(TForm)
        Panel2: TPanel;
        EdtUser: TEdit;
        EdtPwd: TEdit;
        SpeedButton2: TSpeedButton;
        SpeedButton1: TSpeedButton;
        Label7: TLabel;
        Label1: TLabel;
        Label2: TLabel;
        Image1: TImage;
        Label3: TLabel;
        ComboUserName: TComboBox;
        procedure SpeedButton2Click(Sender: TObject);
        procedure SpeedButton1Click(Sender: TObject);
        procedure EdtUserKeyPress(Sender: TObject; var Key: Char);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormShow(Sender: TObject);
        procedure EdtUserExit(Sender: TObject);
        procedure ComboUserNameExit(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        Passed : Boolean;
      end;
    /// 用户名
    var
      Flogin: TFlogin;implementationuses Umain, UlocalDM;{$R *.DFM}procedure TFlogin.SpeedButton2Click(Sender: TObject);
    begin
      //无用户名
      if EdtUser.Text ='' then
      begin
        application.MessageBox(cInputUserName,'提示',mb_ok);
        EdtUser.SetFocus ;
        exit;
      end;
      //用户名非法
      if not Local_data.TUser.Locate('userID',trim(EdtUser.Text),[]) then
      begin
        application.MessageBox(cNoUserName,'提示',mb_ok);
        EdtUser.Text :='';
        EdtUser.SetFocus ;
        exit;
      end;
      // 该用户名的密码有误
      if not (trim(Local_data.TUser.FieldByName('userpwd').AsString)=trim(EdtPwd.Text )) then
      begin
        application.MessageBox(cWrongPassword,'提示',mb_ok);
        EdtPwd.Text :='';
        EdtPwd.SetFocus ;
        exit;
      end;
      FMain.UserID := Local_data.TUser.FieldByName('UserID').AsString;
      FMain.UserName := Local_data.TUser.FieldByName('UserName').AsString;
      FMain.UserType := Local_data.TUser.FieldByName('UserType').AsString;
      FMain.GroupID := Local_data.TUser.FieldByName('GroupID').AsString;
      FMain.DepartmentID := Local_data.TUser.FieldByName('DepartmentID').AsString;
      Passed := true;
      FMain.Show;
      Close;
    end;procedure TFlogin.SpeedButton1Click(Sender: TObject);
    begin
      Application.Terminate;
    end;procedure TFlogin.EdtUserKeyPress(Sender: TObject; var Key: Char);
    begin
      if key=#13 then
        SpeedButton2.Click
      else if key=#27 then
        SpeedButton1.Click ;
    end;procedure TFlogin.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      if not Passed then
        Application.Terminate;
    end;procedure TFlogin.FormShow(Sender: TObject);
    var
      iniFile : TIniFile;
      AppPath,ConString : string;
    begin
      AppPath := ExtractFilePath(Application.ExeName);
      iniFile := TIniFile.Create(AppPath + 'ini\info.ini');
      FMain.DBserverName:=IniFile.ReadString ('local','DBserverName','');
      FMain.DBUserID:=IniFile.ReadString ('local','DBUserID','');
      FMain.DBUserPwd:=IniFile.ReadString ('local','DBUserPwd','');
      FMain.DatabaseName:=IniFile.ReadString ('local','DatabaseName','');
      FMain.ConnectTime:=IniFile.ReadString ('local','ConnectTime','');
      IniFile.Free;
      try
        ConString:='Provider=SQLOLEDB.1;Password='''+FMain.DBUserPwd+''';';
        ConString:=ConString+'Persist Security Info=True;User ID='''+FMain.DBUserID+''';';
        ConString:=ConString+'Initial Catalog='''+FMain.DatabaseName+''';Connect Timeout='+FMain.connecttime+';';
        ConString:=ConString+'Data Source='''+FMain.DBserverName+'''';
       //本地服务器连接设置
        local_data.Connection.connected:=false;
        local_data.Connection.ConnectionString :=ConString;
        local_data.Connection.CommandTimeout :=  strtoint(FMain.ConnectTime);
        local_data.Connection.connected:=true;
      except
        Showmessage('无法打开数据库!');
     end;  Local_data.TUser.Open;
      Local_data.TUser.First;
      ComboUserName.Items.Clear;
      ComboUserName.Items.Add('');
      while not Local_data.TUser.Eof do
      begin
        ComboUserName.Items.Add(Local_data.TUser.FieldByName('UserName').AsString);
        Local_data.TUser.Next;
      end;
     // IniFile.Free;
    end;procedure TFlogin.EdtUserExit(Sender: TObject);
    begin
      if Local_data.TUser.Locate('UserID',EdtUser.Text,[]) then
        ComboUserName.ItemIndex := ComboUserName.Items.IndexOf(Local_data.TUser.FieldByName('UserName').AsString)
      else
        ComboUserName.ItemIndex := 0;
    end;procedure TFlogin.ComboUserNameExit(Sender: TObject);
    begin
      if Local_data.TUser.Locate('UserName',ComboUserName.Text,[]) then
        EdtUser.Text := Local_data.TUser.FieldByName('UserID').AsString;
    end;end.