unit UnitDemo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleServer, USBPassR_TLB, USBPassW_TLB;

type
  TfrmDemo = class(TForm)
    BtWrite: TButton;
    BtReadA: TButton;
    BtChangePassAD: TButton;
    BtClear: TButton;
    BtAbout: TButton;
    BtClearWindows: TButton;
    BtExit: TButton;
    BtReadB: TButton;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    uPassWrite: TuPassWrite;
    Label13: TLabel;
    Label14: TLabel;
    BtChangePassWD: TButton;
    uPassRead: TuPassRead;
    procedure BtExitClick(Sender: TObject);
    procedure BtWriteClick(Sender: TObject);
    procedure BtClearWindowsClick(Sender: TObject);
    procedure BtAboutClick(Sender: TObject);
    procedure BtClearClick(Sender: TObject);
    procedure BtChangePassADClick(Sender: TObject);
    procedure BtReadBClick(Sender: TObject);
    procedure BtReadAClick(Sender: TObject);
    procedure BtChangePassWDClick(Sender: TObject);
  private
    function ShowInfo: boolean;
    function ShowInfoRead: boolean;
    function BooleanToStr(Bool: boolean): string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDemo: TfrmDemo;

implementation

uses UnitDialog;

{$R *.dfm}

procedure TfrmDemo.BtExitClick(Sender: TObject);
begin
   self.Close;
end;

procedure TfrmDemo.BtWriteClick(Sender: TObject);
var
   strPass_WD:WideString;
   strpass_AD:WideString;
   strMsg:string;
begin
   BtClearWindowsClick(nil);
   frmdialog.Caption :='请输入高级密码';
   frmdialog.EditPassWD.Text :='';
   if frmdialog.ShowModal =mrOk then
   begin
       strpass_AD:=trim(frmdialog.EditPassWD.Text );
   end
   else
      exit;
   frmdialog.Caption :='请输入用户密码';
   frmdialog.EditPassWD.Text :='';
   if frmdialog.ShowModal =mrOk then
   begin
       strPass_WD:=trim(frmdialog.EditPassWD.Text );
   end
   else
      exit;
    if uPassWrite.PassCreate(strpass_ad,strpass_WD) then
        begin
           ShowInfo;
        end;
    strmsg:=uPassWrite.TBack_MsgStr ;
    ShowMessage(strmsg);
end;
 
function TfrmDemo.ShowInfo:boolean;
begin
   Label1.Caption:='USB磁盘驱动器   ：'+uPassWrite.TBack_DiskName ;
   Label2.Caption:='USBPass授权编号 ：'+uPassWrite.TBack_DrvKeyNumber ;
   Label3.Caption:='授权写入时间    ：'+datetimetostr(uPassWrite.TBack_RegDate ) ;
   Label4.Caption:='授权软件代码    ：'+uPassWrite.TBack_SoftCode   ;
   Label5.Caption:='使用单位名称    ：'+uPassWrite.TBack_UnitName ;
   Label6.Caption:='授权软件代码    ：'+uPassWrite.TBack_CustomA   ;
   Label7.Caption:='使用单位名称    ：'+uPassWrite.TBack_CustomB  ;
   Label8.Caption:='是否限制使用次数：'+BooleanToStr(uPassWrite.TBack_IsTime)  ;
   Label9.Caption:='剩余使用次数    ：'+floattostr(uPassWrite.TBack_UseTime ) ;
   Label10.Caption:='是否限制使用天数：'+BooleanToStr(uPassWrite.TBack_IsFate )  ;
   Label11.Caption:='剩余使用天数    ：'+floattostr(uPassWrite.TBack_UseFate ) ;
   Label12.Caption:='是否任意条件触发：'+BooleanToStr(uPassWrite.TBack_IsAll  )  ;
   Label13.Caption:='最后使用日期    ：'+Datetostr(uPassWrite.TBack_LastDate ) ;
   Label14.Caption:='附加信息        ：'+uPassWrite.TBack_AnnexInfo   ;
end;
function TfrmDemo.ShowInfoRead:boolean;
begin
   Label1.Caption:='USB磁盘驱动器   ：'+uPassRead.TBack_DiskName ;
   Label2.Caption:='USBPass授权编号 ：'+uPassRead.TBack_DrvKeyNumber ;
   Label3.Caption:='授权写入时间    ：'+datetimetostr(uPassRead.TBack_RegDate ) ;
   Label4.Caption:='授权软件代码    ：'+uPassRead.TBack_SoftCode   ;
   Label5.Caption:='使用单位名称    ：'+uPassRead.TBack_UnitName ;
   Label6.Caption:='授权软件代码    ：'+uPassRead.TBack_CustomA   ;
   Label7.Caption:='使用单位名称    ：'+uPassRead.TBack_CustomB  ;
   Label8.Caption:='是否限制使用次数：'+BooleanToStr(uPassRead.TBack_IsTime)  ;
   Label9.Caption:='剩余使用次数    ：'+floattostr(uPassRead.TBack_UseTime ) ;
   Label10.Caption:='是否限制使用天数：'+BooleanToStr(uPassRead.TBack_IsFate )  ;
   Label11.Caption:='剩余使用天数    ：'+floattostr(uPassRead.TBack_UseFate ) ;
   Label12.Caption:='是否任意条件触发：'+BooleanToStr(uPassRead.TBack_IsAll  )  ;
   Label13.Caption:='最后使用日期    ：'+Datetostr(uPassRead.TBack_LastDate ) ;
   Label14.Caption:='附加信息        ：'+uPassRead.TBack_AnnexInfo   ;
