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

📄 login_unit.~pa

📁 网上搜索来的进销存源码
💻 ~PA
字号:
unit Login_Unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Registry, DB, ADODB;
type
  TInfor = class(Tobject)
    UserName: string;
    Password: string;
  end;
type
  TLogin_Form = class(TForm)
    Label1: TLabel;
    UserName_Combox: TComboBox;
    Label2: TLabel;
    Password_Edit: TEdit;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Password_EditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure UserName_ComboxKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    TmpList : TStringlist;
    LogCount: Integer;
    procedure GetUsers;


  public
    class function ShowMe: boolean;
    function  GetLoginTimes:string;
    function  GetSN :TstringList;
    procedure WriteLoginTimes(TmpStr : string);
  end;

var
  G_IsOverTime : Boolean;
  G_UserName: string;
  Login_Form: TLogin_Form;

implementation
uses Data_unit, main_Unit, Reg_Unit;

{$R *.dfm}

{ TLogin_Form }

procedure TLogin_Form.GetUsers;
var reg: TRegistry;
  VNames: TStrings;
  Infor: TInfor;
  i: integer;
begin
  reg := TRegistry.Create;
  VNames := TStringList.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  Reg.OpenKey('Software\FLy\Login', True);
  Reg.GetValueNames(VNames);
  if VNames.Count <= 0 then
  begin
    Infor := TInfor.Create;
    Reg.WriteString('管理员', '');
    Infor.UserName := '管理员';
    Infor.Password := '';
    UserName_Combox.Items.AddObject(infor.username, infor);
  end
  else
  begin
    for i := 0 to VNames.Count - 1 do
    begin
      Infor := TInfor.Create;
      infor.UserName := Vnames.Strings[i];
      infor.password := Reg.ReadString(VNames.Strings[i]);
      UserName_Combox.Items.AddObject(Vnames.Strings[i], infor);
    end;
  end;
  reg.CloseKey;
  reg.Free;
end;

procedure TLogin_Form.FormDestroy(Sender: TObject);
var i: integer;
begin
  TmpList.Free;
  for i := 0 to UserName_Combox.Items.Count - 1 do
    TInfor(UserName_Combox.Items.Objects[i]).Free;
end;

class function TLogin_Form.ShowMe: boolean;
begin
  try
    Login_Form := TLogin_Form.Create(Application);
    Login_Form.ShowModal;
    if Login_FOrm.ModalResult = mrOk then
      Result := True
    else
      Result := false;
  finally
    Login_Form.Free;
    login_form := nil;
  end;
end;


procedure TLogin_Form.FormCreate(Sender: TObject);
begin
  Getusers;
  UserName_Combox.ItemIndex := 0;
end;

procedure TLogin_Form.Password_EditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_return then
    SpeedButton1.Click;
end;

procedure TLogin_Form.UserName_ComboxKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key = vk_return then
  begin
    Password_edit.SetFocus;
  end;
end;


procedure TLogin_Form.FormActivate(Sender: TObject);
begin
  TmpList := TStringList.Create;
  password_edit.SetFocus;
end;

procedure TLogin_Form.SpeedButton1Click(Sender: TObject);
var
  LoginTimes : string;
  TmpStr: string;
begin
  if Password_Edit.Text = TInfor(UserName_Combox.Items.Objects[UserName_Combox.ItemIndex]).Password then
  begin
    G_UserName := UserName_ComBox.Text;
    Main_Form.ShowMenu;
    //以下为判断是否注册过
    TmpStr := Trim(GetSN.Strings[1]); //看注册表中是否有注册信息
    if (TmpStr = Reg_Form.GetZCH(Trim(TmpList.Strings[0]))) and (TmpStr <> '')  then  //是正确的注册号
    begin     
      if Main_Form.Caption ='一通进销存修改版' then
      begin
        Main_Form.Caption :='一通进销存修改版(正式注册版)';
      end;
    end
    else  //没有注册
    begin
      if Main_Form.Caption ='一通进销存修改版' then
      begin
        Main_Form.Caption :='一通进销存修改版(试用版)';
      end;
      LoginTimes := GetLoginTimes;  //得到剩余的登录次数
      if (StrtoIntDef(LoginTimes,0) >= 2)  and (StrtoIntDef(LoginTimes,0) <= 100) then
      begin
        LoginTimes := IntToStr(StrToInt(LoginTimes)-1);
        Application.MessageBox(Pchar('您还未注册,还可以使用本软件'+LoginTimes+'次!'),'提示',Mb_ok or Mb_IconInformation);
        WriteLoginTimes(LoginTimes);   //把剩余次数写回注册表
      end
      else  //到期了
      begin
        if StrToIntDef(LoginTimes,0)= 1 then
        begin
          Application.MessageBox('软件已过试用期限,请注册!','提示');
          G_IsOverTime := True;
          if Application.MessageBox('现在注册吗?','提示',Mb_YesNo or Mb_IconQuestion)=IdYes then
          begin
            if not Assigned(Reg_Form) then
            begin
              Reg_Form := TReg_Form.Create(Self);
            end;
            Reg_Form.ShowModal;   //显示注册窗口
          end
          else
          begin
            //Application.Terminate;  //程序终止
            Main_Form.Close;
          end;                    
        end;
      end;
    end;
    self.ModalResult := mrok
  end
  else
  begin
    Messagebox(Self.handle, '密码错误', '', MB_ICONSTOP + MB_OK);
    Password_Edit.SelectAll;
    inc(LogCount);
    if LogCount >= 3 then self.ModalResult := mrCancel;
  end;
end;

procedure TLogin_Form.SpeedButton2Click(Sender: TObject);
begin
  Main_Form.Close;
end;               

function TLogin_Form.GetLoginTimes: string;  //获取注册表的登录次数
var
  MyReg: TRegistry;
  LoginTimes: string;
begin
  try
    Myreg := TRegistry.Create;
    MyReg.RootKey := HKEY_LOCAL_MACHINE;
    MyReg.OpenKey('Software\FLy\LoginTimes', True);
    LoginTimes := MyReg.ReadString('LoginTimes');
    Result := LoginTimes;
    if LoginTimes ='' then
    begin
      MyReg.WriteString('LoginTimes','100');
      LoginTimes := MyReg.ReadString('LoginTimes');
      Result := LoginTimes;
    end;      
  finally
    MyReg.CloseKey;
    MyReg.Free;
  end;
end;
function TLogin_Form.GetSN: TstringList; //获取到注册表中的注册信息
var
  MyReg : TRegistry;
  sn,reg : string;
begin
  try
    Myreg := TRegistry.Create;
    MyReg.RootKey:=HKEY_LOCAL_MACHINE;
    MyReg.OpenKey('Software\FLy\Reg',True);
    try
      sn := MyReg.ReadString('sn');
      reg := MyReg.ReadString('reg');
    except
      MyReg.WriteString('sn','');
      MyReg.WriteString('reg','');
    end;
    TmpList.Add(sn);
    TmpList.Add(reg);
    Result := TmpList;
  finally
    MyReg.CloseKey;
    MyReg.Free;
  end;
end;
procedure TLogin_Form.WriteLoginTimes(TmpStr: string); //回写剩余登录次数到注册表
var
  MyReg : TRegistry;
begin
  try
    Myreg := TRegistry.Create;
    MyReg.RootKey:=HKEY_LOCAL_MACHINE;
    MyReg.OpenKey('Software\FLy\LoginTimes',False);
    MyReg.WriteString('LoginTimes',TmpStr);
  finally
    MyReg.CloseKey;
    MyReg.Free;
  end;
end;
end.

⌨️ 快捷键说明

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