FileName('CD.WNS');
Name('Potisk CD - jen text');
Designed('Adresar_X','WinDUO','AdrMan');
Descr('Potisk CD WinDUO - jen text')

DeclareRec('AOC')
DeclareRec('Adresar')

TypVerze:String[10]='Gratis'
SitovaVerze:Boolean
Verze:String[6]=Trim(GetDataIni('CD','Verze'))
LicencniCislo:String[8]
LicencniKod:String[2]
InstalacniKlic:String[8]
xICO:LongInt
RokKlic:String[2]
RegGratis:Boolean
LocStr:String
LicencniKlic:String[8]
IDRokKlic:Byte
Result:Integer
JeGratis:Boolean
Je2000:Boolean
JeMulti:Boolean
Ukonc:Boolean
LocZn :Byte;
LocZn2:Byte;
LocZn3:Byte;

;DlgFollowMouse(True)

if((GetCountBindRec(Adresar)<>0) and (not CompareStr(GetBindName,'ADRMAN')))
  begin
    GetBindRec('Adresar')
    xICO=Adresar.ICO
  end;

if((GetCountBindRec(AOC)<>0) and (not CompareStr(GetBindName,'ADRMAN')))
  begin
    GetBindRec('AOC')
    if(AOC.Uzivatel<>0)
      xICO=AOC.Uzivatel
    LicencniCislo=AOC.LicCis
    LicencniKod=AOC.LicKod
    SitovaVerze=StrPos('SÍ',Upcase(AOC.Verze))
    if(Length(LicencniCislo)>0)
      begin
        LocZn=Asc(Copy(LicencniCislo,1,1))
        LocZn2=Asc(Copy(LicencniCislo,2,1))
        LocZn3=Asc(Copy(LicencniCislo,3,1))
        if(not SitovaVerze)
          begin
            if((LocZn2=Asc('7')) and ((LocZn3=Asc('0')) or (LocZn3=Asc('1'))))
              begin
                SitovaVerze=(LocZn3=Asc('1'))
              end
          end
        if(LocZn=Asc('1'))
          begin
            TypVerze='Mini'
          end else
        if(LocZn=Asc('2'))
          begin
            TypVerze='Standard'
          end else
        if(LocZn=Asc('3'))
          begin
            TypVerze='Plus'
          end else
        if(LocZn=Asc('4'))
          begin
            TypVerze='Multi'
            JeMulti=True
          end else
        if((LocZn=Asc('5')) or (LocZn=Asc('8')))
          begin
            TypVerze='S-Multi'
            JeMulti=True
          end else
        if(LocZn=Asc('7'))
          begin
            if(LocZn2=Asc('9'))
              begin
                TypVerze='200x'
              end else 
            if((LocZn2=Asc('7')) and ((LocZn3=Asc('0')) or (LocZn3=Asc('1'))))
              begin
                TypVerze='Multi'
                JeMulti=True
              end else
              begin
                TypVerze='200x'
              end;
          end else
        if(LocZn=Asc('9'))
          begin
            if(LocZn2=Asc('7'))
              begin
                TypVerze='MiniMa'
              end else
            if(LocZn2=Asc('9'))
              begin
                TypVerze='Nadace'
              end
          end
      end
  end

Znova:

DefDialog('Nastavení potisku CD',384,242)