end;
function TfrmDemo.BooleanToStr(Bool:boolean):string;
begin
    if bool=false then
       Result:='False'
    else
       Result:='True';
end;

procedure TfrmDemo.BtClearWindowsClick(Sender: TObject);
begin
   Label1.Caption:='*';
   Label2.Caption:='*';
   Label3.Caption:='*';
   Label4.Caption:='*';
   Label5.Caption:='*';
   Label6.Caption:='*';
   Label7.Caption:='*';
   Label8.Caption:='*';
   Label9.Caption:='*';
   Label10.Caption:='*';
   Label11.Caption:='*';
   Label12.Caption:='*';
   Label13.Caption:='*';
   Label14.Caption:='*';
end;

procedure TfrmDemo.BtAboutClick(Sender: TObject);
begin
  uPassWrite.PassAbout ;
end;

procedure TfrmDemo.BtClearClick(Sender: TObject);
var
   strpass_wd :WideString;
   strMsg:string;
begin
   frmdialog.Caption :='请输入高级密码';
   frmdialog.EditPassWD.Text :='';
   if frmdialog.ShowModal =mrOk then
   begin
       BtClearWindowsClick(nil);
        strpass_wd:=trim(frmdialog.EditPassWD.Text );
        uPassWrite.PassClear(strpass_wd);

        strmsg:=uPassWrite.TBack_MsgStr ;
        ShowMessage(strmsg);
   end;

end;

procedure TfrmDemo.BtChangePassADClick(Sender: TObject);
var
   OLD_PassWD:WideString;
   New_PassWD:WideString;
   intFlag :Smallint;
   strmsg:string;
begin
   frmdialog.Caption :='请输入原来的高级密码';
   frmdialog.EditPassWD.Text :='';
   if  not (frmdialog.ShowModal=mrok)   then exit;
   OLD_PassWD:=trim(frmdialog.EditPassWD.Text) ;
   frmdialog.Caption :='请输入新的高级密码';
   frmdialog.EditPassWD.Text :='';
   if not (frmdialog.ShowModal=mrok)  then exit;
   new_PassWD:=trim(frmdialog.EditPassWD.Text) ;
   intFlag:=1;
   upasswrite.ChangePassWD(old_passwd,New_passwd,OLD_PassWD,intFlag);
   strmsg:=upasswrite.TBack_MsgStr ;
   ShowMessage(strmsg);
end;
procedure TfrmDemo.BtReadBClick(Sender: TObject);
var
   strpass_wd :WideString;
   strMsg:string;
   intFlag:Smallint;
begin
   frmdialog.Caption :='请输入用户密码';
   frmdialog.EditPassWD.Text :='';
   if frmdialog.ShowModal =mrOk then
   begin
       BtClearWindowsClick(nil);
        strpass_wd:=trim(frmdialog.EditPassWD.Text );
        intFlag:=0;
        if upassread.PassRead(strpass_wd,intFlag) then
        begin
           ShowInfoRead;
        end;
        strmsg:=upassread.TBack_MsgStr ;
        ShowMessage(strmsg);
   end;
end;

procedure TfrmDemo.BtReadAClick(Sender: TObject);
var
   strpass_wd :WideString;
   strMsg:string;
   intFlag:Smallint;
begin
   frmdialog.Caption :='请输入高级密码';
   frmdialog.EditPassWD.Text :='';
   if frmdialog.ShowModal =mrOk then
   begin
       BtClearWindowsClick(nil);
        strpass_wd:=trim(frmdialog.EditPassWD.Text );
        intflag:=1;
        if upassread.PassRead(strpass_wd,intflag) then
        begin
           ShowInfoRead;
        end;
        strmsg:=upassread.TBack_MsgStr ;
        ShowMessage(strmsg);
   end;
end;



procedure TfrmDemo.BtChangePassWDClick(Sender: TObject);
var
   OLD_PassWD:WideString;
   New_PassWD:WideString;
   AD_PassWD:WideString;
   intFlag:Smallint;
   strmsg:string;
begin
   frmdialog.Caption :='请输入原来的用户密码';
   frmdialog.EditPassWD.Text :='';
   if  not (frmdialog.ShowModal=mrok)   then exit;
   OLD_PassWD:=trim(frmdialog.EditPassWD.Text) ;
   frmdialog.Caption :='请输入新的用户密码';
   frmdialog.EditPassWD.Text :='';        
   if not (frmdialog.ShowModal=mrok)  then exit;
   New_PassWD:=trim(frmdialog.EditPassWD.Text) ;
    frmdialog.Caption :='请输入高级密码';
   frmdialog.EditPassWD.Text :='';
   if not (frmdialog.ShowModal=mrok)  then exit;
   AD_PassWD:=trim(frmdialog.EditPassWD.Text) ;
   intFlag:=0;
   upasswrite.ChangePassWD(old_passwd,New_passwd,AD_PassWD,intFlag);
   strmsg:=upasswrite.TBack_MsgStr ;
   ShowMessage(strmsg);
end;

end.
