unit mEncryptEditions;

interface

function CheckMeasureEdition: Boolean;
function CheckCompileEdition: Boolean;
function CheckPlanEdition: Boolean;

procedure InitialModuleEdition;

function CheckEncryptEdition(AEdition: Integer): Boolean;

const
  eidLimitedFixBills = 52;
  eidFixBills = 53;
  eidStandard = 178;

  iAllEdition = 211;
  iCompileEdition = 212;
  iMeasureEdition = 213;
  iPlanEdition = 214;

  EditionHint = '当前加密锁未开通此模块功能，请购买【%s】功能并升级加密锁或联系纵横客服：企业QQ：800003850  电话：(0756)3850888';

var
  _bHasCompileEdition: Boolean;
  _bHasMeasureEdition: Boolean;
  _bHasPlanEdition: Boolean;

implementation

uses
  mEncryptUnit, SysUtils, UtilMethods, ConditionalDefines;

function CheckMeasureEdition: Boolean;
begin
  Result := _bHasMeasureEdition;
  if not Result then
    ErrorMessage(Format(EditionHint, ['计量台账']));
end;

function CheckCompileEdition: Boolean;
begin
  Result := _bHasCompileEdition;
  if not Result then
    ErrorMessage(Format(EditionHint, ['台账编制']));
end;

function CheckPlanEdition: Boolean;
begin
  Result := _bHasPlanEdition;
  if not Result then
    ErrorMessage(Format(EditionHint, ['资金计划']));
end;

procedure InitialModuleEdition;
begin
  {$IFDEF _mEncrypt}
    _bHasCompileEdition := False;
    _bHasMeasureEdition := False;
    _bHasPlanEdition := False;
  {$ELSE}
    _bHasCompileEdition := True;
    _bHasMeasureEdition := True;
    _bHasPlanEdition := True;
  {$ENDIF}
end;

function CheckEncryptEdition(AEdition: Integer): Boolean;
begin
  {$IFDEF _mEncrypt}
    // 检测是否能打开软件
    case _ModuleType of
      mtAll: Result := AEdition in [iAllEdition, iCompileEdition, iMeasureEdition, iPlanEdition];
      mtCompile: Result := AEdition in [iAllEdition, iCompileEdition];
    end;
    AddEncryptLog(Format('[N] CheckS4Edition: Edition = %d And Result = %d', [AEdition, (Ord(Result))]));
    if not Result then Exit;
    // 软件可以打开的基础上，检测各个模块功能是否可用
    case AEdition of
      iAllEdition:
        begin
          _bHasMeasureEdition := True;
          _bHasCompileEdition := True;
          _bHasPlanEdition := True;
        end;
      iCompileEdition: _bHasCompileEdition := True;
      iMeasureEdition: _bHasMeasureEdition := True;
      iPlanEdition: _bHasPlanEdition := True;
    end;
  {$ELSE}
    Result := True;
  {$ENDIF}
end;

end.