DlgShade(-1,'',4,4,376,166)
DlgStatic(-1,'&Typ verze',16,12,110,,,es_Left);
DlgCombo(101,TypVerze,96,8,160,256,10,cbs_DropDownList|cbs_Sort,'200x','Gratis','Gratis registrovaný','Mini','MiniMa','Standard','Plus','Multi','S-Multi','Upgrade','Nadace','');
DlgOnLineHelp(101,'Musí být vyplněno')
DlgCheckBox(102,SitovaVerze,260,10,108,,'Síová verze')
DlgOnLineHelp(102,'Ano nebo Ne')
DlgStatic(-1,'Číslo &verze',16,40,110,,,es_Left)
DlgEdit(103,Verze,128,36,60,,6,es_Left|es_UpperCase,'.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
DlgOnLineHelp(103,'Povinně vyplnit')
DlgDivider(16,68,352,0)
DlgStatic(-1,'&Licenční číslo',16,80,110,,,es_Left)
DlgEdit(104,LicencniCislo,128,76,70,,8,es_Left,'0123456789')
DlgStatic(-1,'-',200,80,10,,,es_Center)
DlgEdit(105,LicencniKod,212,76,32,,2,es_Left|es_UpperCase,'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
DlgDivider(16,106,352,0)
DlgStatic(-1,'&IČO po klíč',16,118,110,,,es_Left)
DlgEditICO(106,xICO,128,114,,,107)
DlgStatic(107,'',208,118,160,,,es_Left)
DlgStatic(-1,'&Rok po klíč (RR)',16,142,110,,,es_Left)
DlgEdit(108,RokKlic,128,138,22,,2,es_Left,'0123456789')
DlgOnLineHelp(108,'Má-li pauál, mělo by se vyplnit. Budou pak mít stejný klíč po celý rok. Pro WinDUO 200x se musí povinně vyplnit. Pokud nemá pauál, nevyplňovat')
;DlgStatic(-1,'Nezadáno = univerzální klíč',154,142,214  ,,,es_Left)

DlgButton(id_Retry,'',168,174)
DlgButton(102,'',238,174)
DlgButton(id_Cancel,'',308,174)

Result=DlgExecute()

if(Result=id_Cancel)
  Halt
  else
if(Result=102)
  Ukonc=True
  else
if(Result<>id_Retry)
  GoTo(Znova)

JeGratis=CompareStr(Copy(TypVerze,1,6),'Gratis')
Je2000=CompareStr(Copy(TypVerze,1,1),'2')
if((Je2000) and (Length(LicencniCislo)=0))
  begin
    Message('Musí zadat i licenční číslo !!!',mb_IconStop);
    GoTo(Znova)
  end
if((JeGratis) and (Length(TypVerze)>6))
  begin
    if(xICO=0)
      begin
        Message('Pro registrovanou gratis verzi musí zadat i IČO !!!',mb_IconStop);
        GoTo(Znova)
      end;
    TypVerze=Copy(TypVerze,1,6)
    RegGratis=True
  end

LicencniKlic=''

if(RegGratis)
  begin
    LicencniKlic=GetLicenceKey('',xICO,75)
    if(Length(LicencniKlic)<>8)
      begin
        Message('Nelze zjistit licenční klíč',mb_IconStop)
        GoTo(Znova)
      end;
  end else
if(Length(LicencniCislo)<>0)
  begin
    if(JeGratis)
      begin
        Message('Pro potisk WinDUO Gratis nesmí být vyplněno licenční číslo !!!',mb_IconExclamation); 
        GoTo(Znova)
      end;
    LocStr=Null(LicencniCislo,8)+'-'+LicencniKod
    if(not TestLicence(LocStr))
      begin
        Message(#13+'Chybné licenční číslo'+#13+LocStr,mb_IconExclamation)
        GoTo(Znova)
      end
    if((Je2000) and (xICO<>0))
      begin
        if(Length(RokKlic)=0)
          begin
            if(not Question('Opravdu chce univerzální klíč pro vechny roky ?'))
              GoTo(Znova)
            IDRokKlic=$FF
          end else
          begin
            IDRokKlic=Val(RokKlic)
          end
        LicencniKlic=GetLicenceKey(LocStr,xICO,IDRokKlic)
        if(Length(LicencniKlic)<>8)
          begin
            Message('Nelze zjistit licenční klíč',mb_IconStop)
            GoTo(Znova)
          end;
      end;
  end;

SetDataIni('CD','Verze',Verze)

WnsType(0)

;PaintMetaFile(0.0,0.0,215,215,'WDCD2.WMF');

FontSize(6)
FontFace(Bold)
TextColor($FF0000);
Text(41,47.5,ta_CENTER,Verze)
FontFace(Normal)
FontSize(4)

if(JeGratis)
  begin
    TextColor($0000FF);
    Text(79,15,ta_CENTER,'Při instalaci nevyplňujte údaje')
    Text(79,19,ta_CENTER,'licenční číslo a instalační klíč ...')
  end else
  begin
    Text(79,15,ta_CENTER,'Licenční číslo '+Null(LicencniCislo,8)+'-'+LicencniKod)

    if(RokKlic<>0)
      begin
        InstalacniKlic=GetInstallKey(LicencniCislo+LicencniKod,xICO,RokKlic,'')
      end else
      begin
        InstalacniKlic=GetInstallKey(LicencniCislo+LicencniKod,xICO,RokKlic,Verze)
      end; 

    if(Length(InstalacniKlic)<>8)
      begin
        Message('Nelze vytvořit instalační klíč')
        GoTo(Znova)
      end;

    FontSize(3)
    FontFace(Bold)

    Text(79,19,ta_CENTER,'Instalační klíč pro IČO '+xICO+' je '+InstalacniKlic)
  end

FontSize(6)
TextColor($FF0000);

if(SitovaVerze)
  begin
    if(LocZn3<>Asc('1'))
      begin
        Message('Chybné licenční číslo pro síovou verzi ...',0);GoTo Znova;
      end;
  end;

if(Length(LicencniCislo)<>0)
  begin
    LocStr=Copy(LicencniCislo,1,2);
    if(CompareStr(LocStr,'17'))
      begin
        if(not CompareStr(TypVerze,'Mini') then
          begin
          ChybnaVerze:
            Message('Chybný typ verze dle licenčního čísla ...',mb_IconStop);
            GoTo(Znova)
          end;
      end else
    if(CompareStr(LocStr,'27'))
      begin
        if(not CompareStr(TypVerze,'Standard') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'37'))
      begin
        if(not CompareStr(TypVerze,'Plus') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'47'))
      begin
        if(not CompareStr(TypVerze,'Multi') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'57'))
      begin
        if(not CompareStr(TypVerze,'S-Multi') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'70'))
      begin
        if(not CompareStr(TypVerze,'200x') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'77'))
      begin
        if((LocZn3=Asc(0))or(LocZn3=Asc(1)))
          begin
            if(not CompareStr(TypVerze,'Multi') then
              GoTo(ChybnaVerze)
          end else
        if(LocZn3=Asc(9))
          begin
            if(not CompareStr(TypVerze,'200x') then
              GoTo(ChybnaVerze)
          end else
          begin
            GoTo(NelzeCD)
          end;
      end else
    if(CompareStr(LocStr,'79'))
      begin
        if(not CompareStr(TypVerze,'200x') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'87'))
      begin
        if(not CompareStr(TypVerze,'S-Multi') then
          GoTo(ChybnaVerze)
      end else
    if(CompareStr(LocStr,'97'))
      begin
        if(not CompareStr(TypVerze,'MiniMa') then
          GoTo(ChybnaVerze)
      end else
      begin
      NelzeCD:
        Message('Toto licenční číslo nelze instalovat z CD ...',mb_IconStop);
        GoTo Znova;
      end;
  end;

if(JeGratis)
  begin
    SitovaVerze=True
  end

if(Je2000)
  begin
    Text(79,22.5,ta_CENTER,'WinDUO '+TypVerze)
    FontSize(3)
    FontFace(Bold)
    if(IDRokKlic<>$FF)
      begin
        LocStr='Licenční klíč pro IČO '+Null(Str(xICO),8)+' pro rok '+AmendYear(IDRokKlic)
      end else
      begin
        LocStr='Univerzální licenční klíč pro IČO '+Null(Str(xICO),8)
      end
    LocStr=LocStr+' je '+LicencniKlic
    Text(79,28,ta_CENTER,LocStr)
  end else
if(SitovaVerze or JeMulti)
  begin
    Text(79,23,ta_CENTER,'WinDUO '+TypVerze)
    FontSize(3.5)
    FontFace(Normal)
    FontWidthScale(0.75)
    LocStr='('
    if(SitovaVerze)
      begin
        LocStr=LocStr+'s podporou práce v síti'
        if(JeMulti)
          LocStr=LocStr+', '
      end
    if(JeMulti)
      begin
        if((LocZn=Asc('4')) or (LocZn=Asc('5')))
          begin
            LocStr=LocStr+'pro vedení 5 klientů'
          end else
        if((LocZn=Asc('7')) or (LocZn=Asc('8')))
          begin
            LocStr=LocStr+'pro vedení neomezeného počtu klientů'
          end else
          begin
            Message('Chybné licenční číslo multiverze ...',0);
            GoTo(Znova);
          end;
      end;
    LocStr=LocStr+')'
    Text(79,28,ta_CENTER,LocStr)

    if(JeGratis and (xICO<>0))
      begin
        Text(117,45,ta_CENTER,'Registrační klíč')
        Text(117,49,ta_CENTER,'roziřující počty')
        Text(117,53,ta_CENTER,'WinDUO Gratis o 50 %')
        Text(117,57,ta_CENTER,'je pro IČO '+Null(xICO,8))
        LicencniKlic=GetLicenceKey('',xICO,75)
        if(Length(LicencniKlic)<>8)
          begin
            Message('Nelze zjistit licenční klíč',mb_IconStop)
            GoTo(Znova)
          end;
        FontSize(4)
        FontFace(Bold)
        Text(117,61,ta_CENTER,LicencniKlic)
      end;

  end else
  begin
    Text(79,25,ta_CENTER,'WinDUO '+TypVerze)


    if(JeGratis and (xICO<>0))
      begin
        FontSize(3.5)
        FontFace(Normal)
        FontWidthScale(0.75)
        GoTo(Gratis)
      end;
  end;

if(not Ukonc)
  begin
    NextPage;
    GoTo(Znova);
  end;

END