Files
winapp/ActCodeFormUnit.cpp
2026-06-23 21:59:23 +08:00

128 lines
3.7 KiB
C++

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GlobalUnit.h"
#include "ActCodeFormUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TActCodeForm *ActCodeForm = NULL;
//---------------------------------------------------------------------------
__fastcall TActCodeForm::TActCodeForm(TComponent* Owner, String code, int exp)
: TForm(Owner)
{
m_sCode = code;
m_tExpire = exp;
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::FormCreate(TObject *Sender)
{
m_leActCode->Text = m_sCode;
m_leActCode->OnChange = OnCodeChange;
if(m_sCode.Length()){
if(!m_tExpire)
m_lbTips->Caption = "授权验证失败,请重新验证";
else if(m_tExpire < time(NULL))
m_lbTips->Caption = "授权码已过期,请延期或更换";
else{
tm* dt = localtime((long*)&m_tExpire);
m_lbTips->Caption = Format(String("有效期至:%.4d-%.2d-%.2d %.2d:%.2d"),
ARRAYOFCONST((dt->tm_year+1900, dt->tm_mon+1, dt->tm_mday, dt->tm_hour, dt->tm_min)));
}
m_btnReset->Enabled = true;
}
else
m_lbTips->Caption = "请输入授权码并验证";
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::OnCodeChange(TObject *Sender)
{
m_btnOk->Caption = m_leActCode->Text.Length()>0 ? "验证" : "关闭";
m_btnReset->Enabled = m_leActCode->Text.Length()>0;
if(m_tExpire>0){
m_tExpire = 0;
m_lbTips->Caption = "请输入授权码并验证";
}
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::OnCodeKeyPress(TObject *Sender, System::WideChar &Key)
{
if(Key==13)
OnOkClick(NULL);
else if(Key<0x1E)
return;
if(Key>='a' && Key<='f')
Key -= 32;
else if((Key>'9' || Key<'0') && (Key<'A' || Key>'F'))
Key = 0;
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::OnOkClick(TObject *Sender)
{
if(m_btnOk->Caption=="关闭"){
ModalResult = mrCancel;
return;
}
String code = m_leActCode->Text;
if(code.Length()<9 || code.Length()>10){
MessageBox(Handle, L"无效的授权码", L"验证", MB_ICONERROR | MB_OK);
return;
}
for(int i=1; i<=code.Length(); i++){
char Key = code[i];
if((Key>'9' || Key<'0') && (Key<'A' || Key>'F')){
MessageBox(Handle, L"无效的授权码", L"验证", MB_ICONERROR | MB_OK);
return;
}
}
m_sCode = code;
Enabled = false;
Screen->Cursor = crHourGlass;
PostMessage(Application->MainFormHandle, UM_USERCONFIRM, UR_VERIFY, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::UMUserConfirm(TMessage &msg)
{
Screen->Cursor = crDefault;
Enabled = true;
if(msg.WParam==102)
m_lbTips->Caption = "无效的授权码,请重新输入";
else if(msg.WParam==106)
m_lbTips->Caption = "该授权码正在其它设备上使用";
else if(msg.WParam>0)
m_lbTips->Caption = "授权验证异常,请稍后重试";
else{
m_tExpire = (int)msg.LParam;
if(m_tExpire < time(NULL))
m_lbTips->Caption = "授权码已过期,请延期或更换";
else{
tm* dt = localtime((long*)&m_tExpire);
m_lbTips->Caption = Format(String("有效期至:%.4d-%.2d-%.2d %.2d:%.2d"),
ARRAYOFCONST((dt->tm_year+1900, dt->tm_mon+1, dt->tm_mday, dt->tm_hour, dt->tm_min)));
m_btnOk->Caption = "关闭";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TActCodeForm::OnResetClick(TObject *Sender)
{
m_leActCode->Text = "";
m_lbTips->Caption = "请输入授权码并验证";
PostMessage(Application->MainFormHandle, UM_USERCONFIRM, UR_RESET, 0 );
m_btnOk->Caption = "关闭";
}
//---------------------------------------------------------------------------